summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-12-11 20:31:34 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-12-11 20:31:34 (GMT)
commit77d8a4fc91aff2e4f25874fac2cb7c1915984cd1 (patch)
treeed9a17663e39ce9fa657a1b4a881937f60e85ce2 /Objects/floatobject.c
parent63a3571e1732176e0e784e0d0e6dac07c9162611 (diff)
downloadcpython-77d8a4fc91aff2e4f25874fac2cb7c1915984cd1.zip
cpython-77d8a4fc91aff2e4f25874fac2cb7c1915984cd1.tar.gz
cpython-77d8a4fc91aff2e4f25874fac2cb7c1915984cd1.tar.bz2
float_floor_div: An expression like 3.//1j crashed the interpreter, or
delivered bizarre results. Check float_divmod for a Py_NotImplemented return and pass it along (instead of treating Py_NotImplemented as a 2-tuple). CONVERT_TO_DOUBLE: Added comments; this macro is obscure.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 8ce0ff5..ec8f719 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -265,8 +265,11 @@ PyFloat_AsStringEx(char *buf, PyFloatObject *v, int precision)
/* Macro and helper that convert PyObject obj to a C double and store
the value in dbl; this replaces the functionality of the coercion
- slot function */
-
+ slot function. If conversion to double raises an exception, obj is
+ set to NULL, and the function invoking this macro returns NULL. If
+ obj is not of float, int or long type, Py_NotImplemented is incref'ed,
+ stored in obj, and returned from the function invoking this macro.
+*/
#define CONVERT_TO_DOUBLE(obj, dbl) \
if (PyFloat_Check(obj)) \
dbl = PyFloat_AS_DOUBLE(obj); \
@@ -519,13 +522,13 @@ float_floor_div(PyObject *v, PyObject *w)
PyObject *t, *r;
t = float_divmod(v, w);
- if (t != NULL) {
- r = PyTuple_GET_ITEM(t, 0);
- Py_INCREF(r);
- Py_DECREF(t);
- return r;
- }
- return NULL;
+ if (t == NULL || t == Py_NotImplemented)
+ return t;
+ assert(PyTuple_CheckExact(t));
+ r = PyTuple_GET_ITEM(t, 0);
+ Py_INCREF(r);
+ Py_DECREF(t);
+ return r;
}
static PyObject *