summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2011-03-07 18:24:35 -0700
committerCharles Harris <charlesr.harris@gmail.com>2011-03-07 18:24:35 -0700
commit60adb1ac9fe688184973a02e8bce552d70d087f4 (patch)
tree065bf924c95d8c8992084fed6a4949b711c9a1fe
parent898e6bdc625cdd3c97865ef99f8d51c5f43eafff (diff)
downloadnumpy-60adb1ac9fe688184973a02e8bce552d70d087f4.tar.gz
BUG: Preliminary fix for ticket #1757.
-rw-r--r--numpy/core/src/multiarray/ctors.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 4fb6bc781..a98116afe 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -822,22 +822,38 @@ discover_dimensions(PyObject *s, int *maxndim, npy_intp *d, int check_it,
npy_intp dtmp[NPY_MAXDIMS];
int j, maxndim_m1 = *maxndim - 1;
- e = PySequence_GetItem(s, 0);
+ if ((e = PySequence_GetItem(s, 0)) == NULL) {
+ /* not a list */
+ *maxndim = 0;
+ PyErr_Clear();
+ return 0;
+ }
r = discover_dimensions(e, &maxndim_m1, d + 1, check_it,
stop_at_string, stop_at_tuple,
out_is_object);
Py_DECREF(e);
+ if (r < 0) {
+ return r;
+ }
/* For the dimension truncation check below */
*maxndim = maxndim_m1 + 1;
for (i = 1; i < n; ++i) {
/* Get the dimensions of the first item */
- e = PySequence_GetItem(s, i);
+ if ((e = PySequence_GetItem(s, 0)) == NULL) {
+ /* not a list */
+ *maxndim = 0;
+ PyErr_Clear();
+ return 0;
+ }
r = discover_dimensions(e, &maxndim_m1, dtmp, check_it,
stop_at_string, stop_at_tuple,
out_is_object);
Py_DECREF(e);
+ if (r < 0) {
+ return r;
+ }
/* Reduce max_ndim_m1 to just items which match */
for (j = 0; j < maxndim_m1; ++j) {