diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-02-15 19:25:32 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-02-15 19:25:32 +0000 |
commit | 2b36f2037f212a884c68a126c30de299ad67057c (patch) | |
tree | e323bb93c17ae849f360027c1e1e9b94875745bf /numpy/core | |
parent | 7f0f842347b0be584df48ea08b18341e05e641b2 (diff) | |
download | numpy-2b36f2037f212a884c68a126c30de299ad67057c.tar.gz |
Change the -1 entry of the fields dict to always be a tuple and enforce it on conversion from the names sequence.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/arraytypes.inc.src | 8 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 15 | ||||
-rw-r--r-- | numpy/core/src/scalartypes.inc.src | 11 |
3 files changed, 19 insertions, 15 deletions
diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src index 30c254f65..468728154 100644 --- a/numpy/core/src/arraytypes.inc.src +++ b/numpy/core/src/arraytypes.inc.src @@ -381,11 +381,11 @@ VOID_getitem(char *ip, PyArrayObject *ap) names = PyDict_GetItem(descr->fields, key); Py_DECREF(key); if (!names) goto finish; - n = PyList_GET_SIZE(names); + n = PyTuple_GET_SIZE(names); ret = PyTuple_New(n); savedflags = ap->flags; for (i=0; i<n; i++) { - key = PyList_GET_ITEM(names, i); + key = PyTuple_GET_ITEM(names, i); tup = PyDict_GetItem(descr->fields, key); if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, &title)) { @@ -476,7 +476,7 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) names = PyDict_GetItem(descr->fields, key); Py_DECREF(key); if (!names) goto finish; - n = PyList_GET_SIZE(names); + n = PyTuple_GET_SIZE(names); if (PyTuple_GET_SIZE(op) != n) { PyErr_SetString(PyExc_ValueError, "size of tuple must match"\ @@ -485,7 +485,7 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) } savedflags = ap->flags; for (i=0; i<n; i++) { - key = PyList_GET_ITEM(names, i); + key = PyTuple_GET_ITEM(names, i); tup = PyDict_GetItem(descr->fields, key); if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, &title)) { diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index 868fa2361..b5bc6af6a 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -3504,7 +3504,7 @@ _convert_from_array_descr(PyObject *obj) int hasobject=0; n = PyList_GET_SIZE(obj); - nameslist = PyList_New(n); + nameslist = PyTuple_New(n); if (!nameslist) return NULL; totalsize = 0; fields = PyDict_New(); @@ -3519,7 +3519,7 @@ _convert_from_array_descr(PyObject *obj) else { Py_INCREF(name); } - PyList_SET_ITEM(nameslist, i, name); + PyTuple_SET_ITEM(nameslist, i, name); if (PyTuple_GET_SIZE(item) == 2) { ret = PyArray_DescrConverter(PyTuple_GET_ITEM(item, 1), &conv); @@ -3590,7 +3590,7 @@ _convert_from_list(PyObject *obj, int align, int try_descr) n = PyList_GET_SIZE(obj); totalsize = 0; if (n==0) return NULL; - nameslist = PyList_New(n); + nameslist = PyTuple_New(n); if (!nameslist) return NULL; fields = PyDict_New(); for (i=0; i<n; i++) { @@ -3615,7 +3615,7 @@ _convert_from_list(PyObject *obj, int align, int try_descr) PyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize)); PyDict_SetItem(fields, key, tup); Py_DECREF(tup); - PyList_SET_ITEM(nameslist, i, key); + PyTuple_SET_ITEM(nameslist, i, key); totalsize += conv->elsize; } key = PyInt_FromLong(-1); @@ -3831,7 +3831,12 @@ _convert_from_dict(PyObject *obj, int align) if (align) new->alignment = maxalign; new->elsize = totalsize; key = PyInt_FromLong(-1); - PyDict_SetItem(fields, key, names); + if (!PyTuple_Check(names)) { + names = PySequence_Tuple(names); + PyDict_SetItem(fields, key, names); + Py_DECREF(names); + } + else PyDict_SetItem(fields, key, names); Py_DECREF(key); new->fields = fields; new->hasobject=hasobject; diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index bdf5402db..2f48ff041 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -1420,7 +1420,6 @@ static PyMethodDef voidtype_methods[] = { /************* As_mapping functions for void array scalar ************/ - static int voidtype_length(PyVoidScalarObject *self) { @@ -1434,7 +1433,7 @@ voidtype_length(PyVoidScalarObject *self) flist = PyDict_GetItem(self->descr->fields, key); Py_DECREF(key); if (!flist) return 0; - return PyList_GET_SIZE(flist); + return PyTuple_GET_SIZE(flist); } } @@ -1472,11 +1471,11 @@ voidtype_subscript(PyVoidScalarObject *self, PyObject *ind) flist = PyDict_GetItem(self->descr->fields, key); Py_DECREF(key); if (!flist) m = 0; - m = PyList_GET_SIZE(flist); + m = PyTuple_GET_SIZE(flist); if (n < 0) n += m; if (n < 0 || n >= m) goto fail; fieldinfo = PyDict_GetItem(self->descr->fields, - PyList_GET_ITEM(flist, n)); + PyTuple_GET_ITEM(flist, n)); return voidtype_getfield(self, fieldinfo, NULL); fail: @@ -1525,11 +1524,11 @@ voidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) flist = PyDict_GetItem(self->descr->fields, key); Py_DECREF(key); if (!flist) m = 0; - m = PyList_GET_SIZE(flist); + m = PyTuple_GET_SIZE(flist); if (n < 0) n += m; if (n < 0 || n >= m) goto fail; fieldinfo = PyDict_GetItem(self->descr->fields, - PyList_GET_ITEM(flist, n)); + PyTuple_GET_ITEM(flist, n)); newtup = Py_BuildValue("(OOO)", val, PyTuple_GET_ITEM(fieldinfo, 0), PyTuple_GET_ITEM(fieldinfo, 1)); |