[Numpy-discussion] numarray CVS seems to have an __array_struct__ bug
jmiller at stsci.edu
Thu Nov 17 04:15:03 EST 2005
Nice catch Andrew, and very timely!
Andrew Straw wrote:
>I think there's a bug in the new __array_struct__ code in numarray CVS.
>Consider an object a which implements the __array_struct__ interface. If
>one constructs a numarray "view" of this array using aview =
>numarray.asarray(a), the numarray.ndarray instance does not keep a
>reference to a.__array_struct__. Thus, a segfault may occur because
>a.data can be freed although aview may attempt to access it.
>In particular code like this will crash:
>buf = numarray.asarray( array_struct_factory() ) # buffer is freed
>buf = 2 # attempt is made to write to the non-existant buffer,
>causing a segfault
>I've "fixed" this issue with the following, which I'm sure is not the
>right way, but it's all I can do at this point.
>diff -u -r1.130 numarraycore.py
>--- Lib/numarraycore.py 4 Nov 2005 20:27:11 -0000 1.130
>+++ Lib/numarraycore.py 17 Nov 2005 11:38:29 -0000
>@@ -357,6 +357,7 @@
> a = None
> if hasattr(sequence, "__array_struct__"):
> a =
>+ a._hack_to_hold_reference_ = sequence.__array_struct__
> elif (hasattr(sequence, "__array_shape__") and
> hasattr(sequence, "__array_typestr__")):
> typestr = sequence.__array_typestr__
>And while I'm at it, can the "from distutils.command.config import log"
>be turned off in setup.py? I like to see those errors, warnings, and
>status strings whiz past...
>This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
>Register for a JBoss Training Course. Free Certification Exam
>for All Training Attendees Through End of 2005. For more info visit:
>Numpy-discussion mailing list
>Numpy-discussion at lists.sourceforge.net
More information about the NumPy-Discussion