[pypy-commit] pypy stmgc-c4: Add a direct translation test for weakrefs

arigo noreply at buildbot.pypy.org
Sat Jul 27 17:03:41 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c4
Changeset: r65716:98a8c851a299
Date: 2013-07-27 17:03 +0200
http://bitbucket.org/pypy/pypy/changeset/98a8c851a299/

Log:	Add a direct translation test for weakrefs

diff --git a/rpython/memory/gc/stmgc.py b/rpython/memory/gc/stmgc.py
--- a/rpython/memory/gc/stmgc.py
+++ b/rpython/memory/gc/stmgc.py
@@ -110,7 +110,7 @@
         # XXX finalizers are ignored for now
         #ll_assert(not needs_finalizer, 'XXX needs_finalizer')
         #ll_assert(not is_finalizer_light, 'XXX is_finalizer_light')
-        #ll_assert(not contains_weakptr, 'XXX contains_weakptr')
+        ll_assert(not contains_weakptr, 'contains_weakptr: use malloc_weakref')
         # XXX call optimized versions, e.g. if size < GC_NURSERY_SECTION
         return llop.stm_allocate(llmemory.GCREF, size, typeid16)
 
diff --git a/rpython/translator/stm/test/test_ztranslated.py b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -1,5 +1,5 @@
 import py
-from rpython.rlib import rstm, rgc
+from rpython.rlib import rstm, rgc, objectmodel
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, rclass
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rtyper.annlowlevel import cast_instance_to_base_ptr
@@ -276,3 +276,30 @@
         t, cbuilder = self.compile(main)
         data = cbuilder.cmdexec('a b')
         assert 'li102ee10:hi there 3e\n0\n' in data
+
+    def test_weakref(self):
+        import weakref
+        class Foo(object):
+            pass
+
+        def f(argv):
+            foo = Foo()
+            foo.n = argv
+            w = weakref.ref(foo)
+            assert w() is foo
+            objectmodel.keepalive_until_here(foo)
+            return w
+        f._dont_inline_ = True
+
+        def main(argv):
+            w = f(argv)
+            assert w() is not None
+            assert len(w().n) == len(argv)
+            rgc.collect()
+            assert w() is None
+            print 'test ok'
+            return 0
+
+        t, cbuilder = self.compile(main)
+        data = cbuilder.cmdexec('a b')
+        assert 'test ok\n' in data


More information about the pypy-commit mailing list