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

numpy-svn@scip... numpy-svn@scip...
Sat Feb 9 23:12:00 CST 2008


Author: charris
Date: 2008-02-09 23:11:58 -0600 (Sat, 09 Feb 2008)
New Revision: 4783

Modified:
   trunk/numpy/core/src/arraytypes.inc.src
Log:
Fix STRING_compare function to work correctly with strings containing zeros.


Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2008-02-10 04:57:45 UTC (rev 4782)
+++ trunk/numpy/core/src/arraytypes.inc.src	2008-02-10 05:11:58 UTC (rev 4783)
@@ -1679,7 +1679,17 @@
 static int
 STRING_compare(char *ip1, char *ip2, PyArrayObject *ap)
 {
-        return strncmp(ip1, ip2, ap->descr->elsize);
+    const unsigned char *c1 = (unsigned char *)ip1;
+    const unsigned char *c2 = (unsigned char *)ip2;
+    const size_t len = ap->descr->elsize;
+    size_t i;
+
+    for(i = 0; i < len; ++i) {
+        if (c1[i] != c2[i]) {
+            return (c1[i] > c2[i]) ? 1 : -1;
+        }
+    }
+    return 0;
 }
 
 /* taken from Python */



More information about the Numpy-svn mailing list