[MATRIX-SIG] Bug report - seg-fault

Timothy A. Hochberg Timothy A. Hochberg" <hochberg@wwa.com
Mon, 11 Aug 1997 12:44:01 -0500 (CDT)


I think I've found a fix for the problem, although I admit to not fully
understanding it. Here's what I've figured out:

a) It never happens for sizes < 4 (e.g., zeros((0,3)) * zeros((0,3)) 
   always works). This probably varies from machine to machine.

b) For larger sizes, it doesn't always fail. I'd be interested in hearing
   from those of you for whom it didn't crash before as to whether it
   crashes if you repeat zeros((0,1000)) * zeros((0,1000)) several times. 

c) The problem arises because some of the stride lengths in a zero size
   array will be longer than the memory allocated for the array (which
   turns out to be one int). Where exactly this causes a problem I'm not
   sure, but it's not suprising.

d) There seem to be two ways to fix this: 1) allocate extra memory - this
   is wasteful, but safe; and it's what I did in the patch I included
   below. 2) Make all the strides have zero length for these zeros size
   arrays. This wastes no space but might have consequences that are too
   horrible to imagine.

Anyway, included below is a patch that fixes the problem by allocating
product(max(1,dimension[i]) space for the array rather than
product(dimension[i]) space.

 ____   
  /im  

+------------------------------------------------+
|Tim Hochberg            Research Assistant      |
|hochberg <at> wwa.com   University of Illinois  |
|                        Electrical Engineering  |
+------------------------------------------------+

*** arrayobject.c       Wed Aug  6 09:45:50 1997
--- arrayobject.c.old   Wed Aug  6 09:46:45 1997
***************
*** 313,324 ****
                        PyErr_SetString(PyExc_ValueError, "negative
dimensions are not allowed");
                        goto fail;
                }
!               /* 
!                  This may waste some space, but it seems to be
!                  (unsuprisingly) unhealthy to allow strides that are
!                  longer than sd.
!               */
!               sd *= dimensions[i] ? dimensions[i] : 1;
        }
  
        /* Make sure we're alligned on ints. */
--- 313,319 ----
                        PyErr_SetString(PyExc_ValueError, "negative
dimensions are not allowed");
                        goto fail;
                }
!               sd *= dimensions[i];
        }
  
        /* Make sure we're alligned on ints. */




_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________