Skip to content

Commit

Permalink
Merge pull request #20420 from charris/backport-20204
Browse files Browse the repository at this point in the history
BUG: Clear errors correctly in F2PY conversions
  • Loading branch information
charris committed Nov 20, 2021
2 parents fc9b124 + 419cbc1 commit d30f190
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions numpy/f2py/cfuncs.py
Expand Up @@ -845,20 +845,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 @@ -888,15 +894,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 @@ -934,14 +944,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 @@ -1001,14 +1016,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 d30f190

Please sign in to comment.