[NumPy-Tickets] [NumPy] #1411: Array reshape bug

NumPy Trac numpy-tickets@scipy....
Fri Mar 19 12:18:11 CDT 2010


#1411: Array reshape bug
---------------------------------------------------+------------------------
 Reporter:  Han                                    |       Owner:  somebody    
     Type:  defect                                 |      Status:  needs_review
 Priority:  normal                                 |   Milestone:              
Component:  numpy.core                             |     Version:  1.3.0       
 Keywords:  reshape, overflow, unpropagated error  |  
---------------------------------------------------+------------------------
Changes (by Han):

  * status:  new => needs_review


Comment:

 Ok, I've traced the original problem to the function
 PyArray_IntpFromSequence in arrayobject.c:

 This function converts the sequence of given shape values  into a C-array
 of integers. It has a special case, though,  when the sequence value is no
 sequence but a single (integer) value. The problem is, it checks if the
 value is a Python integer, and then it converts the Python value to  its C
 equivalent, but it never checks if the conversion went well..

 {{{
 /*NUMPY_API
  * PyArray_IntpFromSequence
  * Returns the number of dimensions or -1 if an error occurred.
  * vals must be large enough to hold maxvals
  */
 static int
 PyArray_IntpFromSequence(PyObject *seq, intp *vals, int maxvals)
 [..]
     if ((nd=PySequence_Length(seq)) == -1) {
         if (PyErr_Occurred()) PyErr_Clear();
 #if SIZEOF_LONG >= SIZEOF_INTP
         if (!(op = PyNumber_Int(seq))) {
             return -1;
         }
 #else
         if (!(op = PyNumber_Long(seq))) {
             return -1;
         }
 #endif
         nd = 1;
 #if SIZEOF_LONG >= SIZEOF_INTP
         vals[0] = (intp ) PyInt_AsLong(op);   // Generates the
 OverflowError
 #else
         vals[0] = (intp ) PyLong_AsLongLong(op);
 #endif
         Py_DECREF(op);
     }
 [..]
 return nd
 }}}

 When adding

 {{{
         if(PyErr_Occurred()) {
             return -1;
         }
 }}}

 after
 {{{
         Py_DECREF(op);
 }}}
 it works as expected.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1411#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list