[pypy-commit] pypy gc-incminimark-pinning: don't allow objects with weakrefs to be pinned

groggi noreply at buildbot.pypy.org
Tue Sep 2 11:43:37 CEST 2014


Author: Gregor Wegberg <code at gregorwegberg.com>
Branch: gc-incminimark-pinning
Changeset: r73280:109d47eb6e54
Date: 2014-09-02 11:38 +0200
http://bitbucket.org/pypy/pypy/changeset/109d47eb6e54/

Log:	don't allow objects with weakrefs to be pinned

diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -970,16 +970,21 @@
             # makes no sense. If you run into this case, you may forgot
             # to check can_move(obj).
             return False
-        if self.has_gcptr(self.get_type_id(obj)):
+        if self._is_pinned(obj):
+            # already pinned, we do not allow to pin it again.
+            # Reason: It would be possible that the first caller unpins
+            # while the second caller thinks it's still pinned.
+            return False
+        #
+        obj_type_id = self.get_type_id(obj)
+        if self.has_gcptr(obj_type_id):
             # objects containing GC pointers can't be pinned. If we would add
             # it, we would have to track all pinned objects and trace them
             # every minor collection to make sure the referenced object are
             # kept alive. Right now this is not a use case that's needed.
             return False
-        if self._is_pinned(obj):
-            # already pinned, we do not allow to pin it again.
-            # Reason: It would be possible that the first caller unpins
-            # while the second caller thinks it's still pinned.
+        if self.weakpointer_offset(obj_type_id) >= 0:
+            # for now we don't support pinning objects with weak pointers.
             return False
         #
         self.header(obj).tid |= GCFLAG_PINNED
diff --git a/rpython/memory/test/test_incminimark_gc.py b/rpython/memory/test/test_incminimark_gc.py
--- a/rpython/memory/test/test_incminimark_gc.py
+++ b/rpython/memory/test/test_incminimark_gc.py
@@ -1,5 +1,6 @@
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rlib import rgc
 
 from rpython.memory.test import test_minimark_gc
 
@@ -37,6 +38,16 @@
         res = self.interpret(f, [])
         assert res == True
 
+    def test_pin_weakref_not_implemented(self):
+        import weakref
+        class A:
+            pass
+        def f():
+            a = A()
+            ref = weakref.ref(a)
+            assert not rgc.pin(ref)
+        self.interpret(f, [])
+
     def test_weakref_to_pinned(self):
         import weakref
         from rpython.rlib import rgc


More information about the pypy-commit mailing list