[Numpy-svn] r8267 - in trunk/numpy/core/src: multiarray umath

numpy-svn@scip... numpy-svn@scip...
Thu Feb 25 11:49:24 CST 2010


Author: charris
Date: 2010-02-25 11:49:24 -0600 (Thu, 25 Feb 2010)
New Revision: 8267

Modified:
   trunk/numpy/core/src/multiarray/arraytypes.c.src
   trunk/numpy/core/src/multiarray/ctors.c
   trunk/numpy/core/src/multiarray/descriptor.c
   trunk/numpy/core/src/multiarray/getset.c
   trunk/numpy/core/src/multiarray/multiarraymodule.c
   trunk/numpy/core/src/multiarray/scalarapi.c
   trunk/numpy/core/src/multiarray/scalartypes.c.src
   trunk/numpy/core/src/multiarray/usertypes.c
   trunk/numpy/core/src/umath/ufunc_object.c
   trunk/numpy/core/src/umath/umathmodule.c.src
Log:
BUG: Make sure that the errors set by the PyCapsule functions are cleared. The
PyCObject functions don't set errors. Note that the error handling in the
current code is spotty and needs to be fixed at some point.

Modified: trunk/numpy/core/src/multiarray/arraytypes.c.src
===================================================================
--- trunk/numpy/core/src/multiarray/arraytypes.c.src	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/multiarray/arraytypes.c.src	2010-02-25 17:49:24 UTC (rev 8267)
@@ -3533,10 +3533,17 @@
     dt_data->den = 1;
     dt_data->events = 1;
 
+/* FIXME
+ * There is no error check here and no way to indicate an error
+ * until the metadata turns up NULL.
+ */
 #if defined(NPY_PY3K)
     cobj = PyCapsule_New((void *)dt_data, NULL, simple_capsule_dtor);
+    if (cobj == NULL) {
+        PyErr_Clear();
+    }
 #else
-    cobj = PyCObject_FromVoidPtr((void *)dt_data, _pya_free);
+    cobj = PyCObject_FromVoidPtr((void *)dt_data, simple_capsule_dtor);
 #endif
     descr->metadata = PyDict_New();
     PyDict_SetItemString(descr->metadata, NPY_METADATA_DTSTR, cobj);

Modified: trunk/numpy/core/src/multiarray/ctors.c
===================================================================
--- trunk/numpy/core/src/multiarray/ctors.c	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/multiarray/ctors.c	2010-02-25 17:49:24 UTC (rev 8267)
@@ -1144,6 +1144,9 @@
         if (PyCapsule_CheckExact(e)) {
             PyArrayInterface *inter;
             inter = (PyArrayInterface *)PyCapsule_GetPointer(e, NULL);
+            if (inter == NULL) {
+                PyErr_Clear();
+            }
 #else
         if (PyCObject_Check(e)) {
             PyArrayInterface *inter;
@@ -1576,6 +1579,9 @@
                 /* A C-function is stored here */
                 PyArray_FinalizeFunc *cfunc;
                 cfunc = PyCapsule_GetPointer(func, NULL);
+                if (cfunc == NULL) {
+                    PyErr_Clear();
+                }
 #else
             if PyCObject_Check(func) {
                 /* A C-function is stored here */
@@ -2127,6 +2133,9 @@
         goto fail;
     }
     inter = PyCapsule_GetPointer(attr, NULL);
+    if (inter == NULL) {
+        PyErr_Clear();
+    }
 #else
     if (!PyCObject_Check(attr)) {
         goto fail;

Modified: trunk/numpy/core/src/multiarray/descriptor.c
===================================================================
--- trunk/numpy/core/src/multiarray/descriptor.c	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/multiarray/descriptor.c	2010-02-25 17:49:24 UTC (rev 8267)
@@ -648,6 +648,9 @@
 
 #if defined(NPY_PY3K)
     dt_data = PyCapsule_GetPointer(cobj, NULL);
+    if (dt_data == NULL) {
+        PyErr_Clear();
+    }
 #else
     dt_data = PyCObject_AsVoidPtr(cobj);
 #endif
@@ -669,6 +672,7 @@
 _convert_datetime_tuple_to_cobj(PyObject *tuple)
 {
     PyArray_DatetimeMetaData *dt_data;
+    PyObject *ret;
 
     dt_data = _pya_malloc(sizeof(PyArray_DatetimeMetaData));
     dt_data->base = _unit_from_str(
@@ -685,11 +689,18 @@
         }
     }
 
+/* FIXME
+ * There is no error handling here.
+ */
 #if defined(NPY_PY3K)
-    return PyCapsule_New((void *)dt_data, NULL, simple_capsule_dtor);
+    ret = PyCapsule_New((void *)dt_data, NULL, simple_capsule_dtor);
+    if (ret == NULL) {
+        PyErr_Clear();
+    }
 #else
-    return PyCObject_FromVoidPtr((void *)dt_data, _pya_free);
+    ret = PyCObject_FromVoidPtr((void *)dt_data, simple_capsule_dtor);
 #endif
+    return ret;
 }
 
 static PyArray_Descr *
@@ -1554,6 +1565,9 @@
     tmp = PyDict_GetItemString(self->metadata, NPY_METADATA_DTSTR);
 #if defined(NPY_PY3K)
     dt_data = PyCapsule_GetPointer(tmp, NULL);
+    if (dt_data == NULL) {
+        PyErr_Clear();
+    }
 #else
     dt_data = PyCObject_AsVoidPtr(tmp);
 #endif

Modified: trunk/numpy/core/src/multiarray/getset.c
===================================================================
--- trunk/numpy/core/src/multiarray/getset.c	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/multiarray/getset.c	2010-02-25 17:49:24 UTC (rev 8267)
@@ -554,7 +554,14 @@
     Py_INCREF(self);
 #if defined(NPY_PY3K)
     ret = PyCapsule_New(inter, NULL, gentype_struct_free);
-    PyCapsule_SetContext(ret, self);
+    if (ret == NULL) {
+        PyErr_Clear();
+    }
+    else if (PyCapsule_SetContext(ret, self) != 0) {
+        PyErr_Clear();
+        Py_DECREF(ret);
+        ret = NULL;
+    }
 #else
     ret = PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);
 #endif

Modified: trunk/numpy/core/src/multiarray/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarray/multiarraymodule.c	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/multiarray/multiarraymodule.c	2010-02-25 17:49:24 UTC (rev 8267)
@@ -1350,9 +1350,18 @@
         return 1;
     }
 
+/* FIXME
+ * There is no err handling here.
+ */
 #if defined(NPY_PY3K)
     data1 = PyCapsule_GetPointer(cobj1, NULL);
+    if (data1 == NULL) {
+        PyErr_Clear();
+    }
     data2 = PyCapsule_GetPointer(cobj2, NULL);
+    if (data2 == NULL) {
+        PyErr_Clear();
+    }
 #else
     data1 = PyCObject_AsVoidPtr(cobj1);
     data2 = PyCObject_AsVoidPtr(cobj2);
@@ -3050,8 +3059,14 @@
     if (PyType_Ready(&PyArrayFlags_Type) < 0) {
         return RETVAL;
     }
+/* FIXME
+ * There is no error handling here
+ */
 #if defined(NPY_PY3K)
     c_api = PyCapsule_New((void *)PyArray_API, NULL, NULL);
+    if (c_api == NULL) {
+        PyErr_Clear();
+    }
 #else
     c_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);
 #endif
@@ -3085,8 +3100,14 @@
     PyDict_SetItemString(d, "METADATA_DTSTR", s);
     Py_DECREF(s);
 
+/* FIXME
+ * There is no error handling here
+ */
 #if defined(NPY_PY3K)
     s = PyCapsule_New((void *)_datetime_strings, NULL, NULL);
+    if (s == NULL) {
+        PyErr_Clear();
+    }
 #else
     s = PyCObject_FromVoidPtr((void *)_datetime_strings, NULL);
 #endif

Modified: trunk/numpy/core/src/multiarray/scalarapi.c
===================================================================
--- trunk/numpy/core/src/multiarray/scalarapi.c	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/multiarray/scalarapi.c	2010-02-25 17:49:24 UTC (rev 8267)
@@ -536,8 +536,11 @@
         }
 #if defined(NPY_PY3K)
         cobj = PyCapsule_New((void *)dt_data, NULL, simple_capsule_dtor);
+        if (cobj == NULL) {
+            PyErr_Clear();
+        }
 #else
-        cobj = PyCObject_FromVoidPtr((void *)dt_data, _pya_free);
+        cobj = PyCObject_FromVoidPtr((void *)dt_data, simple_capsule_dtor);
 #endif
 
         /* Add correct meta-data to the data-type */
@@ -670,8 +673,15 @@
         PyObject *cobj;
         PyArray_DatetimeMetaData *dt_data;
         cobj = PyDict_GetItemString(descr->metadata, NPY_METADATA_DTSTR);
+
+/* FIXME
+ * There is no error handling here.
+ */
 #if defined(NPY_PY3K)
         dt_data = PyCapsule_GetPointer(cobj, NULL);
+        if (dt_data == NULL) {
+            PyErr_Clear();
+        }
 #else
         dt_data = PyCObject_AsVoidPtr(cobj);
 #endif

Modified: trunk/numpy/core/src/multiarray/scalartypes.c.src
===================================================================
--- trunk/numpy/core/src/multiarray/scalartypes.c.src	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/multiarray/scalartypes.c.src	2010-02-25 17:49:24 UTC (rev 8267)
@@ -859,7 +859,13 @@
 
 #if defined(NPY_PY3K)
     ret = PyCapsule_New(inter, NULL, gentype_struct_free);
-    PyCapsule_SetContext(ret, arr);
+    if (ret == NULL) {
+        PyErr_Clear();
+    }
+    else if (PyCapsule_SetContext(ret, arr) != 0) {
+        PyErr_Clear();
+        ret == NULL;
+    }
 #else
     ret = PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);
 #endif

Modified: trunk/numpy/core/src/multiarray/usertypes.c
===================================================================
--- trunk/numpy/core/src/multiarray/usertypes.c	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/multiarray/usertypes.c	2010-02-25 17:49:24 UTC (rev 8267)
@@ -208,6 +208,9 @@
     }
 #if defined(NPY_PY3K)
     cobj = PyCapsule_New((void *)castfunc, NULL, NULL);
+    if (cobj == NULL) {
+        PyErr_Clear();
+    }
 #else
     cobj = PyCObject_FromVoidPtr((void *)castfunc, NULL);
 #endif

Modified: trunk/numpy/core/src/umath/ufunc_object.c
===================================================================
--- trunk/numpy/core/src/umath/ufunc_object.c	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/umath/ufunc_object.c	2010-02-25 17:49:24 UTC (rev 8267)
@@ -374,6 +374,9 @@
 
 #if defined(NPY_PY3K)
     funcdata = (PyUFunc_Loop1d *)PyCapsule_GetPointer(obj, NULL);
+    if (funcdata == NULL) {
+        PyErr_Clear();
+    }
 #else
     funcdata = (PyUFunc_Loop1d *)PyCObject_AsVoidPtr(obj);
 #endif
@@ -523,6 +526,9 @@
          */
 #if defined(NPY_PY3K)
         funcdata = (PyUFunc_Loop1d *)PyCapsule_GetPointer(obj, NULL);
+        if (funcdata == NULL) {
+            PyErr_Clear();
+        }
 #else
         funcdata = (PyUFunc_Loop1d *)PyCObject_AsVoidPtr(obj);
 #endif
@@ -3976,6 +3982,9 @@
     if (cobj == NULL) {
 #if defined(NPY_PY3K)
         cobj = PyCapsule_New((void *)funcdata, NULL, _loop1d_list_free);
+        if (cobj == NULL) {
+            PyErr_Clear();
+        }
 #else
         cobj = PyCObject_FromVoidPtr((void *)funcdata, _loop1d_list_free);
 #endif
@@ -3998,6 +4007,9 @@
          */
 #if defined(NPY_PY3K)
         current = (PyUFunc_Loop1d *)PyCapsule_GetPointer(cobj, NULL);
+        if (current == NULL) {
+            PyErr_Clear();
+        }
 #else
         current = (PyUFunc_Loop1d *)PyCObject_AsVoidPtr(cobj);
 #endif

Modified: trunk/numpy/core/src/umath/umathmodule.c.src
===================================================================
--- trunk/numpy/core/src/umath/umathmodule.c.src	2010-02-25 05:20:51 UTC (rev 8266)
+++ trunk/numpy/core/src/umath/umathmodule.c.src	2010-02-25 17:49:24 UTC (rev 8267)
@@ -307,6 +307,9 @@
 
 #if defined(NPY_PY3K)
     c_api = PyCapsule_New((void *)PyUFunc_API, NULL, NULL);
+    if (c_api == NULL) {
+        PyErr_Clear();
+    }
 #else
     c_api = PyCObject_FromVoidPtr((void *)PyUFunc_API, NULL);
 #endif



More information about the Numpy-svn mailing list