summaryrefslogtreecommitdiff
path: root/numpy/core/src/arraymethods.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-04-10 23:35:58 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-04-10 23:35:58 +0000
commitc71689e56764c93535481273c6a2be857ac08764 (patch)
treeb5a2ff16ed27febb1e57e6df6da443b4a9c6ac27 /numpy/core/src/arraymethods.c
parentfe48ab5baf09f74f416aebccf7b7c68fdaa1b855 (diff)
downloadnumpy-c71689e56764c93535481273c6a2be857ac08764.tar.gz
Byteswap on pickle-read if not
in correct byte-order.
Diffstat (limited to 'numpy/core/src/arraymethods.c')
-rw-r--r--numpy/core/src/arraymethods.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c
index 0806b67e2..29d7105f8 100644
--- a/numpy/core/src/arraymethods.c
+++ b/numpy/core/src/arraymethods.c
@@ -1017,8 +1017,9 @@ array_setstate(PyArrayObject *self, PyObject *args)
}
if (typecode->type_num != PyArray_OBJECT) {
+ int swap=!PyArray_ISNOTSWAPPED(self);
self->data = datastr;
- if (!_IsAligned(self)) {
+ if (!_IsAligned(self) || swap) {
intp num = PyArray_NBYTES(self);
self->data = PyDataMem_NEW(num);
if (self->data == NULL) {
@@ -1026,7 +1027,14 @@ array_setstate(PyArrayObject *self, PyObject *args)
PyDimMem_FREE(self->dimensions);
return PyErr_NoMemory();
}
- memcpy(self->data, datastr, num);
+ if (swap) { /* byte-swap on pickle-read */
+ self->descr->f->copyswapn(self->data, datastr,
+ num, 1,
+ self->descr->elsize);
+ }
+ else {
+ memcpy(self->data, datastr, num);
+ }
self->flags |= OWN_DATA;
self->base = NULL;
}