[pypy-svn] r36878 - in pypy/dist/pypy/jit/timeshifter: . test

ac at codespeak.net ac at codespeak.net
Wed Jan 17 16:48:21 CET 2007


Author: ac
Date: Wed Jan 17 16:48:19 2007
New Revision: 36878

Modified:
   pypy/dist/pypy/jit/timeshifter/rcontainer.py
   pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
Log:
(pedronis, arre) Test for self-referential structures.

Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py	Wed Jan 17 16:48:19 2007
@@ -64,6 +64,16 @@
         innermostdesc = self
         if not TYPE._is_varsize():
             self.alloctoken = RGenOp.allocToken(TYPE)
+
+        # N.B. Closes over descs defined below
+        def fill_into(s, base, vinfo):
+            i = 0
+            for desc in descs:
+                v = vinfo.read_field(desc, base, i)
+                i += 1
+                setattr(s, desc.fieldname, v)
+        self.fill_into = fill_into
+
         fielddescs = []
         fielddesc_by_name = {}
         for name in self.TYPE._names:
@@ -87,6 +97,8 @@
                     desc = StructFieldDesc(hrtyper, self.PTRTYPE, name, index)
                     fielddescs.append(desc)
                 fielddesc_by_name[name] = desc
+        descs = unrolling_iterable(fielddescs) # Used in fill_into above
+
         self.fielddescs = fielddescs
         self.fielddesc_by_name = fielddesc_by_name
         self.innermostdesc = innermostdesc
@@ -131,7 +143,6 @@
         else:
             self.VStructCls = VirtualStruct
 
-        descs = unrolling_iterable(fielddescs)
         if self.immutable and self.noidentity:
             
             def materialize(rgenop, boxes):
@@ -145,14 +156,6 @@
 
             self.materialize = materialize
 
-        def fill_into(s, base, vinfo):
-            i = 0
-            for desc in descs:
-                v = vinfo.read_field(desc, base, i)
-                i += 1
-                setattr(s, desc.fieldname, v)
-        self.fill_into = fill_into
-
         self.gv_make_vinfo_ptr = hrtyper.gv_make_vinfo_ptr
         self.make_vinfo_token = hrtyper.make_vinfo_token
 

Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	Wed Jan 17 16:48:19 2007
@@ -1231,3 +1231,25 @@
 
         res = self.timeshift(f, [ord('b'), 0], [], policy=P_NOVIRTUAL)
         assert res == 1
+
+    def test_self_referential_structures(self):
+        S = lltype.GcForwardReference()
+        S.become(lltype.GcStruct('s',
+                                 ('ps', lltype.Ptr(S))))
+
+        def f(x):
+            s = lltype.malloc(S)
+            if x:
+                s.ps = lltype.malloc(S)
+            return s
+        def count_depth(s):
+            x = 0
+            while s:
+                x += 1
+                s = s.ps
+            return str(x)
+        
+        f.convert_result = count_depth
+
+        res = self.timeshift(f, [3], [], policy=P_NOVIRTUAL)
+        assert res == '2'



More information about the Pypy-commit mailing list