[pypy-commit] pypy default: fix segfault on np.fromstring of record type

bdkearns noreply at buildbot.pypy.org
Sun Feb 23 20:02:33 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r69288:cd632d18a772
Date: 2014-02-23 13:50 -0500
http://bitbucket.org/pypy/pypy/changeset/cd632d18a772/

Log:	fix segfault on np.fromstring of record type

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
@@ -3058,6 +3058,7 @@
         v = fromstring("abcd", dtype="|S2")
         assert v[0] == "ab"
         assert v[1] == "cd"
+
         v = fromstring('@\x01\x99\x99\x99\x99\x99\x9a\xbf\xf1\x99\x99\x99\x99\x99\x9a',
                        dtype=dtype('>c16'))
         assert v.tostring() == \
@@ -3073,6 +3074,18 @@
         assert v.real == 2.2
         assert v.imag == -1.1
 
+        d = [('f0', 'i4'), ('f1', 'u2', (2, 3))]
+        if '__pypy__' not in sys.builtin_module_names:
+            r = fromstring('abcdefghijklmnop'*4*3, dtype=d)
+            assert (r[0:3:2]['f1'] == r['f1'][0:3:2]).all()
+            assert (r[0:3:2]['f1'][0] == r[0:3:2][0]['f1']).all()
+            assert (r[0:3:2]['f1'][0][()] == r[0:3:2][0]['f1'][()]).all()
+            assert r[0:3:2]['f1'][0].strides == r[0:3:2][0]['f1'].strides
+        else:
+            exc = raises(NotImplementedError, fromstring,
+                         'abcdefghijklmnop'*4*3, dtype=d)
+            assert exc.value[0] == "fromstring not implemented for record types"
+
     def test_fromstring_types(self):
         from numpypy import fromstring, array, dtype
         a = fromstring('\xFF', dtype='int8')
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
@@ -1,7 +1,7 @@
 import functools
 import math
 
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.module.micronumpy import interp_boxes
 from pypy.module.micronumpy import support
 from pypy.module.micronumpy.arrayimpl.voidbox import VoidBoxStorage
@@ -1897,6 +1897,10 @@
             itemtype.store(arr, 0, ofs, w_box)
         return interp_boxes.W_VoidBox(arr, 0, dtype)
 
+    def runpack_str(self, space, s):
+        raise oefmt(space.w_NotImplementedError,
+                    "fromstring not implemented for record types")
+
     def store(self, arr, i, ofs, box):
         assert isinstance(box, interp_boxes.W_VoidBox)
         self._store(arr.storage, i, ofs, box, box.dtype.get_size())


More information about the pypy-commit mailing list