From 79ce479c814723035dc6249a800253c8babb4c3c Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 22 Jul 2009 08:48:34 -0700 Subject: [PATCH] Better complex conversion. --- Cython/Compiler/PyrexTypes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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); } } """) -- 2.26.2