Commits

Antonio Cuni committed 15d965e

add a test for a virtual which survives one iteration of the loop, and fix it

  • Participants
  • Parent commits 134553c
  • Branches virtual-raw-mallocs

Comments (0)

Files changed (2)

pypy/jit/metainterp/optimizeopt/virtualstate.py

     def make_varraystruct(self, arraydescr, fielddescrs):
         return VArrayStructStateInfo(arraydescr, fielddescrs)
 
-    def make_vrawbuffer(self):
+    def make_vrawbuffer(self, size, offsets, descrs):
         return VRawBufferStateInfo()
 
 class BoxNotProducable(Exception):

pypy/jit/metainterp/test/test_virtual.py

         # the getarrayitem_raw is in the bridge
         self.check_resops(getarrayitem_raw=1, setarrayitem_raw=0)
 
+    def test_raw_malloc_two_iterations(self):
+        mydriver = JitDriver(greens=[], reds = 'auto')
+        def f(n):
+            res = 0
+            buffer = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw')
+            buffer[0] = chr(0)
+            while ord(buffer[0]) < n:
+                mydriver.jit_merge_point()
+                i = ord(buffer[0])
+                lltype.free(buffer, flavor='raw')
+                buffer = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw')
+                buffer[0] = chr(i+1)
+                res += i
+            lltype.free(buffer, flavor='raw')
+            return res
+        assert f(10) == 45
+        res = self.meta_interp(f, [10])
+        assert res == 45
+        # the getarrayitem_raw is in the preamble
+        self.check_resops(getarrayitem_raw=1, setarrayitem_raw=0)
+
+
 
 
 OONODE = ootype.Instance('NODE', ootype.ROOT, {})