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

numpy-svn@scip... numpy-svn@scip...
Sun Apr 4 15:47:49 CDT 2010


Author: ptvirtan
Date: 2010-04-04 15:47:48 -0500 (Sun, 04 Apr 2010)
New Revision: 8319

Modified:
   trunk/numpy/core/src/multiarray/ctors.c
Log:
ENH: core: add sanity checks and warnings to PEP3118 -> ndarray conversion

Modified: trunk/numpy/core/src/multiarray/ctors.c
===================================================================
--- trunk/numpy/core/src/multiarray/ctors.c	2010-04-04 20:21:03 UTC (rev 8318)
+++ trunk/numpy/core/src/multiarray/ctors.c	2010-04-04 20:47:48 UTC (rev 8319)
@@ -1674,8 +1674,22 @@
     if (view->format != NULL) {
         descr = (PyObject*)_descriptor_from_pep3118_format(view->format);
         if (descr == NULL) {
+            PyObject *msg;
+            msg = PyBytes_FromFormat("Invalid PEP 3118 format string: '%s'",
+                                     view->format);
+            PyErr_WarnEx(PyExc_RuntimeWarning, PyBytes_AS_STRING(msg), 0);
+            Py_DECREF(msg);
             goto fail;
         }
+
+        /* Sanity check */
+        if (descr->elsize != view->itemsize) {
+            PyErr_WarnEx(PyExc_RuntimeWarning,
+                         "Item size computed from the PEP 3118 buffer format "
+                         "string does not match the actual item size.",
+                         0);
+            goto fail;
+        }
     }
     else {
         descr = PyArray_DescrNewFromType(PyArray_STRING);



More information about the Numpy-svn mailing list