[Numpy-svn] r2999 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Aug 11 17:15:00 CDT 2006


Author: oliphant
Date: 2006-08-11 17:14:56 -0500 (Fri, 11 Aug 2006)
New Revision: 2999

Modified:
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/core/src/scalartypes.inc.src
Log:
Some fixes to array interface on Numpy side --- make sure descr pointer is NULL if not used and XDECREF it on interface free.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-08-11 20:46:36 UTC (rev 2998)
+++ trunk/numpy/core/src/arrayobject.c	2006-08-11 22:14:56 UTC (rev 2999)
@@ -6087,6 +6087,7 @@
         PyArrayInterface *inter;
 
         inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));
+        if (inter==NULL) return PyErr_NoMemory();
         inter->two = 2;
         inter->nd = self->nd;
         inter->typekind = self->descr->kind;
@@ -6100,6 +6101,10 @@
         */
         if (self->nd > 0) {
                 inter->shape = (intp *)_pya_malloc(2*sizeof(intp)*self->nd);
+                if (inter->shape == NULL) {
+                        _pya_free(inter);
+                        return PyErr_NoMemory();
+                }
                 inter->strides = inter->shape + self->nd;
                 memcpy(inter->shape, self->dimensions, sizeof(intp)*self->nd);
                 memcpy(inter->strides, self->strides, sizeof(intp)*self->nd);
@@ -6114,6 +6119,7 @@
                 if (inter->descr == NULL) PyErr_Clear();
                 else inter->flags &= ARR_HAS_DESCR;
         }
+        else inter->descr = NULL;
         Py_INCREF(self);
         return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);
 }

Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2006-08-11 20:46:36 UTC (rev 2998)
+++ trunk/numpy/core/src/scalartypes.inc.src	2006-08-11 22:14:56 UTC (rev 2999)
@@ -730,11 +730,11 @@
 static void
 gentype_struct_free(void *ptr, void *arg)
 {
+        PyArrayInterface *arrif = (PyArrayInterface *)ptr;
         Py_DECREF((PyObject *)arg);
-        if (((PyArrayInterface *)ptr)->shape != NULL) {
-                _pya_free(((PyArrayInterface *)ptr)->shape);
-        }
-        _pya_free(ptr);
+        Py_XDECREF(arrif->descr);
+        _pya_free(arrif->shape);
+        _pya_free(arrif);
 }
 
 static PyObject *
@@ -753,6 +753,7 @@
         inter->strides = NULL;
         inter->shape = NULL;
         inter->data = arr->data;
+        inter->descr = NULL;
 
         return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);
 }



More information about the Numpy-svn mailing list