summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRohit Goswami <rog32@hi.is>2021-11-18 20:31:51 +0000
committerRohit Goswami <rog32@hi.is>2021-11-18 20:38:16 +0000
commitb96fa43e2ce6f1b5a0888079e6f39f6f8d554be7 (patch)
treed182a396c50ed3808e0c3265a3a706273a02da96
parent258ce2523ffad99be69afbd421d540086cb6bf61 (diff)
downloadnumpy-b96fa43e2ce6f1b5a0888079e6f39f6f8d554be7.tar.gz
BUG: Clear errors correctly in F2PY conversions
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
-rw-r--r--numpy/f2py/cfuncs.py59
1 files changed, 40 insertions, 19 deletions
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index 1d9236dcd..528c4adee 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -845,20 +845,26 @@ int_from_pyobj(int* v, PyObject *obj, const char *errmess)
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) {
@@ -888,15 +894,19 @@ long_from_pyobj(long* v, PyObject *obj, const char *errmess) {
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;
@@ -934,14 +944,19 @@ long_long_from_pyobj(long_long* v, PyObject *obj, const char *errmess)
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;
@@ -1001,14 +1016,20 @@ double_from_pyobj(double* v, PyObject *obj, const char *errmess)
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);
}