[pypy-svn] r46680 - in pypy/dist/pypy/translator/c: src test

arigo at codespeak.net arigo at codespeak.net
Sun Sep 16 19:14:58 CEST 2007


Author: arigo
Date: Sun Sep 16 19:14:57 2007
New Revision: 46680

Modified:
   pypy/dist/pypy/translator/c/src/mem.h
   pypy/dist/pypy/translator/c/test/test_boehm.py
Log:
Run-time weakrefs to prebuilt objects...  crash Boehm in ways
that cost an afternoon of debugging :-(


Modified: pypy/dist/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/mem.h	(original)
+++ pypy/dist/pypy/translator/c/src/mem.h	Sun Sep 16 19:14:57 2007
@@ -100,7 +100,12 @@
 */
 #define OP_CALL_BOEHM_GC_ALLOC(size, r) OP_BOEHM_ZERO_MALLOC(size, r, void *, 0, 0)
 
-#define OP_BOEHM_DISAPPEARING_LINK(link, obj, r) \
+#define OP_BOEHM_DISAPPEARING_LINK(link, obj, r)			   \
+	if (GC_base(obj) == NULL)					   \
+		; /* 'obj' is probably a prebuilt object - it makes no */  \
+		  /* sense to register it then, and it crashes Boehm in */ \
+		  /* quite obscure ways */				   \
+	else								   \
 		GC_GENERAL_REGISTER_DISAPPEARING_LINK(link, obj)
 
 #endif /* USING_BOEHM_GC */

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	Sun Sep 16 19:14:57 2007
@@ -315,6 +315,21 @@
         res = c_fn(0)
         assert res == -5
 
+    def test_weakref_to_prebuilt(self):
+        import weakref
+        from pypy.rlib import rgc
+        class A:
+            pass
+        a = A()
+        a.hello = 42
+        def fn(n):
+            lst = [weakref.ref(a) for i in range(n)]
+            rgc.collect()
+            for r in lst:
+                assert r() is a
+        c_fn = self.getcompiled(fn, [int])
+        c_fn(100)
+
 
 class TestUsingExactBoehm(TestUsingBoehm):
     gcpolicy = "exact_boehm"



More information about the Pypy-commit mailing list