summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-02-20 18:21:12 +0000
committerPauli Virtanen <pav@iki.fi>2010-02-20 18:21:12 +0000
commit2aa91ba2921894156016118069e020662f11362f (patch)
tree09f513417be5a6e12a579dae32c8123b754a7189
parent212fc25e16b8643f8653a66f5282cee304dc7653 (diff)
downloadnumpy-2aa91ba2921894156016118069e020662f11362f.tar.gz
BUG: properly check the return value of numpy.core._internal._dtype_from_pep3118
-rw-r--r--numpy/core/src/multiarray/buffer.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c
index 45d40f4b9..99fe48b54 100644
--- a/numpy/core/src/multiarray/buffer.c
+++ b/numpy/core/src/multiarray/buffer.c
@@ -606,7 +606,7 @@ _descriptor_from_pep3118_format(char *s)
{
char *buf, *p;
int in_name = 0;
- PyArray_Descr *descr;
+ PyObject *descr;
PyObject *str;
PyObject *_numpy_internal;
@@ -636,15 +636,22 @@ _descriptor_from_pep3118_format(char *s)
return NULL;
}
str = PyUString_FromStringAndSize(buf, strlen(buf));
+ free(buf);
descr = (PyArray_Descr*)PyObject_CallMethod(
_numpy_internal, "_dtype_from_pep3118", "O", str);
Py_DECREF(str);
if (descr == NULL) {
PyErr_Format(PyExc_ValueError,
"'%s' is not a valid PEP 3118 buffer format string", buf);
+ return NULL;
}
- free(buf);
- return descr;
+ if (!PyArray_DescrCheck(descr)) {
+ PyErr_Format(PyExc_RuntimeError,
+ "internal error: numpy.core._internal._dtype_from_pep3118 "
+ "did not return a valid dtype", buf);
+ return NULL;
+ }
+ return (PyArray_Descr*)descr;
}
#else