[pypy-svn] r46528 - in pypy/dist/pypy: rpython/memory/gctransform translator/c translator/c/test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Sep 13 01:23:15 CEST 2007


Author: cfbolz
Date: Thu Sep 13 01:23:15 2007
New Revision: 46528

Modified:
   pypy/dist/pypy/rpython/memory/gctransform/framework.py
   pypy/dist/pypy/translator/c/gc.py
   pypy/dist/pypy/translator/c/test/test_newgc.py
Log:
whack. support prebuilt weakrefs with mark-n-sweep too


Modified: pypy/dist/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform/framework.py	Thu Sep 13 01:23:15 2007
@@ -727,8 +727,8 @@
     # Prebuilt weakrefs don't really need to be weak at all,
     # but we need to emulate the structure expected by ll_weakref_deref().
     if not targetptr:
-        return empty_weaklink
+        return empty_weakref
     else:
-        link = lltype.malloc(WEAKPTR, immortal=True)
+        link = lltype.malloc(WEAKREF, immortal=True)
         link.weakptr = llmemory.cast_ptr_to_adr(targetptr)
         return link

Modified: pypy/dist/pypy/translator/c/gc.py
==============================================================================
--- pypy/dist/pypy/translator/c/gc.py	(original)
+++ pypy/dist/pypy/translator/c/gc.py	Thu Sep 13 01:23:15 2007
@@ -361,6 +361,13 @@
     def get_real_weakref_type(self):
         return framework.WEAKREF
 
+    def convert_weakref_to(self, ptarget):
+        result = framework.convert_weakref_to(ptarget)
+        # XXX whack
+        gct = self.db.gctransformer
+        gct.gcdata.gc.gcheaderbuilder.new_header(result)
+        return result
+
     def OP_GC_RELOAD_POSSIBLY_MOVED(self, funcgen, op):
         args = [funcgen.expr(v) for v in op.args]
         # XXX this more or less assumes mark-and-sweep gc

Modified: pypy/dist/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_newgc.py	Thu Sep 13 01:23:15 2007
@@ -601,6 +601,28 @@
         # more than half of them should have been freed, ideally up to 6000
         assert 3500 <= res <= 6000
 
+    def test_prebuilt_weakref(self):
+        import weakref
+        from pypy.rlib import rgc
+        class A:
+            pass
+        a = A()
+        a.hello = 42
+        refs = [weakref.ref(a), weakref.ref(A())]
+        rgc.collect()
+        def fn():
+            result = 0
+            for i in range(2):
+                a = refs[i]()
+                if a is None:
+                    result += i
+                else:
+                    result += a.hello * i
+            return result
+        c_fn = self.getcompiled(fn)
+        res = c_fn()
+        assert res == fn()
+
     def test_framework_malloc_raw(self):
         A = lltype.Struct('A', ('value', lltype.Signed))
 



More information about the Pypy-commit mailing list