summaryrefslogtreecommitdiff
path: root/numpy/f2py/cfuncs.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2023-01-25 20:50:42 +0100
committerSebastian Berg <sebastianb@nvidia.com>2023-01-25 20:50:42 +0100
commit2784923903353dd4c62c30c9d395fef4ce5fc4bb (patch)
tree14e3383ee1be3796754a6d2820fdd556823a890b /numpy/f2py/cfuncs.py
parent9caf1845e2f1e0b71c23b6f0bb4312b96c35ba43 (diff)
downloadnumpy-2784923903353dd4c62c30c9d395fef4ce5fc4bb.tar.gz
BUG: Fixup f2py's handling a very little bit
This clears the error holding only to the type. Since in the other path the errmessage seemed completely uninitialized, I opted to just ignore it entirely and keep the old error. I could fathom to use error chaining here, but overall, I am not even sure that chaining makes even sense for these errors. This fix is meant to be minimal (the second one, I just noticed randomly), it does not make this code clean.
Diffstat (limited to 'numpy/f2py/cfuncs.py')
-rw-r--r--numpy/f2py/cfuncs.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index 741692562..2d27b6524 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -800,16 +800,23 @@ character_from_pyobj(character* v, PyObject *obj, const char *errmess) {
}
}
{
+ /* TODO: This error (and most other) error handling needs cleaning. */
char mess[F2PY_MESSAGE_BUFFER_SIZE];
strcpy(mess, errmess);
PyObject* err = PyErr_Occurred();
if (err == NULL) {
err = PyExc_TypeError;
+ Py_INCREF(err);
+ }
+ else {
+ Py_INCREF(err);
+ PyErr_Clear();
}
sprintf(mess + strlen(mess),
" -- expected str|bytes|sequence-of-str-or-bytes, got ");
f2py_describe(obj, mess + strlen(mess));
PyErr_SetString(err, mess);
+ Py_DECREF(err);
}
return 0;
}
@@ -1227,8 +1234,8 @@ static int try_pyarr_from_character(PyObject* obj, character* v) {
strcpy(mess, "try_pyarr_from_character failed"
" -- expected bytes array-scalar|array, got ");
f2py_describe(obj, mess + strlen(mess));
+ PyErr_SetString(err, mess);
}
- PyErr_SetString(err, mess);
}
return 0;
}