[pypy-commit] pypy default: merge heads

arigo noreply at buildbot.pypy.org
Fri Oct 26 12:01:41 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r58433:6b60148cc3bb
Date: 2012-10-26 12:01 +0200
http://bitbucket.org/pypy/pypy/changeset/6b60148cc3bb/

Log:	merge heads

diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -4306,14 +4306,7 @@
         """
         expected = """
         []
-        p0 = newstr(11)
-        copystrcontent(s"hello world", p0, 0, 0, 11)
-        # Eventually this should just return s"hello", but ATM this test is
-        # just verifying that it doesn't return "\0\0\0\0\0", so being
-        # slightly underoptimized is ok.
-        p1 = newstr(5)
-        copystrcontent(p0, p1, 0, 0, 5)
-        finish(p1)
+        finish(s"hello")
         """
         self.optimize_strunicode_loop(ops, expected)
 
@@ -4963,12 +4956,7 @@
         """
         expected = """
         [i1]
-        p0 = newstr(6)
-        copystrcontent(s"hello!", p0, 0, 0, 6)
-        p1 = newstr(12)
-        copystrcontent(p0, p1, 0, 0, 6)
-        copystrcontent(s"abc123", p1, 0, 6, 6)
-        i0 = strgetitem(p1, i1)
+        i0 = strgetitem(s"hello!abc123", i1)
         finish(i0)
         """
         self.optimize_strunicode_loop(ops, expected)
@@ -4984,10 +4972,7 @@
         """
         expected = """
         []
-        p0 = newstr(6)
-        copystrcontent(s"hello!", p0, 0, 0, 6)
-        i0 = strgetitem(p0, 0)
-        finish(i0)
+        finish(104)
         """
         self.optimize_strunicode_loop(ops, expected)
 
@@ -5067,6 +5052,21 @@
         """
         self.optimize_strunicode_loop(ops, expected)
 
+    def test_str_copy_constant_virtual(self):
+        ops = """
+        []
+        p0 = newstr(10)
+        copystrcontent(s"abcd", p0, 0, 0, 4)
+        strsetitem(p0, 4, 101)
+        copystrcontent(s"fghij", p0, 0, 5, 5)
+        finish(p0)
+        """
+        expected = """
+        []
+        finish(s"abcdefghij")
+        """
+        self.optimize_strunicode_loop(ops, expected)
+
     def test_call_pure_vstring_const(self):
         py.test.skip("implement me")
         ops = """
diff --git a/pypy/jit/metainterp/optimizeopt/vstring.py b/pypy/jit/metainterp/optimizeopt/vstring.py
--- a/pypy/jit/metainterp/optimizeopt/vstring.py
+++ b/pypy/jit/metainterp/optimizeopt/vstring.py
@@ -489,6 +489,7 @@
 
     def optimize_COPYSTRCONTENT(self, op):
         self._optimize_COPYSTRCONTENT(op, mode_string)
+
     def optimize_COPYUNICODECONTENT(self, op):
         self._optimize_COPYSTRCONTENT(op, mode_unicode)
 
@@ -507,8 +508,8 @@
 
         if length.is_constant() and length.box.getint() == 0:
             return
-        elif (src.is_virtual() and dst.is_virtual() and srcstart.is_constant() and
-            dststart.is_constant() and length.is_constant()):
+        elif ((src.is_virtual() or src.is_constant()) and dst.is_virtual() and
+            srcstart.is_constant() and dststart.is_constant() and length.is_constant()):
 
             src_start = srcstart.force_box(self).getint()
             dst_start = dststart.force_box(self).getint()
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -9,6 +9,7 @@
 from pypy.objspace.std.multimethod import FailedToImplement
 from pypy.objspace.std.stdtypedef import SMM, StdTypeDef
 from pypy.objspace.std.register_all import register_all
+from pypy.rlib import jit
 from pypy.rlib.rarithmetic import ovfcheck, widen
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.objectmodel import specialize, keepalive_until_here
@@ -466,6 +467,9 @@
         self.setlen(0)
         self.fromsequence(w_lst)
 
+    # We can't look into this function until ptradd works with things (in the
+    # JIT) other than rffi.CCHARP
+    @jit.dont_look_inside
     def delslice__Array_ANY_ANY(space, self, w_i, w_j):
         i = space.int_w(w_i)
         if i < 0:
@@ -495,13 +499,13 @@
             rffi.c_memcpy(
                 rffi.cast(rffi.VOIDP, rffi.ptradd(self.buffer, i)),
                 rffi.cast(rffi.VOIDP, rffi.ptradd(oldbuffer, j)),
-                (self.len - j) * mytype.bytes)
+                (self.len - j) * mytype.bytes
+            )
         self.len -= j - i
         self.allocated = self.len
         if oldbuffer:
             lltype.free(oldbuffer, flavor='raw')
 
-
     # Add and mul methods
 
     def add__Array_Array(space, self, other):
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -13,6 +13,8 @@
 from pypy.objspace.std.listtype import get_list_index
 from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
 from pypy.objspace.std.stringobject import W_StringObject
+from pypy.objspace.std.strutil import ParseStringError
+from pypy.objspace.std.strutil import string_to_float
 from pypy.objspace.std.tupleobject import W_TupleObject
 from pypy.objspace.std.unicodeobject import W_UnicodeObject
 from pypy.objspace.std import slicetype
@@ -81,6 +83,14 @@
     data = makebytearraydata_w(space, w_source)
     w_bytearray.data = data
 
+def float__Bytearray(space, w_bytearray):
+    try:
+        value = string_to_float(''.join(w_bytearray.data))
+    except ParseStringError, e:
+        raise OperationError(space.w_ValueError, space.wrap(e.msg))
+    else:
+        return space.wrap(value)
+
 def len__Bytearray(space, w_bytearray):
     result = len(w_bytearray.data)
     return wrapint(space, result)
diff --git a/pypy/objspace/std/test/test_bytearrayobject.py b/pypy/objspace/std/test/test_bytearrayobject.py
--- a/pypy/objspace/std/test/test_bytearrayobject.py
+++ b/pypy/objspace/std/test/test_bytearrayobject.py
@@ -439,6 +439,14 @@
     def test_int(self):
         assert int(bytearray('-1234')) == -1234
 
+    def test_float(self):
+        assert float(bytearray(b'10.4')) == 10.4
+        assert float(bytearray('-1.7e-1')) == -1.7e-1
+        assert float(bytearray(u'.9e10', 'utf-8')) == .9e10
+        import math
+        assert math.isnan(float(bytearray('nan')))
+        raises(ValueError, float, bytearray('not_a_number'))
+
     def test_reduce(self):
         assert bytearray('caf\xe9').__reduce__() == (
             bytearray, (u'caf\xe9', 'latin-1'), None)


More information about the pypy-commit mailing list