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

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Aug 11 15:46:40 CDT 2006


Author: oliphant
Date: 2006-08-11 15:46:36 -0500 (Fri, 11 Aug 2006)
New Revision: 2998

Modified:
   trunk/numpy/core/src/arraymethods.c
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/core/src/multiarraymodule.c
Log:
Check for errors when casting from non-number types.

Modified: trunk/numpy/core/src/arraymethods.c
===================================================================
--- trunk/numpy/core/src/arraymethods.c	2006-08-11 20:16:43 UTC (rev 2997)
+++ trunk/numpy/core/src/arraymethods.c	2006-08-11 20:46:36 UTC (rev 2998)
@@ -531,7 +531,7 @@
 		return obj;
 	}
 	if (descr->names != NULL) {
-		return PyArray_FromArray(self, descr, 0);
+		return PyArray_FromArray(self, descr, NPY_FORCECAST);
 	}
 	return _ARET(PyArray_CastToType(self, descr, 0));
 }	  

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-08-11 20:16:43 UTC (rev 2997)
+++ trunk/numpy/core/src/arrayobject.c	2006-08-11 20:46:36 UTC (rev 2998)
@@ -7301,6 +7301,7 @@
         }
         _pya_free(buffers[0]);
         _pya_free(buffers[1]);
+        if (!PyArray_ISNUMBER(in) && PyErr_Occurred()) return -1;
         return 0;
 }
 
@@ -7354,7 +7355,7 @@
                 if (PyArray_ISNUMBER(mp) && PyArray_ISNUMBER(out)) {
                         NPY_END_THREADS   }
 #endif
-                return 0;
+                if (!PyArray_ISNUMBER(mp) && PyErr_Occurred()) return -1;
         }
 
         /* If the input or output is STRING, UNICODE, or VOID */
@@ -8209,8 +8210,9 @@
 
         obj = PyArray_FromAny(op, descr, min_depth, max_depth,
                               requires, context);
+        if (obj == NULL) return NULL;
         if ((requires & ELEMENTSTRIDES) && 
-            (obj && !PyArray_ElementStrides(obj))) {
+            !PyArray_ElementStrides(obj)) {
                 PyObject *new;
                 new = PyArray_NewCopy((PyArrayObject *)obj, PyArray_ANYORDER);
                 Py_DECREF(obj);

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2006-08-11 20:16:43 UTC (rev 2997)
+++ trunk/numpy/core/src/multiarraymodule.c	2006-08-11 20:46:36 UTC (rev 2998)
@@ -5013,8 +5013,7 @@
                 flags |= ENSUREARRAY;
         }
 
-	if ((ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL)) == NULL) 
-		return NULL;
+        ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL);
 
  finish:
 	if (!ret || (nd=PyArray_NDIM(ret)) >= ndmin) return ret;



More information about the Numpy-svn mailing list