]> granicus.if.org Git - python/commitdiff
Fix for the bug in complex() just reported by Ping.
authorGuido van Rossum <guido@python.org>
Fri, 19 Jan 2001 02:11:59 +0000 (02:11 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 19 Jan 2001 02:11:59 +0000 (02:11 +0000)
Python/bltinmodule.c

index 3acd0e2b465cfbf1fceb966d87ae01fba31260dd..ca9f3124ae93464134d8f34eaa459b435a52e5fe 100644 (file)
@@ -591,12 +591,18 @@ builtin_complex(PyObject *self, PyObject *args)
                }
        }
        else {
-               tmp = (*nbr->nb_float)(r);
+               tmp = PyNumber_Float(r);
                if (own_r) {
                        Py_DECREF(r);
                }
                if (tmp == NULL)
                        return NULL;
+               if (!PyFloat_Check(tmp)) {
+                       PyErr_SetString(PyExc_TypeError,
+                                       "float(r) didn't return a float");
+                       Py_DECREF(tmp);
+                       return NULL;
+               }
                cr.real = PyFloat_AsDouble(tmp);
                Py_DECREF(tmp);
                cr.imag = 0.0;