summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorRonan Lamy <Ronan.Lamy@normalesup.org>2012-07-31 05:40:51 +0100
committerRonan Lamy <Ronan.Lamy@normalesup.org>2012-07-31 05:40:51 +0100
commit339c35f30a0a3b52b13980dabb8eeda9602b686f (patch)
tree55879ebd0e6d36834b667844aa9d05f71588103e /numpy
parentb74c6be49424012e707733871c472fd08f154834 (diff)
downloadnumpy-339c35f30a0a3b52b13980dabb8eeda9602b686f.tar.gz
Copy bytes object when unpickling an array
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/methods.c4
-rw-r--r--numpy/core/tests/test_regression.py8
2 files changed, 10 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index c4147eff2..119056c56 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -1587,8 +1587,8 @@ array_setstate(PyArrayObject *self, PyObject *args)
/* Check that the string is not interned */
if (!_IsAligned(self) || swap || PyString_CHECK_INTERNED(rawdata)) {
#else
- /* Bytes are never interned */
- if (!_IsAligned(self) || swap) {
+ /* Bytes must always be considered immutable */
+ if (1) {
#endif
npy_intp num = PyArray_NBYTES(self);
fa->data = PyDataMem_NEW(num);
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index ac36aa479..492a4f64b 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1601,6 +1601,14 @@ class TestRegression(TestCase):
s = re.sub("a(.)", "\x01\\1", "a_")
assert_equal(s[0], "\x01")
+ def test_pickle_bytes_overwrite(self):
+ if sys.version_info[0] >= 3:
+ data = np.array([1], dtype='b')
+ data = pickle.loads(pickle.dumps(data))
+ data[0] = 0xdd
+ bytestring = "\x01 ".encode('ascii')
+ assert_equal(bytestring[0:1], '\x01'.encode('ascii'))
+
def test_structured_type_to_object(self):
a_rec = np.array([(0,1), (3,2)], dtype='i4,i8')
a_obj = np.empty((2,), dtype=object)