diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-07-02 22:29:44 +0100 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-07-03 09:00:28 +0100 |
commit | 7844860e1b05862e9964900c39dd7e709979d4b5 (patch) | |
tree | dfce177eca5cbcf613edb778eb31f51aa859e915 /numpy | |
parent | 14ff219a13e194c5e7995218fea3c7648eb1c875 (diff) | |
download | numpy-7844860e1b05862e9964900c39dd7e709979d4b5.tar.gz |
BUG: Prevent hangs traversing ufunc userloop linked lists
Fixes gh-9351
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/umath/ufunc_type_resolution.c | 15 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 5 |
2 files changed, 12 insertions, 8 deletions
diff --git a/numpy/core/src/umath/ufunc_type_resolution.c b/numpy/core/src/umath/ufunc_type_resolution.c index 0fd3c45c5..8e0a0f475 100644 --- a/numpy/core/src/umath/ufunc_type_resolution.c +++ b/numpy/core/src/umath/ufunc_type_resolution.c @@ -1305,8 +1305,9 @@ find_userloop(PyUFuncObject *ufunc, if (obj == NULL) { continue; } - funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj); - while (funcdata != NULL) { + for (funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj); + funcdata != NULL; + funcdata = funcdata->next) { int *types = funcdata->arg_types; for (j = 0; j < nargs; ++j) { @@ -1320,8 +1321,6 @@ find_userloop(PyUFuncObject *ufunc, *out_innerloopdata = funcdata->data; return 1; } - - funcdata = funcdata->next; } } } @@ -1792,8 +1791,10 @@ type_tuple_userloop_type_resolver(PyUFuncObject *self, if (obj == NULL) { continue; } - funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj); - while (funcdata != NULL) { + + for (funcdata = (PyUFunc_Loop1d *)NpyCapsule_AsVoidPtr(obj); + funcdata != NULL; + funcdata = funcdata->next) { int *types = funcdata->arg_types; int matched = 1; @@ -1838,8 +1839,6 @@ type_tuple_userloop_type_resolver(PyUFuncObject *self, case -1: return -1; } - - funcdata = funcdata->next; } } } diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 3d6251253..ce16f8d01 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -1000,6 +1000,11 @@ class TestUfunc(TestCase): dtype=rational) assert_equal(result, expected) + def test_custom_ufunc_forced_sig(self): + # gh-9351 - looking for a non-first userloop would previously hang + assert_raises(TypeError, + np.multiply, rational(1), 1, signature=(rational, int, None)) + def test_custom_array_like(self): class MyThing(object): |