diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-07-18 19:02:34 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-07-18 19:02:34 +0000 |
commit | fe9508708db30fde8629269792d25bea838a86e5 (patch) | |
tree | 7bde618778f749d6b5699aa1aec21e564b1a4e5f /numpy/core/src/arrayobject.c | |
parent | 70ff09c6be8979d81a26297e54962b3a5108510d (diff) | |
download | numpy-fe9508708db30fde8629269792d25bea838a86e5.tar.gz |
Fix pickling of dtype objects with hasobject set so hasobject gets set on un-pickle.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index ec83e1648..8bc8e0026 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -159,7 +159,7 @@ PyArray_Item_INCREF(char *data, PyArray_Descr *descr) temp = (PyObject **)data; Py_XINCREF(*temp); } - else if PyDescr_HASFIELDS(descr) { + else if (PyDescr_HASFIELDS(descr)) { PyObject *key, *value, *title=NULL; PyArray_Descr *new; int offset, pos=0; @@ -10465,6 +10465,34 @@ arraydescr_reduce(PyArray_Descr *self, PyObject *args) return ret; } +/* returns 1 if this data-type has an object portion + + used when setting the state because hasobject is not stored. + */ +static int +_descr_find_object(PyArray_Descr *self) +{ + if (self->hasobject || self->type_num == PyArray_OBJECT || self->kind == 'O') + return 1; + if (PyDescr_HASFIELDS(self)) { + PyObject *key, *value, *title=NULL; + PyArray_Descr *new; + int offset, pos=0; + while (PyDict_Next(self->fields, &pos, &key, &value)) { + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + &title)) { + PyErr_Clear(); + return 0; + } + if (_descr_find_object(new)) { + new->hasobject = 1; + return 1; + } + } + } + return 0; +} + /* state is at least byteorder, subarray, and fields but could include elsize and alignment for EXTENDED arrays */ @@ -10484,8 +10512,9 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) if (!PyArg_ParseTuple(args, "(icOOOii)", &version, &endian, &subarray, &names, &fields, &elsize, &alignment)) { PyErr_Clear(); - if (!PyArg_ParseTuple(args, "(icOOii)", &version, &endian, &subarray, - &fields, &elsize, &alignment)) { + if (!PyArg_ParseTuple(args, "(icOOii)", &version, &endian, + &subarray, &fields, &elsize, + &alignment)) { PyErr_Clear(); version = 0; if (!PyArg_ParseTuple(args, "(cOOii)", &endian, &subarray, @@ -10563,6 +10592,7 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) self->alignment = alignment; } + self->hasobject = _descr_find_object(self); Py_INCREF(Py_None); return Py_None; } |