[pypy-svn] r22680 - in pypy/dist/pypy/rpython/memory: . test

rxe at codespeak.net rxe at codespeak.net
Thu Jan 26 13:16:21 CET 2006


Author: rxe
Date: Thu Jan 26 13:16:19 2006
New Revision: 22680

Added:
   pypy/dist/pypy/rpython/memory/test/test_lltypelayout.py   (contents, props changed)
Modified:
   pypy/dist/pypy/rpython/memory/lltypelayout.py
Log:
My money is on this is a bug.  Added test.  Please review!



Modified: pypy/dist/pypy/rpython/memory/lltypelayout.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lltypelayout.py	(original)
+++ pypy/dist/pypy/rpython/memory/lltypelayout.py	Thu Jan 26 13:16:19 2006
@@ -139,5 +139,6 @@
             return offsets_to_gc_pointers(TYPE.OF)
         return []
     elif isinstance(TYPE, lltype.Struct):
-        return offsets_to_gc_pointers(getattr(TYPE, TYPE._arrayfld)) 
+        return varsize_offsets_to_gcpointers_in_var_part(getattr(TYPE,
+                                                                 TYPE._arrayfld)) 
     

Added: pypy/dist/pypy/rpython/memory/test/test_lltypelayout.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/memory/test/test_lltypelayout.py	Thu Jan 26 13:16:19 2006
@@ -0,0 +1,35 @@
+from pypy.rpython.memory.lltypelayout import offsets_to_gc_pointers, \
+     varsize_offset_to_length, varsize_offsets_to_gcpointers_in_var_part
+from pypy.rpython.lltypesystem import lltype
+
+def getname(T):
+    try:
+        return "field:" + T._name
+    except:
+        return "field:" + T.__name__
+
+S = lltype.Struct('S', ('s', lltype.Signed), ('char', lltype.Char))
+GC_S = lltype.GcStruct('GC_S', ('S', S))
+
+A = lltype.Array(S)
+GC_A = lltype.GcArray(S)
+
+S2 = lltype.Struct('SPTRS',
+                   *[(getname(TYPE), lltype.Ptr(TYPE)) for TYPE in (GC_S, GC_A)])  
+GC_S2 = lltype.GcStruct('GC_S2', ('S2', S2))
+
+A2 = lltype.Array(S2)
+GC_A2 = lltype.GcArray(S2)
+
+l = [(getname(TYPE), lltype.Ptr(TYPE)) for TYPE in (GC_S, GC_A)]
+l.append(('vararray', A2))
+
+GC_S3 = lltype.GcStruct('GC_S3', *l)
+
+def test_struct():
+    for T, c in [(GC_S, 0), (GC_S2, 2), (GC_A, 0), (GC_A2, 0), (GC_S3, 2)]:
+        assert len(offsets_to_gc_pointers(T)) == c
+        
+    for T1, T2 in [(GC_A, GC_S), (GC_A2, GC_S2), (GC_S3, GC_S2)]:
+        assert (len(varsize_offsets_to_gcpointers_in_var_part(T1)) ==
+                len(offsets_to_gc_pointers(T2)))



More information about the Pypy-commit mailing list