diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-06-27 01:31:41 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-06-27 01:31:41 +0000 |
commit | 7e4a505ceebc45e4bc90cf5093b6f59aa1125be8 (patch) | |
tree | 065755127e5f6151f91bdb9446c07970607150fe /numpy | |
parent | db8442b04f2b8dcc714dd974d0bd6407e9e054ef (diff) | |
download | numpy-7e4a505ceebc45e4bc90cf5093b6f59aa1125be8.tar.gz |
Fixes for objects in arrays.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/records.py | 1 | ||||
-rw-r--r-- | numpy/core/src/arraymethods.c | 2 | ||||
-rw-r--r-- | numpy/core/src/arrayobject.c | 19 | ||||
-rw-r--r-- | numpy/core/src/arraytypes.inc.src | 4 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 2 | ||||
-rw-r--r-- | numpy/core/src/scalartypes.inc.src | 23 |
6 files changed, 43 insertions, 8 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py index 333bc486e..5d4f9f62a 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -269,6 +269,7 @@ def fromarrays(arrayList, formats=None, names=None, titles=None, shape=None, parsed = format_parser(formats, names, titles, aligned) _names = parsed._names + raise _array = recarray(shape, parsed._descr) # populate the record array (makes a copy) diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c index 79033d66b..d4567401b 100644 --- a/numpy/core/src/arraymethods.c +++ b/numpy/core/src/arraymethods.c @@ -773,6 +773,8 @@ _deepcopy_call(char *iptr, char *optr, PyArray_Descr *dtype, PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(dtype->fields, &pos, &key, &value)) { + if (PyInt_Check(key) && PyInt_AsLong(key) == -1) + continue; if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; _deepcopy_call(iptr + offset, optr + offset, new, diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index fb649893c..fd0fe4122 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -166,6 +166,8 @@ PyArray_Item_INCREF(char *data, PyArray_Descr *descr) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(descr->fields, &pos, &key, &value)) { + if (PyInt_Check(key) && PyInt_AsLong(key) == -1) + continue; if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; PyArray_Item_INCREF(data + offset, new); @@ -193,6 +195,8 @@ PyArray_Item_XDECREF(char *data, PyArray_Descr *descr) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(descr->fields, &pos, &key, &value)) { + if (PyInt_Check(key) && PyInt_AsLong(key) == -1) + continue; if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; PyArray_Item_XDECREF(data + offset, new); @@ -1727,8 +1731,12 @@ array_dealloc(PyArrayObject *self) { if ((self->flags & OWN_DATA) && self->data) { /* Free internal references if an Object array */ - if (self->descr->hasobject) + if (self->descr->hasobject) { + Py_INCREF(self); /*hold on to self */ PyArray_XDECREF(self); + /* Don't need to DECREF -- because we are deleting + self already... */ + } PyDataMem_FREE(self->data); } @@ -4882,6 +4890,8 @@ _putzero(char *optr, PyObject *zero, PyArray_Descr *dtype) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(dtype->fields, &pos, &key, &value)) { + if (PyInt_Check(key) && PyInt_AsLong(key) == -1) + continue; if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; _putzero(optr + offset, zero, new); @@ -5038,6 +5048,8 @@ _fillobject(char *optr, PyObject *obj, PyArray_Descr *dtype) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(dtype->fields, &pos, &key, &value)) { + if (PyInt_Check(key) && PyInt_AsLong(key) == -1) + continue; if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; _fillobject(optr + offset, obj, new); @@ -5070,6 +5082,7 @@ PyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj) } else { char *optr; + optr = arr->data; for (i=0; i<n; i++) { _fillobject(optr, obj, arr->descr); optr += arr->descr->elsize; @@ -5231,6 +5244,10 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) if (ret == NULL) {descr=NULL;goto fail;} if (descr->hasobject) { /* place Py_None in object positions */ PyArray_FillObjectArray(ret, Py_None); + if (PyErr_Occurred()) { + descr=NULL; + goto fail; + } } } else { /* buffer given -- use it */ diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src index ff299c2e7..0baa68a8c 100644 --- a/numpy/core/src/arraytypes.inc.src +++ b/numpy/core/src/arraytypes.inc.src @@ -1220,6 +1220,8 @@ VOID_copyswapn (char *dst, intp dstride, char *src, intp sstride, int offset, pos=0; descr = arr->descr; while (PyDict_Next(descr->fields, &pos, &key, &value)) { + if (PyInt_Check(key) && PyInt_AsLong(key) == -1) + continue; if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {arr->descr=descr;return;} arr->descr = new; @@ -1244,6 +1246,8 @@ VOID_copyswap (char *dst, char *src, int swap, PyArrayObject *arr) int offset, pos=0; descr = arr->descr; /* Save it */ while (PyDict_Next(descr->fields, &pos, &key, &value)) { + if (PyInt_Check(key) && PyInt_AsLong(key) == -1) + continue; if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {arr->descr=descr;return;} arr->descr = new; diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index dbbc1593a..49bcfca69 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -4677,6 +4677,7 @@ PyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran) if (type->hasobject) { PyArray_FillObjectArray(ret, Py_None); + if (PyErr_Occurred()) {Py_DECREF(ret); return NULL;} } return (PyObject *)ret; } @@ -4802,6 +4803,7 @@ PyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran) PyObject *zero = PyInt_FromLong(0); PyArray_FillObjectArray(ret, zero); Py_DECREF(zero); + if (PyErr_Occurred()) {Py_DECREF(ret); return NULL;} } else { n = PyArray_NBYTES(ret); diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index f1c133230..5aa0cb89e 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -1164,13 +1164,22 @@ voidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds) dptr = self->obval + offset; - /* Copy data from value to correct place in dptr */ - src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS, NULL); - if (src == NULL) return NULL; - typecode->f->copyswap(dptr, PyArray_DATA(src), - !PyArray_ISNBO(self->descr->byteorder), - src); - Py_DECREF(src); + if (typecode->type_num == PyArray_OBJECT) { + PyObject **temp; + Py_INCREF(value); + temp = (PyObject **)dptr; + Py_XDECREF(*temp); + memcpy(temp, &value, sizeof(PyObject *)); + } + else { + /* Copy data from value to correct place in dptr */ + src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS, NULL); + if (src == NULL) return NULL; + typecode->f->copyswap(dptr, PyArray_DATA(src), + !PyArray_ISNBO(self->descr->byteorder), + src); + Py_DECREF(src); + } Py_INCREF(Py_None); return Py_None; } |