Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r60182:85218b7bd814
Date: 2013-01-18 17:10 +0000
http://bitbucket.org/pypy/pypy/changeset/85218b7bd814/
Log: numpy arrays should be weakreferenceable
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -1,6 +1,6 @@
from pypy.interpreter.error import operationerrfmt, OperationError
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.typedef import TypeDef, GetSetProperty,
make_weakref_descr
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
from pypy.module.micronumpy.base import W_NDimArray, convert_to_array,\
ArrayArgumentException, issequence_w
@@ -684,8 +684,9 @@
imag = GetSetProperty(W_NDimArray.descr_get_imag,
W_NDimArray.descr_set_imag),
__array_interface__ = GetSetProperty(W_NDimArray.descr_array_iface),
- _from_shape_and_storage = interp2app(descr__from_shape_and_storage,
- as_classmethod=True),
+ __weakref__ = make_weakref_descr(W_NDimArray),
+ _from_shape_and_storage = interp2app(descr__from_shape_and_storage,
+ as_classmethod=True),
__pypy_data__ = GetSetProperty(W_NDimArray.fget___pypy_data__,
W_NDimArray.fset___pypy_data__,
W_NDimArray.fdel___pypy_data__),
diff --git a/pypy/module/micronumpy/test/test_numarray.py
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1615,6 +1615,14 @@
assert (b == [20, 1, 21, 3, 4]).all()
raises(ValueError, "array([1, 2])[array([True, False, True])] = [1, 2,
3]")
+ def test_weakref(self):
+ import _weakref
+ from numpypy import array
+ a = array([1, 2, 3])
+ assert _weakref.ref(a)
+ a = array(42)
+ assert _weakref.ref(a)
+
class AppTestMultiDim(BaseNumpyAppTest):
def test_init(self):
import _numpypy
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit