[Numpy-svn] r8085 - in trunk/numpy: . core/src/multiarray

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Feb 4 09:40:55 EST 2010


Author: oliphant
Date: 2010-02-04 08:40:55 -0600 (Thu, 04 Feb 2010)
New Revision: 8085

Modified:
   trunk/numpy/core/src/multiarray/ctors.c
   trunk/numpy/ctypeslib.py
Log:
BUG: Fix #1388. Return NULL after setting error.   Also simplify ctypeslib prep_simple function.

Modified: trunk/numpy/core/src/multiarray/ctors.c
===================================================================
--- trunk/numpy/core/src/multiarray/ctors.c	2010-02-02 04:54:53 UTC (rev 8084)
+++ trunk/numpy/core/src/multiarray/ctors.c	2010-02-04 14:40:55 UTC (rev 8085)
@@ -3121,8 +3121,11 @@
 
     if ((offset < 0) || (offset >= ts)) {
         PyErr_Format(PyExc_ValueError,
-                     "offset must be positive and smaller than %"
-                     INTP_FMT, (intp)ts);
+                     "offset must be non-negative and smaller than buffer "\
+                     "lenth (%" INTP_FMT ")", (intp)ts);
+        Py_DECREF(buf);
+        Py_DECREF(type);
+        return NULL;
     }
 
     data += offset;

Modified: trunk/numpy/ctypeslib.py
===================================================================
--- trunk/numpy/ctypeslib.py	2010-02-02 04:54:53 UTC (rev 8084)
+++ trunk/numpy/ctypeslib.py	2010-02-04 14:40:55 UTC (rev 8085)
@@ -294,14 +294,15 @@
     # c_double. Filled in by prep_simple.
     _typecodes = {}
 
-    def prep_simple(simple_type, typestr):
+    def prep_simple(simple_type, dtype):
         """Given a ctypes simple type, construct and attach an
         __array_interface__ property to it if it does not yet have one.
         """
         try: simple_type.__array_interface__
         except AttributeError: pass
         else: return
-
+	
+	typestr = _dtype(dtype).str
         _typecodes[typestr] = simple_type
 
         def __array_interface__(self):
@@ -316,11 +317,6 @@
 
         simple_type.__array_interface__ = property(__array_interface__)
 
-    if sys.byteorder == "little":
-        TYPESTR = "<%c%d"
-    else:
-        TYPESTR = ">%c%d"
-
     simple_types = [
         ((ct.c_byte, ct.c_short, ct.c_int, ct.c_long, ct.c_longlong), "i"),
         ((ct.c_ubyte, ct.c_ushort, ct.c_uint, ct.c_ulong, ct.c_ulonglong), "u"),
@@ -330,7 +326,7 @@
     # Prep that numerical ctypes types:
     for types, code in simple_types:
         for tp in types:
-            prep_simple(tp, TYPESTR % (code, ct.sizeof(tp)))
+            prep_simple(tp, "%c%d" % (code, ct.sizeof(tp)))
 
     ################################################################
     # array types




More information about the Numpy-svn mailing list