[Numpy-svn] r3405 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Oct 27 11:10:37 CDT 2006


Author: oliphant
Date: 2006-10-27 11:10:34 -0500 (Fri, 27 Oct 2006)
New Revision: 3405

Modified:
   trunk/numpy/core/src/scalartypes.inc.src
Log:
Re-organize user-defined check.

Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2006-10-27 16:03:16 UTC (rev 3404)
+++ trunk/numpy/core/src/scalartypes.inc.src	2006-10-27 16:10:34 UTC (rev 3405)
@@ -189,16 +189,23 @@
                                  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,



More information about the Numpy-svn mailing list