Commits

Antonio Cuni committed 85218b7

numpy arrays should be weakreferenceable

Comments (0)

Files changed (2)

pypy/module/micronumpy/interp_numarray.py

 
 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
     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__),

pypy/module/micronumpy/test/test_numarray.py

         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