diff options
author | Raymond Hettinger <python@rcn.com> | 2007-04-02 22:39:08 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-04-02 22:39:08 (GMT) |
commit | d6030acd7f974fc8595b514032e1801e68fec300 (patch) | |
tree | 5d288d34c24561f4a2f8eea02f8236d59a4b748e | |
parent | 4bbcb64d5d6560d8adca119f153779d0d18e0482 (diff) | |
download | cpython-d6030acd7f974fc8595b514032e1801e68fec300.zip cpython-d6030acd7f974fc8595b514032e1801e68fec300.tar.gz cpython-d6030acd7f974fc8595b514032e1801e68fec300.tar.bz2 |
Array module's buffer interface can now handle empty arrays.
-rw-r--r-- | Lib/test/test_re.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/arraymodule.c | 6 |
3 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index a885180..f15ce09 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -604,6 +604,13 @@ class ReTests(unittest.TestCase): self.assertEqual(iter.next().span(), (4, 4)) self.assertRaises(StopIteration, iter.next) + def test_empty_array(self): + # SF buf 1647541 + import array + for typecode in 'cbBuhHiIlLfd': + a = array.array(typecode) + self.assertEqual(re.compile("bla").match(a), None) + self.assertEqual(re.compile("").match(a).groups(), ()) def run_re_tests(): from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR @@ -134,6 +134,8 @@ Core and builtins Extension Modules ----------------- +- Bug #1647541: Array module's buffer interface can now handle empty arrays. + - Bug #1693079: The array module can now successfully pickle empty arrays. - Bug #1688393: Prevent crash in socket.recvfrom if length is negative. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 0aeb64e..3ba5cf8 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1745,6 +1745,8 @@ static PyMappingMethods array_as_mapping = { (objobjargproc)array_ass_subscr }; +static const void *emptybuf = ""; + static Py_ssize_t array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr) { @@ -1754,6 +1756,8 @@ array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr) return -1; } *ptr = (void *)self->ob_item; + if (*ptr == NULL) + *ptr = emptybuf; return self->ob_size*self->ob_descr->itemsize; } @@ -1766,6 +1770,8 @@ array_buffer_getwritebuf(arrayobject *self, Py_ssize_t index, const void **ptr) return -1; } *ptr = (void *)self->ob_item; + if (*ptr == NULL) + *ptr = emptybuf; return self->ob_size*self->ob_descr->itemsize; } |