diff options
author | Rohit Goswami <rog32@hi.is> | 2021-11-18 20:31:51 +0000 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2021-11-30 15:15:33 -0700 |
commit | 1503492f27b9e74f4092f6fe3027a8ac1898e037 (patch) | |
tree | 1929d6cc8b7ab697a19a93a8252d774d5abd3f96 | |
parent | e34b45c0b578b0dd7b895d041cc9bd7f7a6f4c65 (diff) | |
download | numpy-1503492f27b9e74f4092f6fe3027a8ac1898e037.tar.gz |
BUG: Clear errors correctly in F2PY conversions
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
-rw-r--r-- | numpy/f2py/cfuncs.py | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py index f403a66b5..4e53344ec 100644 --- a/numpy/f2py/cfuncs.py +++ b/numpy/f2py/cfuncs.py @@ -763,20 +763,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) { @@ -806,15 +812,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; @@ -852,14 +862,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; @@ -919,14 +934,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); } |