Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r69239:4e601676010a
Date: 2014-02-21 12:40 -0500
http://bitbucket.org/pypy/pypy/changeset/4e601676010a/

Log:    fix segfault of fill called on record types

diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -2672,7 +2672,7 @@
         assert arange(3)[array(1)] == 1
 
     def test_fill(self):
-        from numpypy import array
+        from numpypy import array, empty
         a = array([1, 2, 3])
         a.fill(10)
         assert (a == [10, 10, 10]).all()
@@ -2695,6 +2695,20 @@
         e.fill(1.5-3j)
         assert e == 1.5-3j
 
+        a = empty(5, dtype='S3')
+        a.fill('abc')
+        for i in a:
+            assert i == 'abc'
+
+        a = empty(10, dtype=[(_, int) for _ in 'abcde'])
+        a.fill(123)
+        for i in a:
+            import sys
+            if '__pypy__' in sys.builtin_module_names:
+                assert tuple(i) == (123,) + (0,) * 4
+            else:
+                assert tuple(i) == (123,) * 5
+
     def test_array_indexing_bool(self):
         from numpypy import arange
         a = arange(10)
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1897,11 +1897,20 @@
             itemtype.store(arr, 0, ofs, w_box)
         return interp_boxes.W_VoidBox(arr, 0, dtype)
 
-    @jit.unroll_safe
     def store(self, arr, i, ofs, box):
         assert isinstance(box, interp_boxes.W_VoidBox)
-        for k in range(box.dtype.get_size()):
-            arr.storage[k + i + ofs] = box.arr.storage[k + box.ofs]
+        self._store(arr.storage, i, ofs, box, box.dtype.get_size())
+
+    @jit.unroll_safe
+    def _store(self, storage, i, ofs, box, size):
+        for k in range(size):
+            storage[k + i + ofs] = box.arr.storage[k + box.ofs]
+
+    def fill(self, storage, width, box, start, stop, offset):
+        assert isinstance(box, interp_boxes.W_VoidBox)
+        assert width == box.dtype.get_size()
+        for i in xrange(start, stop, width):
+            self._store(storage, i, offset, box, width)
 
     def byteswap(self, w_v):
         # XXX implement
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to