summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-01-25 23:01:35 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-01-25 23:01:35 +0000
commit2a71223ff0ca8ff7c9f7cb69c73de19ae19c1782 (patch)
treeadf492ee27927fd99f6ab02c8f176ce5984559b4
parent9dc43c41723027dc9cb924e98d3e7a37f4f7069d (diff)
downloadnumpy-2a71223ff0ca8ff7c9f7cb69c73de19ae19c1782.tar.gz
Raise error when using same field names and disallow object fields for now.
-rw-r--r--numpy/core/blasdot/_dotblas.c3
-rw-r--r--numpy/core/include/numpy/arrayobject.h3
-rw-r--r--numpy/core/src/arrayobject.c12
-rw-r--r--numpy/core/src/arraytypes.inc.src4
-rw-r--r--numpy/core/src/multiarraymodule.c20
-rw-r--r--numpy/dft/fftpack_litemodule.c3
6 files changed, 34 insertions, 11 deletions
diff --git a/numpy/core/blasdot/_dotblas.c b/numpy/core/blasdot/_dotblas.c
index a919f4053..b5140b78a 100644
--- a/numpy/core/blasdot/_dotblas.c
+++ b/numpy/core/blasdot/_dotblas.c
@@ -994,7 +994,4 @@ DL_EXPORT(void) init_dotblas(void) {
Py_DECREF(d);
Py_DECREF(s);
- /* Check for errors */
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module _dotblas");
}
diff --git a/numpy/core/include/numpy/arrayobject.h b/numpy/core/include/numpy/arrayobject.h
index 2f2b68ad7..37e41a13a 100644
--- a/numpy/core/include/numpy/arrayobject.h
+++ b/numpy/core/include/numpy/arrayobject.h
@@ -74,7 +74,7 @@ extern "C" {
#define PY_SUCCEED 1
/* Helpful to distinguish what is installed */
-#define NDARRAY_VERSION 0x00090402
+#define NDARRAY_VERSION 0x00090403
/* Some platforms don't define bool, long long, or long double.
Handle that here.
@@ -847,6 +847,7 @@ typedef struct {
char type; /* unique-character representing this type */
char byteorder; /* '>' (big), '<' (little), '|'
(not-applicable), or '=' (native). */
+ char hasobject; /* non-zero if it has object arrays in fields */
int type_num; /* number representing this type */
int elsize; /* element size for this type */
int alignment; /* alignment needed for this type */
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index f82be52f1..33a86efe5 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -3761,7 +3761,14 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
self->flags |= OWN_DATA;
/* It is bad to have unitialized OBJECT pointers */
- if (descr == &OBJECT_Descr) {
+ /* which could also be sub-fields of a VOID array */
+ if (descr == &OBJECT_Descr || descr->hasobject) {
+ if (descr->hasobject) {
+ PyErr_SetString(PyExc_TypeError,
+ "fields with object members "\
+ "not yet supported.");
+ goto fail;
+ }
memset(data, 0, sd);
}
}
@@ -8039,7 +8046,8 @@ static PyMemberDef arraydescr_members[] = {
{"byteorder", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},
{"itemsize", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},
{"alignment", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},
- {NULL},
+ {"hasobject", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},
+ {NULL},
};
static PyObject *
diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src
index 4fdb2f99b..fe4d00494 100644
--- a/numpy/core/src/arraytypes.inc.src
+++ b/numpy/core/src/arraytypes.inc.src
@@ -1725,7 +1725,7 @@ static PyArray_Descr @from@_Descr = {
&Py@NAME@ArrType_Type,
PyArray_@from@LTR,
PyArray_@from@LTR,
- '@endian@',
+ '@endian@', 0,
PyArray_@from@, 0,
_ALIGN(@align@),
NULL,
@@ -1794,7 +1794,7 @@ static PyArray_Descr @from@_Descr = {
&Py@NAME@ArrType_Type,
PyArray_@kind@LTR,
PyArray_@from@LTR,
- '@endian@',
+ '@endian@', 0,
PyArray_@from@,
@num@*sizeof(@fromtyp@),
_ALIGN(@fromtyp@),
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c
index 5b23b72f5..966886d04 100644
--- a/numpy/core/src/multiarraymodule.c
+++ b/numpy/core/src/multiarraymodule.c
@@ -3421,6 +3421,7 @@ _convert_from_array_descr(PyObject *obj)
PyObject *nameslist;
PyArray_Descr *new;
PyArray_Descr *conv;
+ int hasobject=0;
n = PyList_GET_SIZE(obj);
nameslist = PyList_New(n);
@@ -3453,6 +3454,14 @@ _convert_from_array_descr(PyObject *obj)
}
else goto fail;
if (ret == PY_FAIL) goto fail;
+ if (PyDict_GetItem(fields, name) != NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "two fields with the same name");
+ goto fail;
+ }
+ if (!hasobject && (conv->hasobject || \
+ conv->type_num == PyArray_OBJECT))
+ hasobject = 1;
tup = PyTuple_New(2);
PyTuple_SET_ITEM(tup, 0, (PyObject *)conv);
PyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));
@@ -3467,6 +3476,7 @@ _convert_from_array_descr(PyObject *obj)
new = PyArray_DescrNewFromType(PyArray_VOID);
new->fields = fields;
new->elsize = totalsize;
+ new->hasobject=hasobject;
return new;
fail:
@@ -3496,6 +3506,7 @@ _convert_from_list(PyObject *obj, int align, int try_descr)
PyObject *nameslist=NULL;
int ret;
int maxalign=0;
+ int hasobject=0;
n = PyList_GET_SIZE(obj);
totalsize = 0;
@@ -3507,6 +3518,9 @@ _convert_from_list(PyObject *obj, int align, int try_descr)
tup = PyTuple_New(2);
key = PyString_FromFormat("f%d", i+1);
ret = PyArray_DescrConverter(PyList_GET_ITEM(obj, i), &conv);
+ if (!hasobject && (conv->hasobject || \
+ conv->type_num == PyArray_OBJECT))
+ hasobject=1;
PyTuple_SET_ITEM(tup, 0, (PyObject *)conv);
if (align) {
int _align;
@@ -3528,6 +3542,7 @@ _convert_from_list(PyObject *obj, int align, int try_descr)
Py_DECREF(nameslist);
new = PyArray_DescrNewFromType(PyArray_VOID);
new->fields = fields;
+ new->hasobject=hasobject;
if (maxalign > 1) {
totalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;
}
@@ -3630,6 +3645,7 @@ _convert_from_dict(PyObject *obj, int align)
int n, i;
int totalsize;
int maxalign=0;
+ int hasobject=0;
fields = PyDict_New();
if (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();
@@ -3672,6 +3688,9 @@ _convert_from_dict(PyObject *obj, int align)
tup = PyTuple_New(len);
descr = PyObject_GetItem(descrs, index);
ret = PyArray_DescrConverter(descr, &newdescr);
+ if (!hasobject && (newdescr->hasobject || \
+ newdescr->type_num == PyArray_OBJECT))
+ hasobject = 1;
Py_DECREF(descr);
PyTuple_SET_ITEM(tup, 0, (PyObject *)newdescr);
if (offsets) {
@@ -3724,6 +3743,7 @@ _convert_from_dict(PyObject *obj, int align)
PyDict_SetItem(fields, key, names);
Py_DECREF(key);
new->fields = fields;
+ new->hasobject=hasobject;
return new;
fail:
diff --git a/numpy/dft/fftpack_litemodule.c b/numpy/dft/fftpack_litemodule.c
index bc6d6bbe9..4fdfa1043 100644
--- a/numpy/dft/fftpack_litemodule.c
+++ b/numpy/dft/fftpack_litemodule.c
@@ -260,7 +260,4 @@ initfftpack_lite(void)
/* XXXX Add constants here */
- /* Check for errors */
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module fftpack");
}