[pypy-svn] r67464 - in pypy/branch/weakdict/pypy/rpython/memory: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Sep 4 11:30:01 CEST 2009
Author: arigo
Date: Fri Sep 4 11:29:58 2009
New Revision: 67464
Modified:
pypy/branch/weakdict/pypy/rpython/memory/gctypelayout.py
pypy/branch/weakdict/pypy/rpython/memory/test/test_gctypelayout.py
Log:
In the encoding of GcArrays with the 'weakarray' hint,
put in the weakpointer_offset the offset of the weak field
within the variable part.
Modified: pypy/branch/weakdict/pypy/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/branch/weakdict/pypy/rpython/memory/gctypelayout.py (original)
+++ pypy/branch/weakdict/pypy/rpython/memory/gctypelayout.py Fri Sep 4 11:29:58 2009
@@ -352,6 +352,9 @@
def weakpointer_offset(TYPE):
if TYPE == WEAKREF:
return llmemory.offsetof(WEAKREF, "weakptr")
+ if isinstance(TYPE, lltype.GcArray) and 'weakarray' in TYPE._hints:
+ weakfieldname = TYPE._hints['weakarray']
+ return llmemory.offsetof(TYPE.OF, weakfieldname)
return -1
def gc_pointers_inside(v, adr, mutable_only=False):
Modified: pypy/branch/weakdict/pypy/rpython/memory/test/test_gctypelayout.py
==============================================================================
--- pypy/branch/weakdict/pypy/rpython/memory/test/test_gctypelayout.py (original)
+++ pypy/branch/weakdict/pypy/rpython/memory/test/test_gctypelayout.py Fri Sep 4 11:29:58 2009
@@ -1,6 +1,6 @@
from pypy.rpython.memory.gctypelayout import TypeLayoutBuilder, GCData
from pypy.rpython.memory.gctypelayout import offsets_to_gc_pointers
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, llmemory
def getname(T):
try:
@@ -40,3 +40,22 @@
lst1 = gcdata.q_varsize_offsets_to_gcpointers_in_var_part(tid1)
lst2 = gcdata.q_offsets_to_gc_pointers(tid2)
assert len(lst1) == len(lst2)
+
+def test_weakarray():
+ OBJ = lltype.GcStruct('some_object')
+ S = lltype.Struct('weakstruct',
+ ('foo', lltype.Ptr(OBJ)),
+ ('bar', lltype.Ptr(OBJ)))
+ A = lltype.GcArray(S, hints={'weakarray': 'bar'})
+ layoutbuilder = TypeLayoutBuilder()
+ tid = layoutbuilder.get_type_id(A)
+ gcdata = GCData(layoutbuilder.type_info_list)
+ assert gcdata.q_is_varsize(tid)
+ assert gcdata.q_has_gcptr_in_varsize(tid)
+ assert not gcdata.q_is_gcarrayofgcptr(tid)
+ assert len(gcdata.q_offsets_to_gc_pointers(tid)) == 0
+ assert len(gcdata.q_varsize_offsets_to_gcpointers_in_var_part(tid)) == 2
+ weakofs = gcdata.q_weakpointer_offset(tid)
+ assert isinstance(weakofs, llmemory.FieldOffset)
+ assert weakofs.TYPE == S
+ assert weakofs.fldname == 'bar'
More information about the Pypy-commit
mailing list