diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-10-23 12:07:52 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-10-23 12:07:52 -0700 |
commit | ec5b97ddb592de1e5722439c3ba0599e62e73fed (patch) | |
tree | 7e8a6aeb47b5755d4467b177ea01d610325ed083 | |
parent | 54d3559c325be26f8fee71e1c669cc502286dc77 (diff) | |
parent | a1dad5dcfe075681128638cae47c5ae26045cb41 (diff) | |
download | numpy-ec5b97ddb592de1e5722439c3ba0599e62e73fed.tar.gz |
Merge pull request #3963 from juliantaylor/default-errobj-crash
Default errobj crash
-rw-r--r-- | numpy/core/include/numpy/ufuncobject.h | 5 | ||||
-rw-r--r-- | numpy/core/numeric.py | 2 | ||||
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 13 | ||||
-rw-r--r-- | numpy/core/src/umath/umathmodule.c | 1 | ||||
-rw-r--r-- | numpy/core/tests/test_numeric.py | 19 |
5 files changed, 31 insertions, 9 deletions
diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h index 423fbc279..a6307df91 100644 --- a/numpy/core/include/numpy/ufuncobject.h +++ b/numpy/core/include/numpy/ufuncobject.h @@ -258,14 +258,11 @@ typedef struct _tagPyUFuncObject { #define UFUNC_FPE_UNDERFLOW 4 #define UFUNC_FPE_INVALID 8 -/* Error mode that avoids look-up (no checking) */ -#define UFUNC_ERR_DEFAULT 0 - #define UFUNC_OBJ_ISOBJECT 1 #define UFUNC_OBJ_NEEDS_API 2 /* Default user error mode */ -#define UFUNC_ERR_DEFAULT2 \ +#define UFUNC_ERR_DEFAULT \ (UFUNC_ERR_WARN << UFUNC_SHIFT_DIVIDEBYZERO) + \ (UFUNC_ERR_WARN << UFUNC_SHIFT_OVERFLOW) + \ (UFUNC_ERR_WARN << UFUNC_SHIFT_INVALID) diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index f43f93d64..1ed339401 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2741,7 +2741,7 @@ class errstate(object): def _setdef(): - defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT2, None] + defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None] umath.seterrobj(defval) # set the default values diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index e419a6611..38091d5ff 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -432,10 +432,17 @@ _extract_pyvals(PyObject *ref, char *name, int *bufsize, { PyObject *retval; + /* default errobj case, skips dictionary lookup */ if (ref == NULL) { - *errmask = UFUNC_ERR_DEFAULT; - *errobj = Py_BuildValue("NO", PyBytes_FromString(name), Py_None); - *bufsize = NPY_BUFSIZE; + if (errmask) { + *errmask = UFUNC_ERR_DEFAULT; + } + if (errobj) { + *errobj = Py_BuildValue("NO", PyBytes_FromString(name), Py_None); + } + if (bufsize) { + *bufsize = NPY_BUFSIZE; + } return 0; } diff --git a/numpy/core/src/umath/umathmodule.c b/numpy/core/src/umath/umathmodule.c index 0b789de26..8c95cebf5 100644 --- a/numpy/core/src/umath/umathmodule.c +++ b/numpy/core/src/umath/umathmodule.c @@ -403,7 +403,6 @@ PyMODINIT_FUNC initumath(void) ADDCONST(ERR_PRINT); ADDCONST(ERR_LOG); ADDCONST(ERR_DEFAULT); - ADDCONST(ERR_DEFAULT2); ADDCONST(SHIFT_DIVIDEBYZERO); ADDCONST(SHIFT_OVERFLOW); diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 5a3de8edd..ac341468c 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -8,6 +8,7 @@ import itertools import numpy as np from numpy.core import * +from numpy.core import umath from numpy.random import rand, randint, randn from numpy.testing import * from numpy.core.multiarray import dot as dot_ @@ -439,6 +440,24 @@ class TestSeterr(TestCase): np.seterrobj(olderrobj) del self.called + def test_errobj_noerrmask(self): + # errmask = 0 has a special code path for the default + olderrobj = np.geterrobj() + try: + # set errobj to something non default + np.seterrobj([umath.UFUNC_BUFSIZE_DEFAULT, + umath.ERR_DEFAULT + 1, None]) + #call a ufunc + np.isnan(np.array([6])) + # same with the default, lots of times to get rid of possible + # pre-existing stack in the code + for i in range(10000): + np.seterrobj([umath.UFUNC_BUFSIZE_DEFAULT, umath.ERR_DEFAULT, + None]) + np.isnan(np.array([6])) + finally: + np.seterrobj(olderrobj) + class TestFloatExceptions(TestCase): def assert_raises_fpe(self, fpeerr, flop, x, y): |