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

Work around behavior of PyComplex_AsCComplex in Py 2.5.

parent acbd0b86
No related branches found
No related tags found
No related merge requests found
...@@ -755,7 +755,27 @@ np_complex_float(char *p, PyObject *v, const formatdef *f) ...@@ -755,7 +755,27 @@ np_complex_float(char *p, PyObject *v, const formatdef *f)
else { else {
float re = 0.0f; float re = 0.0f;
float im = 0.0f; float im = 0.0f;
Py_complex cplx = PyComplex_AsCComplex(v); Py_complex cplx;
#if (PY_VERSION_HEX < 0x02050000)
{
if (PyComplex_Check(v))
cplx = PyComplex_AsCComplex(v);
else if (PyObject_HasAttrString(v, "__complex__"))
{
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);
#endif
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
PyErr_SetString(StructError, PyErr_SetString(StructError,
"required argument is not a complex"); "required argument is not a complex");
...@@ -785,7 +805,27 @@ np_complex_double(char *p, PyObject *v, const formatdef *f) ...@@ -785,7 +805,27 @@ np_complex_double(char *p, PyObject *v, const formatdef *f)
else { else {
double re = 0.0; double re = 0.0;
double im = 0.0; double im = 0.0;
Py_complex cplx = PyComplex_AsCComplex(v); Py_complex cplx;
#if (PY_VERSION_HEX < 0x02050000)
{
if (PyComplex_Check(v))
cplx = PyComplex_AsCComplex(v);
else if (PyObject_HasAttrString(v, "__complex__"))
{
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);
#endif
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
PyErr_SetString(StructError, PyErr_SetString(StructError,
"required argument is not a complex"); "required argument is not a complex");
......
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