Author: Armin Rigo <[email protected]>
Branch: weakref
Changeset: r398:afdffd3e0b36
Date: 2013-07-15 16:37 +0200
http://bitbucket.org/pypy/stmgc/changeset/afdffd3e0b36/

Log:    Weakrefs to old objects

diff --git a/c4/nursery.c b/c4/nursery.c
--- a/c4/nursery.c
+++ b/c4/nursery.c
@@ -449,6 +449,8 @@
         weakref = (gcptr)weakref->h_revision;
         size_t size = stmgc_size(weakref);
         gcptr obj = WEAKREF_PTR(weakref, size);
+        if (!is_in_nursery(d, obj))
+            continue;   /* the pointer does not change */
 
         if (obj->h_tid & GCFLAG_NURSERY_MOVED)
             obj = obj->h_revision;
diff --git a/c4/test/test_nursery.py b/c4/test/test_nursery.py
--- a/c4/test/test_nursery.py
+++ b/c4/test/test_nursery.py
@@ -348,3 +348,16 @@
     p2 = lib.stm_pop_root()
     p1 = lib.stm_pop_root()
     assert lib.rawgetptr(p1, 0) == p2
+
+def test_weakref_old_keep():
+    p2 = oalloc(HDR)
+    p1 = lib.stm_weakref_allocate(WEAKREF_SIZE, WEAKREF_TID, p2)
+    assert p1.h_tid == WEAKREF_TID   # no GC flags
+    assert p1.h_revision == lib.get_private_rev_num()
+    assert lib.rawgetptr(p1, 0) == p2
+    lib.stm_push_root(p1)
+    lib.stm_push_root(p2)
+    minor_collect()
+    p2 = lib.stm_pop_root()
+    p1 = lib.stm_pop_root()
+    assert lib.rawgetptr(p1, 0) == p2
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to