Commits

Manuel Jacob committed 0dcdafb Merge

hg merge default

Comments (0)

Files changed (17)

lib_pypy/_ctypes/array.py

                     # we don't want to have buffers here
                     if len(val) > self._length_:
                         raise ValueError("%r too long" % (val,))
-                    for i in range(len(val)):
-                        self[i] = val[i]
+                    if isinstance(val, str):
+                        _rawffi.rawstring2charp(self._buffer.buffer, val)
+                    else:
+                        for i in range(len(val)):
+                            self[i] = val[i]
                     if len(val) < self._length_:
-                        self[len(val)] = '\x00'
+                        self._buffer[len(val)] = '\x00'
                 res.value = property(getvalue, setvalue)
 
                 def getraw(self):
                 def setraw(self, buffer):
                     if len(buffer) > self._length_:
                         raise ValueError("%r too long" % (buffer,))
-                    for i in range(len(buffer)):
-                        self[i] = buffer[i]
+                    _rawffi.rawstring2charp(self._buffer.buffer, buffer)
                 res.raw = property(getraw, setraw)
             elif subletter == 'u':
                 def getvalue(self):
                     # we don't want to have buffers here
                     if len(val) > self._length_:
                         raise ValueError("%r too long" % (val,))
+                    if isinstance(val, unicode):
+                        target = self._buffer
+                    else:
+                        target = self
                     for i in range(len(val)):
-                        self[i] = val[i]
+                        target[i] = val[i]
                     if len(val) < self._length_:
-                        self[len(val)] = '\x00'
+                        target[len(val)] = u'\x00'
                 res.value = property(getvalue, setvalue)
                 
             if '_length_' in typedict:

pypy/module/_rawffi/__init__.py

         'wcharp2unicode'     : 'interp_rawffi.wcharp2unicode',
         'charp2rawstring'    : 'interp_rawffi.charp2rawstring',
         'wcharp2rawunicode'  : 'interp_rawffi.wcharp2rawunicode',
+        'rawstring2charp'    : 'interp_rawffi.rawstring2charp',
         'CallbackPtr'        : 'callback.W_CallbackPtr',
         '_num_of_allocated_objects' : 'tracker.num_of_allocated_objects',
         'get_libc'           : 'interp_rawffi.get_libc',

pypy/module/_rawffi/interp_rawffi.py

     s = rffi.wcharpsize2unicode(rffi.cast(rffi.CWCHARP, address), maxlength)
     return space.wrap(s)
 
+@unwrap_spec(address=r_uint, newcontent=str)
+def rawstring2charp(space, address, newcontent):
+    from rpython.rtyper.annlowlevel import llstr
+    from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw
+    array = rffi.cast(rffi.CCHARP, address)
+    copy_string_to_raw(llstr(newcontent), array, 0, len(newcontent))
+
 if _MS_WINDOWS:
     @unwrap_spec(code=int)
     def FormatError(space, code):

pypy/module/_rawffi/test/test__rawffi.py

         assert res == u'xx'
         a.free()
 
+    def test_rawstring2charp(self):
+        import _rawffi
+        A = _rawffi.Array('c')
+        a = A(10, 'x'*10)
+        _rawffi.rawstring2charp(a.buffer, "foobar")
+        assert ''.join([a[i] for i in range(10)]) == "foobarxxxx"
+        a.free()
+
     def test_raw_callable(self):
         import _rawffi
         lib = _rawffi.CDLL(self.lib_name)

pypy/module/test_lib_pypy/ctypes_tests/support.py

             import gc
             for _ in range(4):
                 gc.collect()
-            cls.old_num = _rawffi._num_of_allocated_objects()
-
+            try:
+                cls.old_num = _rawffi._num_of_allocated_objects()
+            except RuntimeError:
+                pass
 
     def teardown_class(cls):
         if sys.pypy_translation_info['translation.gc'] == 'boehm':

pypy/tool/gdb_pypy.py

     if len(names) == 1:
         return val[names[0]]
     elif len(names) == 0:
-        raise KeyError, "cannot find field *%s" % suffix
+        raise KeyError("cannot find field *%s" % suffix)
     else:
-        raise KeyError, "too many matching fields: %s" % ', '.join(names)
+        raise KeyError("too many matching fields: %s" % ', '.join(names))
 
 def lookup(val, suffix):
     """
     def invoke(self, arg, from_tty):
         # some magic code to automatically reload the python file while developing
         from pypy.tool import gdb_pypy
-        reload(gdb_pypy)
+        try:
+            reload(gdb_pypy)
+        except:
+            import imp
+            imp.reload(gdb_pypy)
         gdb_pypy.RPyType.prog2typeids = self.prog2typeids # persist the cache
         self.__class__ = gdb_pypy.RPyType
-        print self.do_invoke(arg, from_tty)
+        print (self.do_invoke(arg, from_tty).decode('latin-1'))
 
     def do_invoke(self, arg, from_tty):
         try:
             obj = self.gdb.parse_and_eval(arg)
             hdr = lookup(obj, '_gcheader')
             tid = hdr['h_tid']
-            if sys.maxint < 2**32:
+            if sys.maxsize < 2**32:
                 offset = tid & 0xFFFF     # 32bit
             else:
                 offset = tid & 0xFFFFFFFF # 64bit
         if linenum in self.line2offset:
             return self.line2offset[linenum]
         line = self.lines[linenum]
-        member, descr = map(str.strip, line.split(None, 1))
-        if sys.maxint < 2**32:
+        member, descr = [x.strip() for x in line.split(None, 1)]
+        if sys.maxsize < 2**32:
             TIDT = "int*"
         else:
             TIDT = "char*"
         expr = ("((%s)(&pypy_g_typeinfo.%s)) - (%s)&pypy_g_typeinfo"
-                   % (TIDT, member, TIDT))
+                   % (TIDT, member.decode("latin-1"), TIDT))
         offset = int(self.gdb.parse_and_eval(expr))
         self.line2offset[linenum] = offset
         self.offset2descr[offset] = descr
         # binary search through the lines, asking gdb to parse stuff lazily
         if offset in self.offset2descr:
             return self.offset2descr[offset]
-        if not (0 < offset < sys.maxint):
+        if not (0 < offset < sys.maxsize):
             return None
         linerange = (0, len(self.lines))
         while linerange[0] < linerange[1]:

rpython/jit/metainterp/optimizeopt/earlyforce.py

                     value.force_box(self)
         self.emit_operation(op)
 
-    def new(self):
-        return OptEarlyForce()
-
     def setup(self):
         self.optimizer.optearlyforce = self

rpython/jit/metainterp/optimizeopt/heap.py

             self.postponed_op = None
             self.next_optimization.propagate_forward(postponed_op)
 
-    def new(self):
-        return OptHeap()
-
     def produce_potential_short_preamble_ops(self, sb):
         descrkeys = self.cached_fields.keys()
         if not we_are_translated():

rpython/jit/metainterp/optimizeopt/intbounds.py

     """Keeps track of the bounds placed on integers by guards and remove
        redundant guards"""
 
-    def new(self):
-        return OptIntBounds()
-
     def propagate_forward(self, op):
         dispatch_opt(self, op)
 

rpython/jit/metainterp/optimizeopt/optimizer.py

     def force_at_end_of_preamble(self):
         pass
 
-    # It is too late to force stuff here, it must be done in force_at_end_of_preamble
-    def new(self):
-        raise NotImplementedError
-
     # Called after last operation has been propagated to flush out any posponed ops
     def flush(self):
         pass
         for o in self.optimizations:
             o.flush()
 
-    def new(self):
-        new = Optimizer(self.metainterp_sd, self.loop)
-        return self._new(new)
-
-    def _new(self, new):
-        optimizations = [o.new() for o in self.optimizations]
-        new.set_optimizations(optimizations)
-        new.quasi_immutable_deps = self.quasi_immutable_deps
-        return new
-
     def produce_potential_short_preamble_ops(self, sb):
         for opt in self.optimizations:
             opt.produce_potential_short_preamble_ops(sb)

rpython/jit/metainterp/optimizeopt/pure.py

     def flush(self):
         assert self.postponed_op is None
 
-    def new(self):
-        assert self.postponed_op is None
-        return OptPure()
-
     def setup(self):
         self.optimizer.optpure = self
 

rpython/jit/metainterp/optimizeopt/rewrite.py

         self.loop_invariant_results = {}
         self.loop_invariant_producer = {}
 
-    def new(self):
-        return OptRewrite()
-
     def produce_potential_short_preamble_ops(self, sb):
         for op in self.loop_invariant_producer.values():
             sb.add_potential(op)

rpython/jit/metainterp/optimizeopt/unroll.py

             self.emitted_guards += 1 # FIXME: can we use counter in self._emit_operation?
         self._emit_operation(op)
 
-    def new(self):
-        new = UnrollableOptimizer(self.metainterp_sd, self.loop)
-        return self._new(new)
-
 
 class UnrollOptimizer(Optimization):
     """Unroll the loop into two iterations. The first one will

rpython/jit/metainterp/optimizeopt/virtualize.py

 
     _last_guard_not_forced_2 = None
 
-    def new(self):
-        return OptVirtualize()
-
     def make_virtual(self, known_class, box, source_op=None):
         vvalue = VirtualValue(self.optimizer.cpu, known_class, box, source_op)
         self.make_equal_to(box, vvalue)

rpython/jit/metainterp/optimizeopt/vstring.py

 
 class OptString(optimizer.Optimization):
     "Handling of strings and unicodes."
-    def new(self):
-        return OptString()
 
     def make_vstring_plain(self, box, source_op, mode):
         vvalue = VStringPlainValue(box, source_op, mode)

rpython/rtyper/lltypesystem/rstr.py

             i += 1
         return count
 
+    @signature(types.any(), types.any(), types.int(), types.int(), returns=types.int())
     def ll_find(s1, s2, start, end):
         if start < 0:
             start = 0
 
         return LLHelpers.ll_search(s1, s2, start, end, FAST_FIND)
 
+    @signature(types.any(), types.any(), types.int(), types.int(), returns=types.int())
     def ll_rfind(s1, s2, start, end):
         if start < 0:
             start = 0

rpython/translator/unsimplify.py

     block.exitswitch = None
     return link
 
-def split_block_at_start(annotator, block):
-    # split before the first op, preserve order and inputargs
-    # in the second block!
-    return split_block(annotator, block, 0, _forcelink=block.inputargs)
-
 def call_initial_function(translator, initial_func, annhelper=None):
     """Before the program starts, call 'initial_func()'."""
     from rpython.annotator import model as annmodel