c8ca126fdd
* Sun Aug 5 2012 David Malcolm <dmalcolm@redhat.com> - 1:1.6.2-5 - rework patches for 3.3 to more directly reflect upstream's commits - re-enable test suite on python 3 - forcibly regenerate Cython .c source to avoid import issues on Python 3.3
51 lines
1.6 KiB
Diff
51 lines
1.6 KiB
Diff
commit f2ac38f09ff258339ef44572a3abba02019e1f55
|
|
Author: Ondrej Certik <ondrej.certik@gmail.com>
|
|
Date: Fri Aug 3 10:39:25 2012 -0700
|
|
|
|
Use PyUnicode_DecodeUTF32()
|
|
|
|
This function handles the swapping automatically and it returns a unicode
|
|
object in one of: UCS1, UCS2 or UCS4 internal Python format.
|
|
|
|
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
|
|
index 97a5e4b..d9bc492 100644
|
|
--- a/numpy/core/src/multiarray/scalarapi.c
|
|
+++ b/numpy/core/src/multiarray/scalarapi.c
|
|
@@ -644,25 +644,18 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
|
|
#if PY_VERSION_HEX >= 0x03030000
|
|
if (type_num == NPY_UNICODE) {
|
|
PyObject *u, *args;
|
|
- char *buffer;
|
|
+ int byteorder;
|
|
|
|
- if (swap) {
|
|
- buffer = malloc(itemsize);
|
|
- if (buffer == NULL) {
|
|
- PyErr_NoMemory();
|
|
- return NULL;
|
|
- }
|
|
- memcpy(buffer, data, itemsize);
|
|
- byte_swap_vector(buffer, itemsize >> 2, 4);
|
|
- }
|
|
- else {
|
|
- buffer = data;
|
|
- }
|
|
- u = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer,
|
|
- itemsize >> 2);
|
|
- if (swap) {
|
|
- free(buffer);
|
|
- }
|
|
+#if NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
|
|
+ byteorder = -1;
|
|
+#elif NPY_BYTE_ORDER == NPY_BIG_ENDIAN
|
|
+ byteorder = +1;
|
|
+#else
|
|
+ #error Endianness undefined ?
|
|
+#endif
|
|
+ if (swap) byteorder *= -1;
|
|
+
|
|
+ u = PyUnicode_DecodeUTF32(data, itemsize, NULL, &byteorder);
|
|
if (u == NULL) {
|
|
return NULL;
|
|
}
|