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

numpy-svn@scip... numpy-svn@scip...
Tue Feb 27 22:01:15 CST 2007


Author: oliphant
Date: 2007-02-27 22:01:10 -0600 (Tue, 27 Feb 2007)
New Revision: 3557

Modified:
   trunk/numpy/core/src/arraytypes.inc.src
Log:
Fix getitem on a string to just truncate trailing NULLs rather than stop at interior NULLs

Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2007-02-28 03:22:18 UTC (rev 3556)
+++ trunk/numpy/core/src/arraytypes.inc.src	2007-02-28 04:01:10 UTC (rev 3557)
@@ -360,14 +360,19 @@
         return 0;
 }
 
-/* STRING -- can handle both NULL-terminated and not NULL-terminated cases */
+/* STRING -- can handle both NULL-terminated and not NULL-terminated cases 
+             will truncate all ending NULLs in returned string.
+*/    
 static PyObject *
 STRING_getitem(char *ip, PyArrayObject *ap)
 {
-        if (ip[ap->descr->elsize-1])
-                return PyString_FromStringAndSize(ip,ap->descr->elsize);
-        else
-                return PyString_FromString(ip);
+        /* Will eliminate NULLs at the end */
+        char *ptr;
+        int size = ap->descr->elsize;
+
+        ptr = ip + size-1;
+        while (*ptr-- == '\0') size--;
+        return PyString_FromStringAndSize(ip,size);
 }
 
 static int



More information about the Numpy-svn mailing list