[pypy-svn] r45672 - pypy/dist/pypy/translator/c/test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Aug 15 12:55:09 CEST 2007


Author: cfbolz
Date: Wed Aug 15 12:55:09 2007
New Revision: 45672

Modified:
   pypy/dist/pypy/translator/c/test/test_boehm.py
Log:
Test that I expected to fail with boehm about id(obj) not keeping obj alive.


Modified: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py	Wed Aug 15 12:55:09 2007
@@ -95,6 +95,49 @@
         # it might be the test's fault though.
         assert 0 < res <= 84
 
+    def test_id_is_weak(self):
+        # test that id(obj) does not keep obj alive
+        from pypy.rpython.lltypesystem.lloperation import llop
+        class State:
+            pass
+        s = State()
+        class A(object):
+            def __del__(self):
+                s.a_dels += 1
+        class B(A):
+            def __del__(self):
+                s.b_dels += 1
+        class C(A):
+            pass
+        def f():
+            s.a_dels = 0
+            s.b_dels = 0
+            a = A()
+            ida = id(a)
+            b = B()
+            idb = id(b)
+            c = C()
+            idc = id(c)
+            llop.gc__collect(lltype.Void)
+            llop.gc__collect(lltype.Void)
+            llop.gc__collect(lltype.Void)
+            
+            # the strange additions at the end are to keep ida, idb alive
+            return s.a_dels * 10 + s.b_dels + ida + idb - idb - ida
+        fn = self.getcompiled(f)
+        # we can't demand that boehm has collected all of the objects,
+        # even with the gc__collect call.  calling the compiled
+        # function twice seems to help, though.
+        res = 0
+        res += fn()
+        res += fn()
+        # if res is still 0, then we haven't tested anything so fail.
+        # it might be the test's fault though.
+        assert 0 < res <= 44
+        print res
+
+
+
     def test_weakgcaddress_is_weak(self):
         py.test.skip("weakgcaddress as we know it is fragile")
         from pypy.rpython.lltypesystem.lloperation import llop



More information about the Pypy-commit mailing list