[Numpy-discussion] numarray CVS seems to have an __array_struct__ bug
Andrew Straw
strawman at astraw.com
Thu Nov 17 03:42:06 EST 2005
Hi,
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[1] = 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 =
_numarray._array_from_array_struct(sequence.__array_struct__)
+ 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...
More information about the NumPy-Discussion
mailing list