mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Raise OverflowError when appropriate on long->float conversion. Most of
the fiddling is simply due to that no caller of PyLong_AsDouble ever checked for failure (so that's fixing old bugs). PyLong_AsDouble is much faster for big inputs now too, but that's more of a happy consequence than a design goal.
This commit is contained in:
parent
1832de4bc0
commit
9fffa3eea3
5 changed files with 76 additions and 23 deletions
|
@ -271,18 +271,19 @@ PyFloat_AsStringEx(char *buf, PyFloatObject *v, int precision)
|
|||
return obj;
|
||||
|
||||
static int
|
||||
convert_to_double(PyObject **v,
|
||||
double *dbl)
|
||||
convert_to_double(PyObject **v, double *dbl)
|
||||
{
|
||||
register PyObject *obj = *v;
|
||||
|
||||
|
||||
if (PyInt_Check(obj)) {
|
||||
*dbl = (double)PyInt_AS_LONG(obj);
|
||||
}
|
||||
else if (PyLong_Check(obj)) {
|
||||
PyFPE_START_PROTECT("convert_to_double", {*v=NULL;return -1;})
|
||||
*dbl = PyLong_AsDouble(obj);
|
||||
PyFPE_END_PROTECT(*dbl)
|
||||
if (*dbl == -1.0 && PyErr_Occurred()) {
|
||||
*v = NULL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Py_INCREF(Py_NotImplemented);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue