Skip to content
Snippets Groups Projects
Commit 14f6b740 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Py 2.5 complex workaround: If no __complex__, still call AsCComplex.

parent d143e0f0
No related branches found
No related tags found
No related merge requests found
...@@ -757,22 +757,16 @@ np_complex_float(char *p, PyObject *v, const formatdef *f) ...@@ -757,22 +757,16 @@ np_complex_float(char *p, PyObject *v, const formatdef *f)
float im = 0.0f; float im = 0.0f;
Py_complex cplx; Py_complex cplx;
#if (PY_VERSION_HEX < 0x02060000) #if (PY_VERSION_HEX < 0x02060000)
if (PyComplex_Check(v))
cplx = PyComplex_AsCComplex(v);
else if (PyObject_HasAttrString(v, "__complex__"))
{ {
if (PyComplex_Check(v)) PyObject *v2 = PyObject_CallMethod(v, "__complex__", "");
cplx = PyComplex_AsCComplex(v); cplx = PyComplex_AsCComplex(v2);
else if (PyObject_HasAttrString(v, "__complex__")) Py_DECREF(v2);
{
PyObject *v2 = PyObject_CallMethod(v, "__complex__", "");
cplx = PyComplex_AsCComplex(v2);
Py_DECREF(v2);
}
else
{
PyErr_SetString(StructError,
"required argument is not a complex");
return -1;
}
} }
else
cplx = PyComplex_AsCComplex(v);
#else #else
cplx = PyComplex_AsCComplex(v); cplx = PyComplex_AsCComplex(v);
#endif #endif
...@@ -807,22 +801,16 @@ np_complex_double(char *p, PyObject *v, const formatdef *f) ...@@ -807,22 +801,16 @@ np_complex_double(char *p, PyObject *v, const formatdef *f)
double im = 0.0; double im = 0.0;
Py_complex cplx; Py_complex cplx;
#if (PY_VERSION_HEX < 0x02060000) #if (PY_VERSION_HEX < 0x02060000)
if (PyComplex_Check(v))
cplx = PyComplex_AsCComplex(v);
else if (PyObject_HasAttrString(v, "__complex__"))
{ {
if (PyComplex_Check(v)) PyObject *v2 = PyObject_CallMethod(v, "__complex__", "");
cplx = PyComplex_AsCComplex(v); cplx = PyComplex_AsCComplex(v2);
else if (PyObject_HasAttrString(v, "__complex__")) Py_DECREF(v2);
{
PyObject *v2 = PyObject_CallMethod(v, "__complex__", "");
cplx = PyComplex_AsCComplex(v2);
Py_DECREF(v2);
}
else
{
PyErr_SetString(StructError,
"required argument is not a complex");
return -1;
}
} }
else
cplx = PyComplex_AsCComplex(v);
#else #else
cplx = PyComplex_AsCComplex(v); cplx = PyComplex_AsCComplex(v);
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment