Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r69925:d944127917e1
Date: 2014-03-13 08:11 +0100
http://bitbucket.org/pypy/pypy/changeset/d944127917e1/
Log: Test and fix for GC roots stored in non-GC prebuilt objects
diff --git a/rpython/memory/gc/base.py b/rpython/memory/gc/base.py
--- a/rpython/memory/gc/base.py
+++ b/rpython/memory/gc/base.py
@@ -18,6 +18,7 @@
needs_write_barrier = False
malloc_zero_filled = False
prebuilt_gc_objects_are_static_roots = True
+ ignore_immutable_static_roots = True
object_minimal_size = 0
gcflag_extra = 0 # or a real GC flag that is always 0 when not collecting
diff --git a/rpython/memory/gc/stmgc.py b/rpython/memory/gc/stmgc.py
--- a/rpython/memory/gc/stmgc.py
+++ b/rpython/memory/gc/stmgc.py
@@ -23,6 +23,7 @@
inline_simple_malloc_varsize = True
needs_write_barrier = "stm"
prebuilt_gc_objects_are_static_roots = False
+ ignore_immutable_static_roots = False
malloc_zero_filled = True
object_minimal_size = 16
#gcflag_extra = GCFLAG_EXTRA
diff --git a/rpython/memory/gctypelayout.py b/rpython/memory/gctypelayout.py
--- a/rpython/memory/gctypelayout.py
+++ b/rpython/memory/gctypelayout.py
@@ -451,7 +451,8 @@
return
else:
appendto = self.addresses_of_static_ptrs_in_nongc
- for a in gc_pointers_inside(value, adr, mutable_only=True):
+ mutable_only = gc.ignore_immutable_static_roots
+ for a in gc_pointers_inside(value, adr, mutable_only=mutable_only):
appendto.append(a)
# ____________________________________________________________
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -882,6 +882,14 @@
*pp = stm_setup_prebuilt(*pp);
stm_set_prebuilt_identityhash(*pp, *ph);
}
+
+ object_t ***cur = (object_t ***)
+ pypy_g_rpython_memory_gctypelayout_GCData.gcd_inst_static_root_start;
+ object_t ***end = (object_t ***)
+ pypy_g_rpython_memory_gctypelayout_GCData.gcd_inst_static_root_nongcend;
+ for ( ; cur != end; cur++) {
+ **cur = stm_setup_prebuilt(**cur);
+ }
}
'''
diff --git a/rpython/translator/stm/test/test_ztranslated.py
b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -433,3 +433,23 @@
assert ': -inf\n' in data
data = cbuilder.cmdexec('2')
assert ': nan\n' in data
+
+ def test_static_root_in_nongc(self):
+ class A:
+ def __init__(self, n):
+ self.n = n
+ class B:
+ def _freeze_(self):
+ return True
+ b1 = B(); b1.a = A(42)
+ b2 = B(); b2.a = A(84)
+ def dump(b):
+ print '<', b.a.n, '>'
+ def main(argv):
+ dump(b1)
+ dump(b2)
+ return 0
+
+ t, cbuilder = self.compile(main)
+ data = cbuilder.cmdexec('')
+ assert '< 42 >\n< 84 >\n' in data
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit