Commit 4446b3a4 authored by Stefan Behnel's avatar Stefan Behnel

another PyPy fix for double conversion: PyNumber_Float() to properly convert strings etc.

parent 8e92f1c1
......@@ -442,24 +442,26 @@ static CYTHON_INLINE int __Pyx_init_unicode_iteration(
/////////////// pyobject_as_double.proto ///////////////
#if CYTHON_COMPILING_IN_PYPY
// currently works because PyPy calls float() internally
#define __Pyx_PyObject_AsDouble(obj) PyFloat_AsDouble(obj)
#else
static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
#if CYTHON_COMPILING_IN_PYPY
#define __Pyx_PyObject_AsDouble(obj) \
(likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) : \
likely(PyInt_CheckExact(obj)) ? \
PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
#else
#define __Pyx_PyObject_AsDouble(obj) \
((likely(PyFloat_CheckExact(obj))) ? \
PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj))
#endif
/////////////// pyobject_as_double ///////////////
#if !CYTHON_COMPILING_IN_PYPY
static double __Pyx__PyObject_AsDouble(PyObject* obj) {
PyObject* float_value;
#if CYTHON_COMPILING_IN_PYPY
float_value = PyNumber_Float(obj);
#else
if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) {
return PyFloat_AsDouble(obj);
} else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) {
......@@ -476,6 +478,7 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj) {
PyTuple_SET_ITEM(args, 0, 0);
Py_DECREF(args);
}
#endif
if (likely(float_value)) {
double value = PyFloat_AS_DOUBLE(float_value);
Py_DECREF(float_value);
......@@ -484,4 +487,3 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj) {
bad:
return (double)-1;
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment