[pypy-svn] r26772 - in pypy/dist/pypy: interpreter module/_weakref/test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri May 5 01:12:23 CEST 2006


Author: cfbolz
Date: Fri May  5 01:12:17 2006
New Revision: 26772

Modified:
   pypy/dist/pypy/interpreter/typedef.py
   pypy/dist/pypy/module/_weakref/test/test_weakref.py
Log:
make sure that interplevel __del__ is called even in the presence of an
applevel __del__. This prevents a (virtual, but should also work on pypy-c)
segfault in py.py.


Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Fri May  5 01:12:17 2006
@@ -77,6 +77,8 @@
                 except OperationError, e:
                     e.write_unraisable(self.space, 'method __del__ of ', self)
                     e.clear(self.space)   # break up reference cycles
+                if hasattr(cls, '__del__'):
+                    cls.__del__(self)
     elif wants_slots:
         supercls = get_unique_interplevel_subclass(cls, hasdict, False, False)
         

Modified: pypy/dist/pypy/module/_weakref/test/test_weakref.py
==============================================================================
--- pypy/dist/pypy/module/_weakref/test/test_weakref.py	(original)
+++ pypy/dist/pypy/module/_weakref/test/test_weakref.py	Fri May  5 01:12:17 2006
@@ -144,6 +144,24 @@
         w = _weakref.ref(A())
         raises(TypeError, hash, w)
 
+    def test_weakref_subclass_with_del(self):
+        import _weakref
+        class Ref(_weakref.ref):
+            def __del__(self):
+                b.a = 42
+        class A(object):
+            pass
+        a = A()
+        b = A()
+        b.a = 1
+        w = Ref(a)
+        del w
+        assert b.a == 42
+        if _weakref.getweakrefcount(a) > 0:
+            # the following can crash if the presence of the applevel __del__
+            # leads to the fact that the __del__ of _weakref.ref is not called.
+            assert _weakref.getweakrefs(a)[0]() is a
+
 class AppTestProxy(object):
     def setup_class(cls):
         space = gettestobjspace(usemodules=('_weakref',))



More information about the Pypy-commit mailing list