[Numpy-svn] r8191 - trunk/numpy/core/src/multiarray

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 12:21:12 CST 2010


Author: ptvirtan
Date: 2010-02-20 12:21:12 -0600 (Sat, 20 Feb 2010)
New Revision: 8191

Modified:
   trunk/numpy/core/src/multiarray/buffer.c
Log:
BUG: properly check the return value of numpy.core._internal._dtype_from_pep3118

Modified: trunk/numpy/core/src/multiarray/buffer.c
===================================================================
--- trunk/numpy/core/src/multiarray/buffer.c	2010-02-20 18:20:47 UTC (rev 8190)
+++ trunk/numpy/core/src/multiarray/buffer.c	2010-02-20 18:21:12 UTC (rev 8191)
@@ -606,7 +606,7 @@
 {
     char *buf, *p;
     int in_name = 0;
-    PyArray_Descr *descr;
+    PyObject *descr;
     PyObject *str;
     PyObject *_numpy_internal;
 
@@ -636,15 +636,22 @@
         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



More information about the Numpy-svn mailing list