diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-11 07:09:36 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-11 07:09:36 +0000 |
commit | 59a421dba03c127672e13be07bbbdb81e72f1188 (patch) | |
tree | e0328886c48879d8bc94fbc64fde7db89e3a90fe /numpy/core/src/arrayobject.c | |
parent | cceb25c8c4b0d7c35d2629c9a8004abb8fda9574 (diff) | |
download | numpy-59a421dba03c127672e13be07bbbdb81e72f1188.tar.gz |
Rework meaning of isnative so it takes into account the fields.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 4a004f313..fcfb70a52 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -10367,12 +10367,39 @@ arraydescr_isbuiltin_get(PyArray_Descr *self) return PyInt_FromLong(val); } +static int +_arraydescr_isnative(PyArray_Descr *self) +{ + if (self->names == NULL) { + return PyArray_ISNBO(self->byteorder); + } + else { + 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)) return -1; + if (!_arraydescr_isnative(new)) return 0; + } + } + return 1; +} + +/* return Py_True if this data-type descriptor + has native byteorder if no fields are defined + + or if all sub-fields have native-byteorder if + fields are defined +*/ static PyObject * arraydescr_isnative_get(PyArray_Descr *self) { PyObject *ret; - - ret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False); + int retval; + retval = _arraydescr_isnative(self); + if (retval == -1) return NULL; + ret = (retval ? Py_True : Py_False); Py_INCREF(ret); return ret; } |