summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2017-04-08 11:50:54 -0400
committerCharles Harris <charlesr.harris@gmail.com>2017-04-27 13:37:50 -0600
commitb1fa10aaf1dc70343e7b267a6e2858ad30b0d97e (patch)
treeb146948155b26d3de66063631ae0f2ee954a413c
parent25e973d61150f515448566d35a86ea878aa4c98f (diff)
downloadnumpy-b1fa10aaf1dc70343e7b267a6e2858ad30b0d97e.tar.gz
BUG: ensure subclass of override class doesn't segfault.
-rw-r--r--numpy/core/src/umath/override.c3
-rw-r--r--numpy/core/tests/test_umath.py5
2 files changed, 5 insertions, 3 deletions
diff --git a/numpy/core/src/umath/override.c b/numpy/core/src/umath/override.c
index 61a6bb720..6cd4bee14 100644
--- a/numpy/core/src/umath/override.c
+++ b/numpy/core/src/umath/override.c
@@ -409,7 +409,8 @@ PyUFunc_CheckOverride(PyUFuncObject *ufunc, char *method,
/* Check for sub-types to the right of obj. */
for (j = i + 1; j < noa; j++) {
other_obj = with_override[j];
- if (PyObject_Type(other_obj) != PyObject_Type(obj) &&
+ if (other_obj != NULL &&
+ PyObject_Type(other_obj) != PyObject_Type(obj) &&
PyObject_IsInstance(other_obj,
PyObject_Type(override_obj))) {
override_obj = NULL;
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 5ae4739bb..454f27020 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -7,6 +7,7 @@ import itertools
from numpy.testing.utils import _gen_alignment_data
import numpy.core.umath as ncu
+from numpy.core import umath_tests as ncu_tests
import numpy as np
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal, assert_raises,
@@ -1620,7 +1621,7 @@ class TestSpecialMethods(TestCase):
def __array_ufunc__(self, func, method, *inputs, **kwargs):
return NotImplemented
- class CSub(object):
+ class CSub(C):
def __array_ufunc__(self, func, method, *inputs, **kwargs):
return NotImplemented
@@ -1889,8 +1890,8 @@ class TestSpecialMethods(TestCase):
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
return self, ufunc, method, inputs, kwargs
+ inner1d = ncu_tests.inner1d
a = A()
- inner1d = np.core.umath_tests.inner1d
res = inner1d(a, a)
assert_equal(res[0], a)
assert_equal(res[1], inner1d)