diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-10-27 16:10:34 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-10-27 16:10:34 +0000 |
commit | 50c0847bc0f6dd4df616ac3c12d21dc423e8018c (patch) | |
tree | 8ba4d36cc73cd3685b6d62ea4485c0920128cd60 /numpy/core/src | |
parent | 4a8eb74e8e925929f3e5fd6933e50bccc91d8e23 (diff) | |
download | numpy-50c0847bc0f6dd4df616ac3c12d21dc423e8018c.tar.gz |
Re-organize user-defined check.
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/scalartypes.inc.src | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index 95ba5e96f..1bea2ef7e 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -189,16 +189,23 @@ PyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode) NULL, NULL, 0, NULL); if (r==NULL) {Py_XDECREF(outcode); return NULL;} - if (PyDataType_ISUSERDEF(typecode)) { - /* Use setitem to set array from scalar */ - if (typecode->f->setitem(scalar, PyArray_DATA(r), r) < 0) { - Py_XDECREF(outcode); - Py_DECREF(r); - return NULL; + + memptr = scalar_value(scalar, typecode); + + if (memptr == NULL) { + if (PyDataType_ISUSERDEF(typecode)) { + /* Use setitem to set array from scalar */ + if (typecode->f->setitem(scalar, + PyArray_DATA(r), r) < 0) { + Py_XDECREF(outcode); + Py_DECREF(r); + return NULL; + } } + PyErr_SetString(PyExc_ValueError, "invalid scalar"); + return NULL; } - memptr = scalar_value(scalar, typecode); #ifndef Py_UNICODE_WIDE if (typecode->type_num == PyArray_UNICODE) { PyUCS2Buffer_AsUCS4((Py_UNICODE *)memptr, |