From: Robert Bradshaw Date: Wed, 22 Jul 2009 15:48:34 +0000 (-0700) Subject: Better complex conversion. X-Git-Tag: 0.12.alpha0~224^2~1^2^2~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=79ce479c814723035dc6249a800253c8babb4c3c;p=cython.git Better complex conversion. --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index d5423c50..d285aec7 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -827,13 +827,14 @@ static %(type)s __pyx_PyObject_As_%(type_name)s(PyObject* o); /* proto */ """, impl=""" static %(type)s __pyx_PyObject_As_%(type_name)s(PyObject* o) { - if (PyComplex_Check(o)) { + if (PyComplex_CheckExact(o)) { return %(type_name)s_from_parts( (%(real_type)s)((PyComplexObject *)o)->cval.real, (%(real_type)s)((PyComplexObject *)o)->cval.imag); } else { - return %(type_name)s_from_parts(%(type_convert)s(o), 0); + Py_complex cval = PyComplex_AsCComplex(o); + return %(type_name)s_from_parts((%(real_type)s)cval.real, (%(real_type)s)cval.imag); } } """)