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

arigo at codespeak.net arigo at codespeak.net
Wed Nov 17 11:56:06 CET 2010


Author: arigo
Date: Wed Nov 17 11:56:05 2010
New Revision: 79182

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:
Fixing the test is as easy as swapping two phases of a major collection:
we have to *first* invalidate weakrefs and *then* trace from the finalizers.

Skipped in TestMarkCompactGC for now.


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	Wed Nov 17 11:56:05 2010
@@ -1205,6 +1205,10 @@
         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
@@ -1214,10 +1218,6 @@
         #
         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	Wed Nov 17 11:56:05 2010
@@ -266,10 +266,10 @@
         if self.run_finalizers.non_empty():
             self.update_run_finalizers()
         scan = self.scan_copied(scan)
-        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()
+        if self.objects_with_finalizers.non_empty():
+            scan = self.deal_with_objects_with_finalizers(scan)
         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	Wed Nov 17 11:56:05 2010
@@ -306,7 +306,7 @@
             def __del__(self):
                 # when __del__ is called, the weakref should have been cleared
                 if self.ref() is None:
-                    a.count += 1   # ok
+                    a.count += 10  # ok
                 else:
                     a.count = 666  # not ok
         class C(object):
@@ -321,10 +321,10 @@
             ref = g()
             llop.gc__collect(lltype.Void)
             llop.gc__collect(lltype.Void)
-            result = a.count == 1 and (ref() is None)
+            result = a.count + (ref() is None)
             return result
         res = self.interpret(f, [])
-        assert res
+        assert res == 11
 
     def test_weakref_to_object_with_finalizer_ordering(self):
         import weakref, gc
@@ -335,7 +335,7 @@
             def __del__(self):
                 # when __del__ is called, the weakref should have been cleared
                 if self.ref() is None:
-                    a.count += 1   # ok
+                    a.count += 10  # ok
                 else:
                     a.count = 666  # not ok
         def g():
@@ -347,10 +347,10 @@
             ref = g()
             llop.gc__collect(lltype.Void)
             llop.gc__collect(lltype.Void)
-            result = a.count == 1 and (ref() is None)
+            result = a.count + (ref() is None)
             return result
         res = self.interpret(f, [])
-        assert res
+        assert res == 11
 
     def test_id(self):
         class A(object):
@@ -731,6 +731,9 @@
     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