[pypy-svn] r79237 - in pypy/trunk/pypy/rpython/memory: gc test

arigo at codespeak.net arigo at codespeak.net
Thu Nov 18 13:33:37 CET 2010


Author: arigo
Date: Thu Nov 18 13:33:35 2010
New Revision: 79237

Modified:
   pypy/trunk/pypy/rpython/memory/gc/minimark.py
   pypy/trunk/pypy/rpython/memory/gc/semispace.py
   pypy/trunk/pypy/rpython/memory/test/test_gc.py
Log:
Revert r79182.  It's not as easy, it even looks like a mess.

What we can (for now) guarantee is that with this kind of relation:
    
    a --------> weakref object - - - -> b --------> c

if c has a finalizer, then when the finalizer of c runs, we are sure
that b is gone, so the weakref points to None.



Modified: pypy/trunk/pypy/rpython/memory/gc/minimark.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/gc/minimark.py	(original)
+++ pypy/trunk/pypy/rpython/memory/gc/minimark.py	Thu Nov 18 13:33:35 2010
@@ -1205,10 +1205,6 @@
         self.collect_roots()
         self.visit_all_objects()
         #
-        # Weakref support: clear the weak pointers to dying objects
-        if self.old_objects_with_weakrefs.non_empty():
-            self.invalidate_old_weakrefs()
-        #
         # Finalizer support: adds the flag GCFLAG_VISITED to all objects
         # with a finalizer and all objects reachable from there (and also
         # moves some objects from 'objects_with_finalizers' to
@@ -1218,6 +1214,10 @@
         #
         self.objects_to_trace.delete()
         #
+        # Weakref support: clear the weak pointers to dying objects
+        if self.old_objects_with_weakrefs.non_empty():
+            self.invalidate_old_weakrefs()
+        #
         # Walk all rawmalloced objects and free the ones that don't
         # have the GCFLAG_VISITED flag.
         self.free_unvisited_rawmalloc_objects()

Modified: pypy/trunk/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/gc/semispace.py	(original)
+++ pypy/trunk/pypy/rpython/memory/gc/semispace.py	Thu Nov 18 13:33:35 2010
@@ -266,10 +266,10 @@
         if self.run_finalizers.non_empty():
             self.update_run_finalizers()
         scan = self.scan_copied(scan)
-        if self.objects_with_weakrefs.non_empty():
-            self.invalidate_weakrefs()
         if self.objects_with_finalizers.non_empty():
             scan = self.deal_with_objects_with_finalizers(scan)
+        if self.objects_with_weakrefs.non_empty():
+            self.invalidate_weakrefs()
         self.update_objects_with_id()
         self.finished_full_collect()
         self.debug_check_consistency()

Modified: pypy/trunk/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/trunk/pypy/rpython/memory/test/test_gc.py	Thu Nov 18 13:33:35 2010
@@ -304,7 +304,7 @@
         a = A()
         class B(object):
             def __del__(self):
-                # when __del__ is called, the weakref should have been cleared
+                # when __del__ is called, the weakref to c should be dead
                 if self.ref() is None:
                     a.count += 10  # ok
                 else:
@@ -333,8 +333,10 @@
         a = A()
         class B(object):
             def __del__(self):
-                # when __del__ is called, the weakref should have been cleared
-                if self.ref() is None:
+                # when __del__ is called, the weakref to myself is still valid
+                # in RPython (at least with most GCs; this test might be
+                # skipped for specific GCs)
+                if self.ref() is self:
                     a.count += 10  # ok
                 else:
                     a.count = 666  # not ok
@@ -732,6 +734,9 @@
 class TestMarkSweepGC(GCTest):
     from pypy.rpython.memory.gc.marksweep import MarkSweepGC as GCClass
 
+    def test_weakref_to_object_with_finalizer_ordering(self):
+        py.test.skip("Does not work")
+
 class TestSemiSpaceGC(GCTest, snippet.SemiSpaceGCTests):
     from pypy.rpython.memory.gc.semispace import SemiSpaceGC as GCClass
     GC_CAN_MOVE = True
@@ -754,9 +759,6 @@
     def test_finalizer_order(self):
         py.test.skip("Not implemented yet")
 
-    def test_weakref_to_object_with_finalizer_ordering(self):
-        py.test.skip("Not implemented yet")
-
 class TestHybridGC(TestGenerationalGC):
     from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
     GC_CAN_MALLOC_NONMOVABLE = True



More information about the Pypy-commit mailing list