diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2008-12-18 17:08:32 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2008-12-18 17:08:32 (GMT) |
commit | 3ad3a0d366e48798f17dc3db4377fc9659d52d05 (patch) | |
tree | 783d501b6bbe5b1bfd3ba8ef74f38fcd80f1aa05 /Lib/test/test_array.py | |
parent | f289ae6f01683689dfd07785c9617175b40aea91 (diff) | |
download | cpython-3ad3a0d366e48798f17dc3db4377fc9659d52d05.zip cpython-3ad3a0d366e48798f17dc3db4377fc9659d52d05.tar.gz cpython-3ad3a0d366e48798f17dc3db4377fc9659d52d05.tar.bz2 |
Issue #4583: crash after resizing an array.array which has buffer exports.
Diffstat (limited to 'Lib/test/test_array.py')
-rwxr-xr-x | Lib/test/test_array.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index ff9026a..5a505de 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -8,6 +8,7 @@ from test import support from weakref import proxy import array, io, math from pickle import loads, dumps +import operator class ArraySubclass(array.array): pass @@ -709,8 +710,23 @@ class BaseTest(unittest.TestCase): def test_buffer(self): a = array.array(self.typecode, self.example) - b = bytes(memoryview(a)) + m = memoryview(a) + b = bytes(m) + self.assertEqual(b, a.tostring()) self.assertEqual(b[0], a.tostring()[0]) + # Resizing is forbidden when there are buffer exports + self.assertRaises(BufferError, a.append, a[0]) + self.assertRaises(BufferError, a.extend, a[0:1]) + self.assertRaises(BufferError, a.remove, a[0]) + self.assertRaises(BufferError, a.fromlist, a.tolist()) + self.assertRaises(BufferError, a.fromstring, a.tostring()) + if self.typecode == 'u': + self.assertRaises(BufferError, a.fromunicode, a.tounicode()) + self.assertRaises(BufferError, operator.setitem, a, slice(0, 0), a) + self.assertRaises(BufferError, operator.delitem, a, 0) + self.assertRaises(BufferError, operator.delitem, a, slice(0, 1)) + self.assertRaises(BufferError, operator.irepeat, a, 2) + self.assertRaises(BufferError, operator.irepeat, a, 0) def test_weakref(self): s = array.array(self.typecode, self.example) |