Commits

mattip committed 49b1145 Merge

merge numpypy-segfault fixing segfault while iterating over empty ndarrays

  • Participants
  • Parent commits 2ee41b8, a038818

Comments (0)

Files changed (4)

pypy/doc/whatsnew-head.rst

 .. branch: ndarray-view
 Add view to ndarray and zeroD arrays, not on dtype scalars yet
 
+.. branch: numpypy-segfault
+fix segfault caused by iterating over empty ndarrays
+
 .. branch: identity-set
 Faster sets for objects
 

pypy/module/micronumpy/interp_arrayops.py

            [ 3.,  4., -1.],
            [-1., -1., -1.]])
 
-    
+
     NOTE: support for not passing x and y is unsupported
     """
     if space.is_none(w_y):
             for f in dtype.fields:
                 if f not in a_dt.fields or \
                              dtype.fields[f] != a_dt.fields[f]:
-                    raise OperationError(space.w_TypeError, 
+                    raise OperationError(space.w_TypeError,
                                space.wrap("record type mismatch"))
         elif dtype.is_record_type() or a_dt.is_record_type():
-            raise OperationError(space.w_TypeError, 
+            raise OperationError(space.w_TypeError,
                         space.wrap("invalid type promotion"))
         dtype = interp_ufuncs.find_binop_result_dtype(space, dtype,
                                                       arr.get_dtype())

pypy/module/micronumpy/iter.py

      calculate_slice_strides
 from pypy.module.micronumpy.base import W_NDimArray
 from pypy.module.micronumpy.arrayimpl import base
+from pypy.module.micronumpy.support import product
 from rpython.rlib import jit
 
 # structures to describe slicing
         self.shape = shape
         self.offset = start
         self.shapelen = len(shape)
-        self._done = False
+        self._done = self.shapelen == 0 or product(shape) == 0
         self.strides = strides
         self.backstrides = backstrides
         self.size = array.size
             self.backstrides = backstrides[:dim] + [0] + backstrides[dim:]
         self.first_line = True
         self.indices = [0] * len(shape)
-        self._done = False
+        self._done = array.get_size() == 0
         self.offset = array.start
         self.dim = dim
         self.array = array

pypy/module/micronumpy/test/test_numarray.py

         b = array(a, copy=False, ndmin=4)
         b[0,0,0,0] = 0
         assert a[0, 0] == 0
+        a = array([[[]]])
+        # Simulate tiling an empty array, really tests repeat, reshape
+        # b = tile(a, (3, 2, 5))
+        reps = (3, 4, 5)
+        c = array(a, copy=False, subok=True, ndmin=len(reps))
+        d = c.reshape(3, 4, 0)
+        e = d.repeat(3, 0)
+        assert e.shape == (9, 4, 0)
 
     def test_type(self):
         from numpypy import array
         a = array(range(100) + range(100) + range(100))
         b = a.argsort()
         assert (b[:3] == [0, 100, 200]).all()
+        a = array([[[]]]).reshape(3,4,0)
+        b = a.argsort()
+        assert b.size == 0
 
     def test_argsort_random(self):
         from numpypy import array