[Numpy-svn] r8147 - trunk/numpy/core/src/multiarray

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 12:08:14 CST 2010


Author: ptvirtan
Date: 2010-02-20 12:08:14 -0600 (Sat, 20 Feb 2010)
New Revision: 8147

Modified:
   trunk/numpy/core/src/multiarray/common.c
Log:
BUG: core: prefer byte strings over PEP 3118 buffers when determining array type in _array_find_type

Modified: trunk/numpy/core/src/multiarray/common.c
===================================================================
--- trunk/numpy/core/src/multiarray/common.c	2010-02-20 18:07:57 UTC (rev 8146)
+++ trunk/numpy/core/src/multiarray/common.c	2010-02-20 18:08:14 UTC (rev 8147)
@@ -195,6 +195,21 @@
         goto finish;
     }
 
+    if (PyBytes_Check(op)) {
+        chktype = PyArray_DescrNewFromType(PyArray_STRING);
+        chktype->elsize = PyString_GET_SIZE(op);
+        goto finish;
+    }
+
+    if (PyUnicode_Check(op)) {
+        chktype = PyArray_DescrNewFromType(PyArray_UNICODE);
+        chktype->elsize = PyUnicode_GET_DATA_SIZE(op);
+#ifndef Py_UNICODE_WIDE
+        chktype->elsize <<= 1;
+#endif
+        goto finish;
+    }
+
 #if PY_VERSION_HEX >= 0x02070000
     /* PEP 3118 buffer interface */
     memset(&buffer_view, 0, sizeof(Py_buffer));
@@ -258,21 +273,6 @@
         PyErr_Clear();
     }
 
-    if (PyString_Check(op)) {
-        chktype = PyArray_DescrNewFromType(PyArray_STRING);
-        chktype->elsize = PyString_GET_SIZE(op);
-        goto finish;
-    }
-
-    if (PyUnicode_Check(op)) {
-        chktype = PyArray_DescrNewFromType(PyArray_UNICODE);
-        chktype->elsize = PyUnicode_GET_DATA_SIZE(op);
-#ifndef Py_UNICODE_WIDE
-        chktype->elsize <<= 1;
-#endif
-        goto finish;
-    }
-
 #if !defined(NPY_PY3K)
     if (PyBuffer_Check(op)) {
         chktype = PyArray_DescrNewFromType(PyArray_VOID);



More information about the Numpy-svn mailing list