Commits

Armin Rigo committed 994df46

Checkin of in-progress changes.

Comments (0)

Files changed (2)

pypy/jit/backend/llsupport/llmodel.py

 from pypy.rpython.llinterp import LLInterpreter, LLException
 from pypy.rpython.annlowlevel import llhelper
 from pypy.rlib.objectmodel import we_are_translated, specialize
+from pypy.rlib.debug import ll_assert
 from pypy.jit.metainterp.history import BoxInt, BoxPtr, set_future_values,\
      BoxFloat
 from pypy.jit.metainterp import history
 
     # ____________________________________________________________
 
+    @specialize.argtype(2)
+    def _checkarraybound(self, arraydescr, array, itemindex):
+        if lltype.typeOf(array) == llmemory.GCREF:
+            length = self.bh_arraylen_gc(arraydescr, array)
+            ll_assert(0 <= itemindex < length,
+                      "bh_setarrayitem_gc: index out of bound")
+
     def bh_arraylen_gc(self, arraydescr, array):
         assert isinstance(arraydescr, BaseArrayDescr)
         ofs = arraydescr.get_ofs_length(self.translate_support_code)
 
     @specialize.argtype(2)
     def bh_getarrayitem_gc_i(self, arraydescr, gcref, itemindex):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs, size, sign = self.unpack_arraydescr_size(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
             raise NotImplementedError("size = %d" % size)
 
     def bh_getarrayitem_gc_r(self, arraydescr, gcref, itemindex):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs = self.unpack_arraydescr(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
 
     @specialize.argtype(2)
     def bh_getarrayitem_gc_f(self, arraydescr, gcref, itemindex):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs = self.unpack_arraydescr(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
 
     @specialize.argtype(2)
     def bh_setarrayitem_gc_i(self, arraydescr, gcref, itemindex, newvalue):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs, size, sign = self.unpack_arraydescr_size(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
             raise NotImplementedError("size = %d" % size)
 
     def bh_setarrayitem_gc_r(self, arraydescr, gcref, itemindex, newvalue):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs = self.unpack_arraydescr(arraydescr)
         self.gc_ll_descr.do_write_barrier(gcref, newvalue)
         # --- start of GC unsafe code (no GC operation!) ---
 
     @specialize.argtype(2)
     def bh_setarrayitem_gc_f(self, arraydescr, gcref, itemindex, newvalue):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs = self.unpack_arraydescr(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)

pypy/jit/backend/x86/assembler.py

         base_loc, ofs_loc, value_loc, size_loc, baseofs = arglocs
         assert isinstance(baseofs, ImmedLoc)
         assert isinstance(size_loc, ImmedLoc)
+        #
+        # XXX
+        if op.getopname() == 'setarrayitem_gc':
+            # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but we may get
+            # it as a setarrayitem_raw!!!!!!  fix this
+            from pypy.jit.backend.llsupport.descr import BaseArrayDescr
+            arraydescr = op.getdescr()
+            assert isinstance(arraydescr, BaseArrayDescr)
+            ofs = arraydescr.get_ofs_length(self.cpu.translate_support_code)
+            self.mc.CMP(addr_add_const(base_loc, ofs), ofs_loc)
+            self.mc.J_il8(rx86.Conditions['A'], 0)
+            ja_location = self.mc.get_relative_pos()
+            self.mc.writechar(chr(0xCC))    # INT3
+            # patch the JA above
+            offset = self.mc.get_relative_pos() - ja_location
+            assert 0 < offset <= 127
+            self.mc.overwrite(ja_location-1, chr(offset))
+        # XXX
+        #
         scale = _get_scale(size_loc.value)
         dest_addr = AddressLoc(base_loc, ofs_loc, scale, baseofs.value)
         self.save_into_mem(dest_addr, value_loc, size_loc)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.