Author: Maciej Fijalkowski <[email protected]>
Branch: rdict-experiments
Changeset: r59783:c6a93cd01585
Date: 2013-01-05 22:36 +0200
http://bitbucket.org/pypy/pypy/changeset/c6a93cd01585/
Log: merge default
diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -140,10 +140,11 @@
return hop.genop(opname, vlist, resulttype = hop.r_result.lowleveltype)
def copy_struct_item(source, dest, si, di):
- TP = lltype.typeOf(source)
+ TP = lltype.typeOf(source).TO.OF
i = 0
while i < len(TP._names):
setattr(dest[di], TP._names[i], getattr(source[si], TP._names[i]))
+ i += 1
class CopyStructEntry(ExtRegistryEntry):
_about_ = copy_struct_item
@@ -173,6 +174,15 @@
else:
dest[di] = source[si]
[email protected]()
+def _contains_gcptr(TP):
+ if not isinstance(TP, lltype.Struct):
+ return False
+ for TP in TP._flds.itervalues():
+ if isinstance(TP, lltype.Ptr) and TP.TO._gckind == 'gc':
+ return True
+ return False
+
@jit.oopspec('list.ll_arraycopy(source, dest, source_start, dest_start,
length)')
@enforceargs(None, None, int, int, int)
@specialize.ll()
@@ -195,7 +205,8 @@
TP = lltype.typeOf(source).TO
assert TP == lltype.typeOf(dest).TO
- if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
+ if isinstance(TP.OF, lltype.Ptr) and (TP.OF.TO._gckind == 'gc'
+ or _contains_gcptr(TP.OF.TO)):
# perform a write barrier that copies necessary flags from
# source to dest
if not llop.gc_writebarrier_before_copy(lltype.Bool, source, dest,
diff --git a/pypy/rlib/test/test_rgc.py b/pypy/rlib/test/test_rgc.py
--- a/pypy/rlib/test/test_rgc.py
+++ b/pypy/rlib/test/test_rgc.py
@@ -150,7 +150,21 @@
interpret(f, [])
- f()
+ a1 = lltype.malloc(TP, 3)
+ a2 = lltype.malloc(TP, 3)
+ a1[1].x = 3
+ a1[1].y = 15
+ rgc.copy_struct_item(a1, a2, 1, 2)
+ assert a2[2].x == 3
+ assert a2[2].y == 15
+
+def test__contains_gcptr():
+ assert not rgc._contains_gcptr(lltype.Signed)
+ assert not rgc._contains_gcptr(lltype.Struct('x', ('x', lltype.Signed)))
+ assert rgc._contains_gcptr(lltype.Struct('x', ('x', lltype.Signed),
+ ('y', lltype.Ptr(lltype.GcArray(lltype.Signed)))))
+ assert rgc._contains_gcptr(lltype.Struct('x', ('x', lltype.Signed),
+ ('y', llmemory.GCREF)))
def test_ll_arraycopy_small():
TYPE = lltype.GcArray(lltype.Signed)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit