summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2011-03-26 10:22:56 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2011-03-26 10:22:56 (GMT)
commit657bd0a25ddac6a951baaa9ac3167d8bce1b7308 (patch)
tree4659a374a59ce205ca58c36e2e8b4d03f491b7da
parentb9a1c5662b37839c9d3e2cbba5893582add09713 (diff)
parent633872e3fbfba101dcae0fb1d6938c91e10adafe (diff)
downloadcpython-657bd0a25ddac6a951baaa9ac3167d8bce1b7308.zip
cpython-657bd0a25ddac6a951baaa9ac3167d8bce1b7308.tar.gz
cpython-657bd0a25ddac6a951baaa9ac3167d8bce1b7308.tar.bz2
Merge #11675
-rw-r--r--Lib/multiprocessing/sharedctypes.py4
-rw-r--r--Lib/test/test_multiprocessing.py15
-rw-r--r--Misc/NEWS4
3 files changed, 22 insertions, 1 deletions
diff --git a/Lib/multiprocessing/sharedctypes.py b/Lib/multiprocessing/sharedctypes.py
index e83ce58..1e694da 100644
--- a/Lib/multiprocessing/sharedctypes.py
+++ b/Lib/multiprocessing/sharedctypes.py
@@ -80,7 +80,9 @@ def RawArray(typecode_or_type, size_or_initializer):
type_ = typecode_to_type.get(typecode_or_type, typecode_or_type)
if isinstance(size_or_initializer, int):
type_ = type_ * size_or_initializer
- return _new_value(type_)
+ obj = _new_value(type_)
+ ctypes.memset(ctypes.addressof(obj), 0, ctypes.sizeof(obj))
+ return obj
else:
type_ = type_ * len(size_or_initializer)
result = _new_value(type_)
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index 06449d2..0ddc71c 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -929,6 +929,21 @@ class _TestArray(BaseTestCase):
self.assertEqual(list(arr[:]), seq)
@unittest.skipIf(c_int is None, "requires _ctypes")
+ def test_array_from_size(self):
+ size = 10
+ # Test for zeroing (see issue #11675).
+ # The repetition below strengthens the test by increasing the chances
+ # of previously allocated non-zero memory being used for the new array
+ # on the 2nd and 3rd loops.
+ for _ in range(3):
+ arr = self.Array('i', size)
+ self.assertEqual(len(arr), size)
+ self.assertEqual(list(arr), [0] * size)
+ arr[:] = range(10)
+ self.assertEqual(list(arr), list(range(10)))
+ del arr
+
+ @unittest.skipIf(c_int is None, "requires _ctypes")
def test_rawarray(self):
self.test_array(raw=True)
diff --git a/Misc/NEWS b/Misc/NEWS
index 947777a..17b5d7e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
+- Issue #11675: multiprocessing.[Raw]Array objects created from an integer size
+ are now zeroed on creation. This matches the behaviour specified by the
+ documentation.
+
- Issue #10998: Remove mentions of -Q, sys.flags.division_warning and
Py_DivisionWarningFlag left over from Python 2.