summaryrefslogtreecommitdiff
path: root/numpy/f2py/rules.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-12-01 16:27:48 +0000
committerEric Wieser <wieser.eric@gmail.com>2019-12-02 09:28:44 +0000
commit3c6bbd7b43bf584aeef780a9e42acf2ecce7b179 (patch)
treeef8cae52c02e714a58861bbfbb4783cb0d5696ca /numpy/f2py/rules.py
parent6fa0ff8e56e7e09f0c1cdbce2da338be073947e9 (diff)
downloadnumpy-3c6bbd7b43bf584aeef780a9e42acf2ecce7b179.tar.gz
ENH: Chain exceptions when converting python objects to fortran
Note that since we now need `npy_3kcompat.h`, we can delete all duplicated lines in this file We preserve the original exception type for compatibility with old code here.
Diffstat (limited to 'numpy/f2py/rules.py')
-rwxr-xr-xnumpy/f2py/rules.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py
index f2f713bde..28eb9da30 100755
--- a/numpy/f2py/rules.py
+++ b/numpy/f2py/rules.py
@@ -1064,8 +1064,10 @@ if (#varname#_capi==Py_None) {
'\tcapi_#varname#_tmp = array_from_pyobj(#atype#,#varname#_Dims,#varname#_Rank,capi_#varname#_intent,#varname#_capi);'},
"""\
\tif (capi_#varname#_tmp == NULL) {
-\t\tif (!PyErr_Occurred())
-\t\t\tPyErr_SetString(#modulename#_error,\"failed in converting #nth# `#varname#\' of #pyname# to C/Fortran array\" );
+\t\tPyObject *exc, *val, *tb;
+\t\tPyErr_Fetch(&exc, &val, &tb);
+\t\tPyErr_SetString(exc ? exc : #modulename#_error,\"failed in converting #nth# `#varname#\' of #pyname# to C/Fortran array\" );
+\t\tnpy_PyErr_ChainExceptionsCause(exc, val, tb);
\t} else {
\t\t#varname# = (#ctype# *)(PyArray_DATA(capi_#varname#_tmp));
""",
@@ -1081,8 +1083,10 @@ if (#varname#_capi==Py_None) {
\t\t\twhile ((_i = nextforcomb()))
\t\t\t\t#varname#[capi_i++] = #init#; /* fortran way */
\t\t} else {
-\t\t\tif (!PyErr_Occurred())
-\t\t\t\tPyErr_SetString(#modulename#_error,\"Initialization of #nth# #varname# failed (initforcomb).\");
+\t\t\tPyObject *exc, *val, *tb;
+\t\t\tPyErr_Fetch(&exc, &val, &tb);
+\t\t\tPyErr_SetString(exc ? exc : #modulename#_error,\"Initialization of #nth# #varname# failed (initforcomb).\");
+\t\t\tnpy_PyErr_ChainExceptionsCause(exc, val, tb);
\t\t\tf2py_success = 0;
\t\t}
\t}