diff options
author | sasha <sasha@localhost> | 2006-01-15 22:47:52 +0000 |
---|---|---|
committer | sasha <sasha@localhost> | 2006-01-15 22:47:52 +0000 |
commit | f22f844e4fd3cf724c250d850f6b04bf1650aa9f (patch) | |
tree | 765e9c48adb8611bb4cba443ca0e57b10de54d47 /numpy/core | |
parent | 1a897288732e541db9f42cff8122c7886791d438 (diff) | |
download | numpy-f22f844e4fd3cf724c250d850f6b04bf1650aa9f.tar.gz |
do not mask errors in {{{__array_wrap__}}}
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/ufuncobject.c | 22 | ||||
-rw-r--r-- | numpy/core/tests/test_umath.py | 9 |
2 files changed, 21 insertions, 10 deletions
diff --git a/numpy/core/src/ufuncobject.c b/numpy/core/src/ufuncobject.c index 21f03a955..6464fd10e 100644 --- a/numpy/core/src/ufuncobject.c +++ b/numpy/core/src/ufuncobject.c @@ -2561,7 +2561,7 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args) PyArrayObject *mps[MAX_ARGS]; PyObject *retobj[MAX_ARGS]; PyObject *res; - PyObject *obj; + PyObject *wrap; int errval; /* Initialize all array objects to NULL to make cleanup easier @@ -2587,7 +2587,7 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args) use __array_wrap__ of input object with largest __array_priority__ (default = 0.0) */ - obj = _find_array_wrap(args); + wrap = _find_array_wrap(args); /* wrap outputs */ for (i=0; i<self->nout; i++) { @@ -2602,15 +2602,15 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args) back into old */ mps[j] = (PyArrayObject *)old; } - if (obj != NULL) { - res = PyObject_CallFunction(obj, "O(OOi)", + if (wrap != NULL) { + res = PyObject_CallFunction(wrap, "O(OOi)", mps[j], self, args, i); - if (res == NULL) { + if (res == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) { PyErr_Clear(); - res = PyObject_CallFunctionObjArgs(obj, mps[j], NULL); + res = PyObject_CallFunctionObjArgs(wrap, mps[j], NULL); } - Py_DECREF(obj); - if (res == NULL) PyErr_Clear(); + Py_DECREF(wrap); + if (res == NULL) goto fail; else if (res == Py_None) Py_DECREF(res); else { Py_DECREF(mps[j]); @@ -2629,8 +2629,10 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args) PyTuple_SET_ITEM(ret, i, retobj[i]); } return (PyObject *)ret; - } - + } + fail: + for(i=self->nin; i<self->nargs; i++) Py_XDECREF(mps[i]); + return NULL; } static PyObject * diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 9fd21faa7..b3b2d2c5e 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -99,5 +99,14 @@ class test_special_methods(ScipyTestCase): self.failUnless(type(exp(b) is B)) self.failUnless(type(exp(c) is C)) + def test_failing_wrap(self): + class A(object): + def __array__(self): + return zeros(1) + def __array_wrap__(self, arr, context): + raise RuntimeError + a = A() + self.failUnlessRaises(RuntimeError, maximum, a, a) + if __name__ == "__main__": ScipyTest().run() |