Author: mattip <[email protected]>
Branch:
Changeset: r78634:b0a67e1d9a20
Date: 2015-07-21 17:11 -0400
http://bitbucket.org/pypy/pypy/changeset/b0a67e1d9a20/
Log: test, fix issue #2090
diff --git a/pypy/module/micronumpy/concrete.py
b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -400,11 +400,17 @@
class ConcreteArrayNotOwning(BaseConcreteArray):
def __init__(self, shape, dtype, order, strides, backstrides, storage,
start=0):
+ if len(shape) > NPY.MAXDIMS:
+ raise oefmt(dtype.itemtype.space.w_ValueError,
+ "sequence too large; must be smaller than %d", NPY.MAXDIMS)
make_sure_not_resized(shape)
make_sure_not_resized(strides)
make_sure_not_resized(backstrides)
self.shape = shape
- self.size = support.product(shape) * dtype.elsize
+ try:
+ self.size = support.product(shape) * dtype.elsize
+ except OverflowError as e:
+ raise oefmt(dtype.itemtype.space.w_ValueError, "array is too big")
self.order = order
self.dtype = dtype
self.strides = strides
@@ -445,8 +451,14 @@
storage=lltype.nullptr(RAW_STORAGE), zero=True):
gcstruct = V_OBJECTSTORE
flags = NPY.ARRAY_ALIGNED | NPY.ARRAY_WRITEABLE
+ if len(shape) > NPY.MAXDIMS:
+ raise oefmt(dtype.itemtype.space.w_ValueError,
+ "sequence too large; must be smaller than %d", NPY.MAXDIMS)
if storage == lltype.nullptr(RAW_STORAGE):
- length = support.product(shape)
+ try:
+ length = support.product(shape)
+ except OverflowError as e:
+ raise oefmt(dtype.itemtype.space.w_ValueError, "array is too
big")
if dtype.num == NPY.OBJECT:
storage = dtype.itemtype.malloc(length * dtype.elsize,
zero=True)
gcstruct = _create_objectstore(storage, length, dtype.elsize)
diff --git a/pypy/module/micronumpy/test/test_ndarray.py
b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -267,6 +267,11 @@
y = array(x.T, copy=False)
assert (y == x.T).all()
+ exc = raises(ValueError, ndarray, [1,2,256]*10000)
+ assert exc.value[0] == 'sequence too large; must be smaller than 32'
+ exc = raises(ValueError, ndarray, [1,2,256]*10)
+ assert exc.value[0] == 'array is too big'
+
def test_ndmin(self):
from numpy import array
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit