summaryrefslogtreecommitdiff
path: root/numpy/core/src/arrayobject.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2008-02-26 21:17:13 +0000
committerTravis Oliphant <oliphant@enthought.com>2008-02-26 21:17:13 +0000
commitfb61bf2421093cc034c7d0985c77648188a8b209 (patch)
treed119b19f26d9f0684aba0e910f1bc35095303ee9 /numpy/core/src/arrayobject.c
parentfa547b80f7035da85f66f9cbabc4ff75969d23cd (diff)
downloadnumpy-fb61bf2421093cc034c7d0985c77648188a8b209.tar.gz
Make sure that mp is an array before testing for 0-d ness.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r--numpy/core/src/arrayobject.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 75c1b6e29..5b657ce63 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -3032,6 +3032,11 @@ array_subscript_nice(PyArrayObject *self, PyObject *op)
mp = (PyArrayObject *)array_subscript(self, op);
+ /* mp could be a scalar if op is not an Int, Scalar, Long or other Index
+ object and still convertable to an integer (so that the code goes to
+ array_subscript_simple). So, this cast is a bit dangerous..
+ */
+
/* The following is just a copy of PyArray_Return with an
additional logic in the nd == 0 case.
*/
@@ -3043,14 +3048,15 @@ array_subscript_nice(PyArrayObject *self, PyObject *op)
return NULL;
}
- if (mp->nd == 0) {
+ if (PyArray_Check(mp) && mp->nd == 0) {
Bool noellipses = TRUE;
if ((op == Py_Ellipsis) || PyString_Check(op) || PyUnicode_Check(op))
noellipses = FALSE;
else if (PyBool_Check(op) || PyArray_IsScalar(op, Bool) ||
(PyArray_Check(op) && (PyArray_DIMS(op)==0) &&
- PyArray_ISBOOL(op)))
- noellipses = FALSE;
+ PyArray_ISBOOL(op))) {
+ noellipses = FALSE;
+ }
else if (PySequence_Check(op)) {
int n, i;
PyObject *temp;