[Python-checkins] r54662 - in python/branches/release25-maint: Lib/test/test_re.py Misc/NEWS Modules/arraymodule.c

raymond.hettinger python-checkins at python.org
Tue Apr 3 00:39:13 CEST 2007


Author: raymond.hettinger
Date: Tue Apr 3 00:39:08 2007
New Revision: 54662
Modified:
 python/branches/release25-maint/Lib/test/test_re.py
 python/branches/release25-maint/Misc/NEWS
 python/branches/release25-maint/Modules/arraymodule.c
Log:
Array module's buffer interface can now handle empty arrays.
Modified: python/branches/release25-maint/Lib/test/test_re.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_re.py	(original)
+++ python/branches/release25-maint/Lib/test/test_re.py	Tue Apr 3 00:39:08 2007
@@ -604,6 +604,13 @@
 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
Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Tue Apr 3 00:39:08 2007
@@ -134,6 +134,8 @@
 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.
Modified: python/branches/release25-maint/Modules/arraymodule.c
==============================================================================
--- python/branches/release25-maint/Modules/arraymodule.c	(original)
+++ python/branches/release25-maint/Modules/arraymodule.c	Tue Apr 3 00:39:08 2007
@@ -1745,6 +1745,8 @@
 	(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 @@
 		return -1;
 	}
 	*ptr = (void *)self->ob_item;
+	if (*ptr == NULL)
+		*ptr = emptybuf;
 	return self->ob_size*self->ob_descr->itemsize;
 }
 
@@ -1766,6 +1770,8 @@
 		return -1;
 	}
 	*ptr = (void *)self->ob_item;
+	if (*ptr == NULL)
+		*ptr = emptybuf;
 	return self->ob_size*self->ob_descr->itemsize;
 }
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /