diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-11 22:14:56 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-11 22:14:56 +0000 |
commit | 26d3328c64bc8437f37b49fcc4ed3c7d5cfa7e97 (patch) | |
tree | 98747ec7aec9a0753fc580d7773d0679c76b1c19 /numpy | |
parent | ec2a036800c2c0867789684c188f25f6bacecc73 (diff) | |
download | numpy-26d3328c64bc8437f37b49fcc4ed3c7d5cfa7e97.tar.gz |
Some fixes to array interface on Numpy side --- make sure descr pointer is NULL if not used and XDECREF it on interface free.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/arrayobject.c | 6 | ||||
-rw-r--r-- | numpy/core/src/scalartypes.inc.src | 9 |
2 files changed, 11 insertions, 4 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 81c8dcf98..1e155fd00 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -6087,6 +6087,7 @@ array_struct_get(PyArrayObject *self) 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 @@ array_struct_get(PyArrayObject *self) */ 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 @@ array_struct_get(PyArrayObject *self) 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); } diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index 1f92ee24e..e680b9fc4 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -730,11 +730,11 @@ gentype_size_get(PyObject *self) 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 @@ gentype_struct_get(PyObject *self) inter->strides = NULL; inter->shape = NULL; inter->data = arr->data; + inter->descr = NULL; return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free); } |