summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-04 05:14:19 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-04 05:14:19 (GMT)
commit9fffa3eea3a7e99b0179988e7a016a45bf63ab96 (patch)
tree1b891e323dff2790bcd2b74ad4071cb0d380803d /Objects/floatobject.c
parent1832de4bc07e7ffd5938b41e8d7d8fcf8b5e12e2 (diff)
downloadcpython-9fffa3eea3a7e99b0179988e7a016a45bf63ab96.zip
cpython-9fffa3eea3a7e99b0179988e7a016a45bf63ab96.tar.gz
cpython-9fffa3eea3a7e99b0179988e7a016a45bf63ab96.tar.bz2
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.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 478e131..8443aff 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -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);