Author: Matti Picus <[email protected]>
Branch:
Changeset: r65163:49b114578eb7
Date: 2013-07-02 07:54 +0300
http://bitbucket.org/pypy/pypy/changeset/49b114578eb7/
Log: merge numpypy-segfault fixing segfault while iterating over empty
ndarrays
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -65,6 +65,9 @@
.. 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
diff --git a/pypy/module/micronumpy/interp_arrayops.py
b/pypy/module/micronumpy/interp_arrayops.py
--- a/pypy/module/micronumpy/interp_arrayops.py
+++ b/pypy/module/micronumpy/interp_arrayops.py
@@ -65,7 +65,7 @@
[ 3., 4., -1.],
[-1., -1., -1.]])
-
+
NOTE: support for not passing x and y is unsupported
"""
if space.is_none(w_y):
@@ -122,10 +122,10 @@
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())
diff --git a/pypy/module/micronumpy/iter.py b/pypy/module/micronumpy/iter.py
--- a/pypy/module/micronumpy/iter.py
+++ b/pypy/module/micronumpy/iter.py
@@ -46,6 +46,7 @@
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
@@ -225,7 +226,7 @@
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
@@ -284,7 +285,7 @@
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
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
@@ -293,6 +293,14 @@
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
@@ -2562,6 +2570,9 @@
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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit