diff options
author | David Cournapeau <cournape@gmail.com> | 2009-03-23 06:44:47 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-03-23 06:44:47 +0000 |
commit | 8640579ac3ba988ac41ba48b38a9a8565b4220ae (patch) | |
tree | 4164684f67b46b042bc2e2b72187637c53317993 /numpy/core/src/arrayobject.c | |
parent | 527eebd9ed4a9fd778bc7418bb968dfd00f3c270 (diff) | |
download | numpy-8640579ac3ba988ac41ba48b38a9a8565b4220ae.tar.gz |
BUG: Fix #1061.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index ff04485d6..bc99e1f30 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -5364,7 +5364,7 @@ static int PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals) { int nd, i; - PyObject *op; + PyObject *op, *err; /* * Check to see if sequence is a single integer first. @@ -5388,6 +5388,22 @@ PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals) vals[0] = (intp ) PyLong_AsLongLong(op); #endif Py_DECREF(op); + + /* + * Check wether there was an error - if the error was an overflow, raise + * a ValueError instead to be more helpful + */ + if(vals[0] == -1) { + err = PyErr_Occurred(); + if (err && + PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) { + PyErr_SetString(PyExc_ValueError, + "Maximum allowed dimension exceeded"); + } + if(err != NULL) { + return -1; + } + } } else { for (i = 0; i < MIN(nd,maxvals); i++) { @@ -5401,8 +5417,21 @@ PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals) vals[i]=(intp )PyLong_AsLongLong(op); #endif Py_DECREF(op); - if(PyErr_Occurred()) { - return -1; + + /* + * Check wether there was an error - if the error was an overflow, + * raise a ValueError instead to be more helpful + */ + if(vals[0] == -1) { + err = PyErr_Occurred(); + if (err && + PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) { + PyErr_SetString(PyExc_ValueError, + "Maximum allowed dimension exceeded"); + } + if(err != NULL) { + return -1; + } } } } |