Skip to content

Commit

Permalink
Merge pull request #20497 from charris/backport-20404
Browse files Browse the repository at this point in the history
BUG: Clear errors correctly in F2PY conversions
  • Loading branch information
charris committed Nov 30, 2021
2 parents e34b45c + 1503492 commit f6bcca4
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions numpy/f2py/cfuncs.py
Expand Up @@ -763,20 +763,26 @@
return !(*v == -1 && PyErr_Occurred());
}
if (PyComplex_Check(obj))
if (PyComplex_Check(obj)) {
PyErr_Clear();
tmp = PyObject_GetAttrString(obj,\"real\");
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
}
else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
/*pass*/;
else if (PySequence_Check(obj))
}
else if (PySequence_Check(obj)) {
PyErr_Clear();
tmp = PySequence_GetItem(obj, 0);
}
if (tmp) {
PyErr_Clear();
if (int_from_pyobj(v, tmp, errmess)) {
Py_DECREF(tmp);
return 1;
}
Py_DECREF(tmp);
}
{
PyObject* err = PyErr_Occurred();
if (err == NULL) {
Expand Down Expand Up @@ -806,15 +812,19 @@
return !(*v == -1 && PyErr_Occurred());
}
if (PyComplex_Check(obj))
if (PyComplex_Check(obj)) {
PyErr_Clear();
tmp = PyObject_GetAttrString(obj,\"real\");
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
}
else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
/*pass*/;
else if (PySequence_Check(obj))
tmp = PySequence_GetItem(obj,0);
}
else if (PySequence_Check(obj)) {
PyErr_Clear();
tmp = PySequence_GetItem(obj, 0);
}
if (tmp) {
PyErr_Clear();
if (long_from_pyobj(v, tmp, errmess)) {
Py_DECREF(tmp);
return 1;
Expand Down Expand Up @@ -852,14 +862,19 @@
return !(*v == -1 && PyErr_Occurred());
}
if (PyComplex_Check(obj))
if (PyComplex_Check(obj)) {
PyErr_Clear();
tmp = PyObject_GetAttrString(obj,\"real\");
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
}
else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
/*pass*/;
else if (PySequence_Check(obj))
tmp = PySequence_GetItem(obj,0);
if (tmp) {
}
else if (PySequence_Check(obj)) {
PyErr_Clear();
tmp = PySequence_GetItem(obj, 0);
}
if (tmp) {
if (long_long_from_pyobj(v, tmp, errmess)) {
Py_DECREF(tmp);
return 1;
Expand Down Expand Up @@ -919,14 +934,20 @@
Py_DECREF(tmp);
return !(*v == -1.0 && PyErr_Occurred());
}
if (PyComplex_Check(obj))
if (PyComplex_Check(obj)) {
PyErr_Clear();
tmp = PyObject_GetAttrString(obj,\"real\");
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
}
else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
/*pass*/;
else if (PySequence_Check(obj))
tmp = PySequence_GetItem(obj,0);
if (tmp) {
}
else if (PySequence_Check(obj)) {
PyErr_Clear();
tmp = PySequence_GetItem(obj, 0);
}
if (tmp) {
if (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}
Py_DECREF(tmp);
}
Expand Down

0 comments on commit f6bcca4

Please sign in to comment.