diff options
author | Ben Walsh <b@wumpster.com> | 2011-08-21 13:51:40 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-08-21 13:57:49 -0600 |
commit | d7b12a38aa602839b238c2105d0fae208fe891ef (patch) | |
tree | 6003d9591994b0483a8f9ad20e203a14f6e918de | |
parent | 04741c071b54d024c86d38b85494ab9aefb77e46 (diff) | |
download | numpy-d7b12a38aa602839b238c2105d0fae208fe891ef.tar.gz |
BUG: Fix segfault when PyArray_VOID and no minitype in _array_find_type.
The segfault showed up in numpy/testing/print_coercion_tables.py and
'lookfor'.
-rw-r--r-- | numpy/core/src/multiarray/common.c | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c index 5b17ad28c..546883ddd 100644 --- a/numpy/core/src/multiarray/common.c +++ b/numpy/core/src/multiarray/common.c @@ -253,7 +253,8 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max) } if (minitype == NULL) { minitype = chktype; - } else { + } + else { newtype = PyArray_PromoteTypes(chktype, minitype); Py_DECREF(minitype); minitype = newtype; @@ -273,7 +274,8 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max) finish: if (minitype == NULL) { outtype = chktype; - } else { + } + else { outtype = PyArray_PromoteTypes(chktype, minitype); Py_DECREF(chktype); Py_DECREF(minitype); @@ -286,7 +288,7 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max) * unless input was already a VOID */ if (outtype->type_num == PyArray_VOID && - minitype->type_num != PyArray_VOID) { + (minitype == NULL || minitype->type_num != PyArray_VOID)) { Py_DECREF(outtype); return PyArray_DescrFromType(NPY_OBJECT); } diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 03f1b10c6..b9dfcddf9 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -327,6 +327,10 @@ class TestCreation(TestCase): msg = 'String conversion for %s' % type assert_equal(array(nstr, dtype=type), result, err_msg=msg) + def test_void(self): + arr = np.array([np.void(0)], dtype='V') + assert_equal(arr.dtype.kind, 'V') + def test_non_sequence_sequence(self): """Should not segfault. |