summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2009-11-27 09:46:18 +0000
committerDavid Cournapeau <cournape@gmail.com>2009-11-27 09:46:18 +0000
commit2d4edf255ae85bded0844186314c42e8a35185d2 (patch)
tree02b99ec313974e554ca7a15472483f49fe0668a7
parent131ac69ad30c3dbc8ca210c5dd954c62b4e7e4d6 (diff)
downloadnumpy-2d4edf255ae85bded0844186314c42e8a35185d2.tar.gz
BUG: (#1078): fix segfault when creating arrays with a sequence which contains 0d array.
-rw-r--r--numpy/core/src/multiarray/ctors.c13
-rw-r--r--numpy/core/tests/test_regression.py10
2 files changed, 21 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index d58b0576e..a2eb4494b 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1182,8 +1182,17 @@ discover_dimensions(PyObject *s, int nd, intp *d, int check_it)
if (PyArray_Check(s)) {
- for (i=0; i<nd; i++) {
- d[i] = PyArray_DIM(s,i);
+ /*
+ * XXXX: we handle the case of scalar arrays (0 dimensions) separately.
+ * This is an hack, the function discover_dimensions needs to be
+ * improved.
+ */
+ if (PyArray_NDIM(s) == 0) {
+ d[0] = 0;
+ } else {
+ for (i=0; i<nd; i++) {
+ d[i] = PyArray_DIM(s,i);
+ }
}
return 0;
}
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 7fff66b15..83d014485 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1101,6 +1101,16 @@ class TestRegression(TestCase):
assert np.alltrue(a == np.array([0,1,2,3,4,5,6,7,8,9]))
assert np.alltrue(b == np.array([0,1,2,3,4,5,6,7,8,9]))
+ def test_array_from_sequence_scalar_array(self):
+ """Ticket #1078: segfaults when creating an array with a sequence of 0d
+ arrays."""
+ a = np.ones(2)
+ b = np.array(3)
+ assert_raises(ValueError, lambda: np.array((a, b)))
+
+ t = ((1,), np.array(1))
+ assert_raises(ValueError, lambda: np.array(t))
+
def test_array_too_big(self):
"""Ticket #1080."""
assert_raises(ValueError, np.zeros, [2**10]*10)