summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-10-19 12:48:06 -0500
committerGitHub <noreply@github.com>2021-10-19 12:48:06 -0500
commite416e65303fe6ddb1c5f5792abeeaa7d4f903c2f (patch)
tree4c45c6680c29eb8b4feeff3f639a9ee81594b4d4
parent405c6eec7937721bd2e284dceaf4f49d5e6e39e8 (diff)
parent8e3f1ac0d4b44750f9c83ff74ed7f29dc6182196 (diff)
downloadnumpy-e416e65303fe6ddb1c5f5792abeeaa7d4f903c2f.tar.gz
Merge pull request #20136 from WarrenWeckesser/fix-npyiter-deallocate-check
BUG: core: Fix incorrect check of NpyIter_Deallocate return value.
-rw-r--r--numpy/core/src/umath/_umath_tests.c.src10
-rw-r--r--numpy/core/src/umath/ufunc_object.c2
-rw-r--r--numpy/core/tests/test_umath.py8
3 files changed, 19 insertions, 1 deletions
diff --git a/numpy/core/src/umath/_umath_tests.c.src b/numpy/core/src/umath/_umath_tests.c.src
index 33d8539d5..ce42fc271 100644
--- a/numpy/core/src/umath/_umath_tests.c.src
+++ b/numpy/core/src/umath/_umath_tests.c.src
@@ -400,6 +400,16 @@ addUfuncs(PyObject *dictionary) {
}
PyDict_SetItemString(dictionary, "always_error", f);
Py_DECREF(f);
+ f = PyUFunc_FromFuncAndDataAndSignature(always_error_functions,
+ always_error_data, always_error_signatures, 1, 2, 1, PyUFunc_None,
+ "always_error_gufunc",
+ "simply, broken, gufunc that sets an error (but releases the GIL).",
+ 0, "(i),()->()");
+ if (f == NULL) {
+ return -1;
+ }
+ PyDict_SetItemString(dictionary, "always_error_gufunc", f);
+ Py_DECREF(f);
f = PyUFunc_FromFuncAndDataAndSignature(inner1d_functions, inner1d_data,
inner1d_signatures, 2, 2, 1, PyUFunc_None, "inner1d",
"inner on the last dimension and broadcast on the rest \n"
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 228e67576..7824173e2 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -2542,7 +2542,7 @@ PyUFunc_GeneralizedFunctionInternal(PyUFuncObject *ufunc,
PyArray_free(inner_strides);
NPY_AUXDATA_FREE(auxdata);
- if (NpyIter_Deallocate(iter) < 0) {
+ if (!NpyIter_Deallocate(iter)) {
retval = -1;
}
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 8ff81ea51..4366e2257 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -3886,3 +3886,11 @@ def test_bad_legacy_ufunc_silent_errors():
with pytest.raises(RuntimeError, match=r"How unexpected :\)!"):
ncu_tests.always_error.at(arr, [0, 1, 2], arr)
+
+
+@pytest.mark.parametrize('x1', [np.arange(3.0), [0.0, 1.0, 2.0]])
+def test_bad_legacy_gufunc_silent_errors(x1):
+ # Verify that an exception raised in a gufunc loop propagates correctly.
+ # The signature of always_error_gufunc is '(i),()->()'.
+ with pytest.raises(RuntimeError, match=r"How unexpected :\)!"):
+ ncu_tests.always_error_gufunc(x1, 0.0)