summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/descriptor.c9
-rw-r--r--numpy/core/tests/test_dtype.py9
2 files changed, 18 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c
index 0ba1a9c04..1784e2102 100644
--- a/numpy/core/src/multiarray/descriptor.c
+++ b/numpy/core/src/multiarray/descriptor.c
@@ -1010,6 +1010,9 @@ _convert_from_dict(PyObject *obj, int align)
}
tup = PyTuple_New(len);
descr = PyObject_GetItem(descrs, index);
+ if (!descr) {
+ goto fail;
+ }
ret = PyArray_DescrConverter(descr, &newdescr);
Py_DECREF(descr);
if (ret == PY_FAIL) {
@@ -1025,6 +1028,9 @@ _convert_from_dict(PyObject *obj, int align)
if (offsets) {
long offset;
off = PyObject_GetItem(offsets, index);
+ if (!off) {
+ goto fail;
+ }
offset = PyInt_AsLong(off);
PyTuple_SET_ITEM(tup, 1, off);
if (offset < totalsize) {
@@ -1046,6 +1052,9 @@ _convert_from_dict(PyObject *obj, int align)
PyTuple_SET_ITEM(tup, 2, item);
}
name = PyObject_GetItem(names, index);
+ if (!name) {
+ goto fail;
+ }
Py_DECREF(index);
#if defined(NPY_PY3K)
if (!PyUString_Check(name)) {
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py
index 02fec7242..e817ce5d4 100644
--- a/numpy/core/tests/test_dtype.py
+++ b/numpy/core/tests/test_dtype.py
@@ -33,6 +33,15 @@ class TestRecord(TestCase):
self.assertTrue(hash(a) != hash(b),
"%s and %s hash the same !" % (a, b))
+ def test_not_lists(self):
+ """Test if an appropriate exception is raised when passing bad values to
+ the dtype constructor.
+ """
+ self.assertRaises(TypeError, np.dtype,
+ dict(names=set(['A', 'B']), formats=['f8', 'i4']))
+ self.assertRaises(TypeError, np.dtype,
+ dict(names=['A', 'B'], formats=set(['f8', 'i4'])))
+
class TestSubarray(TestCase):
def test_single_subarray(self):
a = np.dtype((np.int, (2)))