summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-06-15 02:41:16 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-06-15 02:41:16 +0000
commitd5a134b8bc96cf1e63c31c0ce933e442adb77c2a (patch)
treea913a1db6352ec4680c048b75d3d2d695f961e55 /numpy
parentd1e359d1a85be3905a0c760464ba986171b589fc (diff)
downloadnumpy-d5a134b8bc96cf1e63c31c0ce933e442adb77c2a.tar.gz
Fix-up unicode comparison for mis-aligned arrays.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/arrayobject.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 5fad00a54..c77f3f91d 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -3708,22 +3708,41 @@ PyArray_CompareUCS4(PyArray_UCS4 *s1, PyArray_UCS4 *s2, register size_t len)
return 0;
}
+/* This also handles possibly mis-aligned data */
static int
_myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)
{
PyArray_UCS4 *sptr;
+ PyArray_UCS4 *s1t=s1, *s2t=s2;
int val;
+ intp size;
- val = PyArray_CompareUCS4(s1, s2, MIN(len1, len2));
- if ((val != 0) || (len1 == len2)) return val;
- if (len2 > len1) {sptr = s2+len1; val = -1;}
- else {sptr = s1+len2; val = 1;}
- if (*sptr != 0) return val;
- return 0;
+ if ((intp)s1 % sizeof(PyArray_UCS4) != 0) {
+ size = len1*sizeof(PyArray_UCS4);
+ s1t = malloc(size);
+ memcpy(s1t, s1, size);
+ }
+ if ((intp)s2 % sizeof(PyArray_UCS4) != 0) {
+ size = len2*sizeof(PyArray_UCS4);
+ s2t = malloc(size);
+ memcpy(s2t, s2, size);
+ }
+ val = PyArray_CompareUCS4(s1t, s2t, MIN(len1,len2));
+ if ((val != 0) || (len1 == len2)) goto finish;
+ if (len2 > len1) {sptr = s2t+len1; val = -1;}
+ else {sptr = s1t+len2; val = 1;}
+ if (*sptr != 0) goto finish;
+ val = 0;
+
+ finish:
+ if (s1t != s1) free(s1t);
+ if (s2t != s2) free(s2t);
+ return val;
}
+
/* Compare s1 and s2 which are not necessarily NULL-terminated.
s1 is of length len1
s2 is of length len2