Author: Remi Meier
Branch: c7-weakref
Changeset: r984:2bb70b712097
Date: 2014-03-12 16:52 +0100
http://bitbucket.org/pypy/stmgc/changeset/2bb70b712097/

Log:    fix cleanup on abort

diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -484,6 +484,7 @@
     /* reset these lists to NULL too on abort */
     LIST_FREE(pseg->objects_pointing_to_nursery);
     LIST_FREE(pseg->large_overflow_objects);
+    list_clear(pseg->young_weakrefs);
 }
 
 static void abort_with_mutex(void)
diff --git a/c7/test/test_weakref.py b/c7/test/test_weakref.py
--- a/c7/test/test_weakref.py
+++ b/c7/test/test_weakref.py
@@ -81,11 +81,49 @@
         assert stm_get_weakref(lp1) == lp0
 
 
+    def test_abort_cleanup(self):
+        self.start_transaction()
 
+        self.push_root_no_gc()
+        lp1 = stm_allocate_weakref(ffi.NULL)    # no collection here
+        self.pop_root()
 
+        self.abort_transaction()
+        self.start_transaction()
 
 
 
+class TestMajorCollection(BaseTest):
+    def test_simple(self):
+        self.start_transaction()
+
+        self.push_root_no_gc()
+        lp2 = stm_allocate(48)
+        lp1 = stm_allocate_weakref(lp2)    # no collection here
+        self.pop_root()
+
+        assert stm_get_weakref(lp1) == lp2
+
+        self.push_root(lp1)
+        self.push_root(lp2)
+        stm_minor_collect()
+        lp2 = self.pop_root()
+        lp1 = self.pop_root()
+        # lp2 survived
+        assert stm_get_weakref(lp1) == lp2
+
+        self.push_root(lp1)
+        stm_minor_collect()
+        lp1 = self.pop_root()
+        # lp2 survived because no major collection
+        assert stm_get_weakref(lp1) == lp2
+
+        self.push_root(lp1)
+        stm_major_collect()
+        lp1 = self.pop_root()
+        # lp2 died
+        assert stm_get_weakref(lp1) == ffi.NULL
+
 
 
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to