Better complex conversion.
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 22 Jul 2009 15:48:34 +0000 (08:48 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 22 Jul 2009 15:48:34 +0000 (08:48 -0700)
Cython/Compiler/PyrexTypes.py

index d5423c50fe43904edd244d54590351e8496fbfee..d285aec7d0292fd2c05c6d83cb0bc3590e5dd3da 100644 (file)
@@ -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);
     }
 }
 """)