1. Pypy
  2. Untitled project
  3. pypy

Commits

Armin Rigo  committed 40f0c1c Merge

merge heads

  • Participants
  • Parent commits 2fbd921, 70df159
  • Branches default

Comments (0)

Files changed (76)

File pypy/doc/_ref.txt

View file
  • Ignore whitespace
 .. _`rpython/translator/c/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/
 .. _`rpython/translator/c/src/stacklet/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/
 .. _`rpython/translator/c/src/stacklet/stacklet.h`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/stacklet.h
-.. _`rpython/translator/cli/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/cli/
-.. _`rpython/translator/jvm/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/jvm/
 .. _`rpython/translator/tool/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/tool/

File pypy/doc/garbage_collection.rst

View file
  • Ignore whitespace
   are preserved.  If the object dies then the pre-reserved location
   becomes free garbage, to be collected at the next major collection.
 
+The exact name of this GC is either `minimark` or `incminimark`.  The
+latter is a version that does major collections incrementally (i.e.  one
+major collection is split along some number of minor collections, rather
+than being done all at once after a specific minor collection).  The
+default is `incminimark`, as it seems to have a very minimal impact on
+performance and memory usage at the benefit of avoiding the long pauses
+of `minimark`.
+
 .. include:: _ref.txt

File pypy/doc/gc_info.rst

View file
  • Ignore whitespace
 Minimark
 --------
 
-PyPy's default ``minimark`` garbage collector is configurable through
+PyPy's default ``incminimark`` garbage collector is configurable through
 several environment variables:
 
 ``PYPY_GC_NURSERY``
     Defaults to 1/2 of your cache or ``4M``.
     Small values (like 1 or 1KB) are useful for debugging.
 
+``PYPY_GC_NURSERY_CLEANUP``
+    The interval at which nursery is cleaned up. Must
+    be smaller than the nursery size and bigger than the
+    biggest object we can allotate in the nursery.
+
+``PYPY_GC_INCREMENT_STEP``
+    The size of memory marked during the marking step.  Default is size of
+    nursery times 2. If you mark it too high your GC is not incremental at
+    all.  The minimum is set to size that survives minor collection times
+    1.5 so we reclaim anything all the time.
+
 ``PYPY_GC_MAJOR_COLLECT``
     Major collection memory factor.
     Default is ``1.82``, which means trigger a major collection when the

File pypy/doc/whatsnew-head.rst

View file
  • Ignore whitespace
 .. branch: remove-del-from-generatoriterator
 Speed up generators that don't yield inside try or wait blocks by skipping
 unnecessary cleanup.
+
+.. branch: annotator
+Remove FlowObjSpace.
+Improve cohesion between rpython.flowspace and rpython.annotator.

File pypy/interpreter/astcompiler/test/test_compiler.py

View file
  • Ignore whitespace
-import py
+import py, sys
 from pypy.interpreter.astcompiler import codegen, astbuilder, symtable, optimize
 from pypy.interpreter.pyparser import pyparse
 from pypy.interpreter.pyparser.test import expressions
 
 class AppTestCompiler:
 
+    def setup_class(cls):
+        cls.w_maxunicode = cls.space.wrap(sys.maxunicode)
+
     def test_docstring_not_loaded(self):
         import StringIO, dis, sys
         ns = {}
         l = [a for a in Foo()]
         assert hint_called[0]
         assert l == list(range(5))
-        
+
+    def test_unicode_in_source(self):
+        import sys
+        d = {}
+        exec '# -*- coding: utf-8 -*-\n\nu = u"\xf0\x9f\x92\x8b"' in d
+        if sys.maxunicode > 65535 and self.maxunicode > 65535:
+            expected_length = 1
+        else:
+            expected_length = 2
+        assert len(d['u']) == expected_length
+
 
 class TestOptimizations:
     def count_instructions(self, source):

File pypy/interpreter/baseobjspace.py

View file
  • Ignore whitespace
         """
         return self.unpackiterable(w_iterable, expected_length)
 
-    def listview_str(self, w_list):
+    def listview_bytes(self, w_list):
         """ Return a list of unwrapped strings out of a list of strings. If the
         argument is not a list or does not contain only strings, return None.
         May return None anyway.
         """
         return (None, None)
 
-    def newlist_str(self, list_s):
+    def newlist_bytes(self, list_s):
         return self.newlist([self.wrap(s) for s in list_s])
 
     def newlist_unicode(self, list_u):

File pypy/interpreter/pyframe.py

  • Ignore whitespace
File contents unchanged.

File pypy/interpreter/pyparser/parsestring.py

View file
  • Ignore whitespace
     Yes, it's very inefficient.
     Yes, CPython has very similar code.
     """
-
     # we use ps as "pointer to s"
     # q is the virtual last char index of the string
     ps = 0
     if unicode_literal: # XXX Py_UnicodeFlag is ignored for now
         if encoding is None or encoding == "iso-8859-1":
             # 'unicode_escape' expects latin-1 bytes, string is ready.
-            buf = s
-            bufp = ps
-            bufq = q
-            u = None
+            assert 0 <= ps <= q
+            substr = s[ps:q]
         else:
-            # String is utf8-encoded, but 'unicode_escape' expects
-            # latin-1; So multibyte sequences must be escaped.
-            lis = [] # using a list to assemble the value
-            end = q
-            # Worst case: "\XX" may become "\u005c\uHHLL" (12 bytes)
-            while ps < end:
-                if s[ps] == '\\':
-                    lis.append(s[ps])
-                    ps += 1
-                    if ord(s[ps]) & 0x80:
-                        # A multibyte sequence will follow, it will be
-                        # escaped like \u1234. To avoid confusion with
-                        # the backslash we just wrote, we emit "\u005c"
-                        # instead.
-                        lis.append("u005c")
-                if ord(s[ps]) & 0x80: # XXX inefficient
-                    w, ps = decode_utf8(space, s, ps, end, "utf-16-be")
-                    rn = len(w)
-                    assert rn % 2 == 0
-                    for i in range(0, rn, 2):
-                        lis.append('\\u')
-                        lis.append(hexbyte(ord(w[i])))
-                        lis.append(hexbyte(ord(w[i+1])))
-                else:
-                    lis.append(s[ps])
-                    ps += 1
-            buf = ''.join(lis)
-            bufp = 0
-            bufq = len(buf)
-        assert 0 <= bufp <= bufq
-        substr = buf[bufp:bufq]
+            substr = decode_unicode_utf8(space, s, ps, q)
         if rawmode:
             v = unicodehelper.decode_raw_unicode_escape(space, substr)
         else:
         result = "0" + result
     return result
 
+def decode_unicode_utf8(space, s, ps, q):
+    # ****The Python 2.7 version, producing UTF-32 escapes****
+    # String is utf8-encoded, but 'unicode_escape' expects
+    # latin-1; So multibyte sequences must be escaped.
+    lis = [] # using a list to assemble the value
+    end = q
+    # Worst case:
+    # "<92><195><164>" may become "\u005c\U000000E4" (16 bytes)
+    while ps < end:
+        if s[ps] == '\\':
+            lis.append(s[ps])
+            ps += 1
+            if ord(s[ps]) & 0x80:
+                # A multibyte sequence will follow, it will be
+                # escaped like \u1234. To avoid confusion with
+                # the backslash we just wrote, we emit "\u005c"
+                # instead.
+                lis.append("u005c")
+        if ord(s[ps]) & 0x80: # XXX inefficient
+            w, ps = decode_utf8(space, s, ps, end, "utf-32-be")
+            rn = len(w)
+            assert rn % 4 == 0
+            for i in range(0, rn, 4):
+                lis.append('\\U')
+                lis.append(hexbyte(ord(w[i])))
+                lis.append(hexbyte(ord(w[i+1])))
+                lis.append(hexbyte(ord(w[i+2])))
+                lis.append(hexbyte(ord(w[i+3])))
+        else:
+            lis.append(s[ps])
+            ps += 1
+    return ''.join(lis)
+
 def PyString_DecodeEscape(space, s, recode_encoding):
     """
     Unescape a backslash-escaped string. If recode_encoding is non-zero,

File pypy/interpreter/pyparser/test/test_parsestring.py

View file
  • Ignore whitespace
 from pypy.interpreter.pyparser import parsestring
-import py
+import py, sys
 
 class TestParsetring:
     def parse_and_compare(self, literal, value):
         input = ["'", 'x', ' ', chr(0xc3), chr(0xa9), ' ', chr(92), 'n', "'"]
         w_ret = parsestring.parsestr(space, 'utf8', ''.join(input))
         assert space.str_w(w_ret) == ''.join(expected)
+
+    def test_wide_unicode_in_source(self):
+        if sys.maxunicode == 65535:
+            py.test.skip("requires a wide-unicode host")
+        self.parse_and_compare('u"\xf0\x9f\x92\x8b"',
+                               unichr(0x1f48b),
+                               encoding='utf-8')
+
+    def test_decode_unicode_utf8(self):
+        buf = parsestring.decode_unicode_utf8(self.space,
+                                              'u"\xf0\x9f\x92\x8b"', 2, 6)
+        if sys.maxunicode == 65535:
+            assert buf == r"\U0000d83d\U0000dc8b"
+        else:
+            assert buf == r"\U0001f48b"

File pypy/module/__builtin__/test/test_classobj.py

View file
  • Ignore whitespace
         assert (D() >= A()) == 'D:A.ge'
 
 
-class AppTestOldStyleClassStrDict(object):
+class AppTestOldStyleClassBytesDict(object):
     def setup_class(cls):
         if cls.runappdirect:
             py.test.skip("can only be run on py.py")
         def is_strdict(space, w_class):
-            from pypy.objspace.std.dictmultiobject import StringDictStrategy
+            from pypy.objspace.std.dictmultiobject import BytesDictStrategy
             w_d = w_class.getdict(space)
-            return space.wrap(isinstance(w_d.strategy, StringDictStrategy))
+            return space.wrap(isinstance(w_d.strategy, BytesDictStrategy))
 
         cls.w_is_strdict = cls.space.wrap(gateway.interp2app(is_strdict))
 

File pypy/module/__pypy__/test/test_special.py

View file
  • Ignore whitespace
         l = [1, 2, 3]
         assert list_strategy(l) == "int"
         l = ["a", "b", "c"]
-        assert list_strategy(l) == "str"
+        assert list_strategy(l) == "bytes"
+        l = [u"a", u"b", u"c"]
+        assert list_strategy(l) == "unicode"
         l = [1.1, 2.2, 3.3]
         assert list_strategy(l) == "float"
         l = range(3)

File pypy/module/_cffi_backend/ctypestruct.py

View file
  • Ignore whitespace
         if self.fields_dict is None:
             space = self.space
             raise operationerrfmt(w_errorcls or space.w_TypeError,
-                                  "'%s' is not completed yet", self.name)
+                              "'%s' is opaque or not completed yet", self.name)
 
     def _alignof(self):
         self.check_complete(w_errorcls=self.space.w_ValueError)

File pypy/module/_rawffi/test/test__rawffi.py

View file
  • Ignore whitespace
 from rpython.translator.platform import platform
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.conftest import option
 from pypy.module._rawffi.interp_rawffi import TYPEMAP, TYPEMAP_FLOAT_LETTERS
 from pypy.module._rawffi.tracker import Tracker
 
     def setup_class(cls):
         cls.w_sizes_and_alignments = cls.space.wrap(dict(
             [(k, (v.c_size, v.c_alignment)) for k,v in TYPEMAP.iteritems()]))
-        #
-        # detect if we're running on PyPy with DO_TRACING not compiled in
-        if option.runappdirect:
-            try:
-                import _rawffi
-                _rawffi._num_of_allocated_objects()
-            except (ImportError, RuntimeError), e:
-                py.test.skip(str(e))
-        #
         Tracker.DO_TRACING = True
 
     def test_structure_autofree(self):

File pypy/module/cpyext/api.py

View file
  • Ignore whitespace
     else:
         prefix = 'cpyexttest'
     init_buffer = rffi.llexternal('_%s_init_bufferobject' % prefix, [], lltype.Void,
-                                  compilation_info=eci, _nowrapper=True)
+                                  compilation_info=eci, releasegil=False)
     init_pycobject = rffi.llexternal('_%s_init_pycobject' % prefix, [], lltype.Void,
-                                     compilation_info=eci, _nowrapper=True)
+                                     compilation_info=eci, releasegil=False)
     init_capsule = rffi.llexternal('_%s_init_capsule' % prefix, [], lltype.Void,
-                                   compilation_info=eci, _nowrapper=True)
+                                   compilation_info=eci, releasegil=False)
     INIT_FUNCTIONS.extend([
         lambda space: init_buffer(),
         lambda space: init_pycobject(),

File pypy/module/cpyext/test/test_cpyext.py

View file
  • Ignore whitespace
             Build an extension module linked against the cpyext api library.
             """
             if not space.is_none(w_separate_module_files):
-                separate_module_files = space.listview_str(w_separate_module_files)
+                separate_module_files = space.listview_bytes(
+                    w_separate_module_files)
                 assert separate_module_files is not None
             else:
                 separate_module_files = []
             if not space.is_none(w_separate_module_sources):
-                separate_module_sources = space.listview_str(w_separate_module_sources)
+                separate_module_sources = space.listview_bytes(
+                    w_separate_module_sources)
                 assert separate_module_sources is not None
             else:
                 separate_module_sources = []

File pypy/module/itertools/interp_itertools.py

View file
  • Ignore whitespace
 class W_Product(W_Root):
     def __init__(self, space, args_w, w_repeat):
         self.gears = [
-            space.fixedview(arg_w) for arg_w in args_w
+            space.unpackiterable(arg_w) for arg_w in args_w
         ] * space.int_w(w_repeat)
-        self.num_gears = len(self.gears)
-        # initialization of indicies to loop over
-        self.indicies = [
-            (0, len(gear))
-            for gear in self.gears
-        ]
-        self.cont = True
-        for _, lim in self.indicies:
-            if lim <= 0:
-                self.cont = False
+        #
+        for gear in self.gears:
+            if len(gear) == 0:
+                self.lst = None
                 break
+        else:
+            self.indices = [0] * len(self.gears)
+            self.lst = [gear[0] for gear in self.gears]
 
-    def roll_gears(self):
-        if self.num_gears == 0:
-            self.cont = False
-            return
+    def _rotate_previous_gears(self):
+        lst = self.lst
+        x = len(self.gears) - 1
+        lst[x] = self.gears[x][0]
+        self.indices[x] = 0
+        x -= 1
+        # the outer loop runs as long as a we have a carry
+        while x >= 0:
+            gear = self.gears[x]
+            index = self.indices[x] + 1
+            if index < len(gear):
+                # no carry: done
+                lst[x] = gear[index]
+                self.indices[x] = index
+                return
+            lst[x] = gear[0]
+            self.indices[x] = 0
+            x -= 1
+        else:
+            self.lst = None
 
-        # Starting from the end of the gear indicies work to the front
-        # incrementing the gear until the limit is reached. When the limit
-        # is reached carry operation to the next gear
-        should_carry = True
-
-        for n in range(0, self.num_gears):
-            nth_gear = self.num_gears - n - 1
-            if should_carry:
-                count, lim = self.indicies[nth_gear]
-                count += 1
-                if count == lim and nth_gear == 0:
-                    self.cont = False
-                if count == lim:
-                    should_carry = True
-                    count = 0
-                else:
-                    should_carry = False
-                self.indicies[nth_gear] = (count, lim)
+    def fill_next_result(self):
+        # the last gear is done here, in a function with no loop,
+        # to allow the JIT to look inside
+        lst = self.lst
+        x = len(self.gears) - 1
+        if x >= 0:
+            gear = self.gears[x]
+            index = self.indices[x] + 1
+            if index < len(gear):
+                # no carry: done
+                lst[x] = gear[index]
+                self.indices[x] = index
             else:
-                break
+                self._rotate_previous_gears()
+        else:
+            self.lst = None
 
     def iter_w(self, space):
         return space.wrap(self)
 
     def next_w(self, space):
-        if not self.cont:
+        if self.lst is None:
             raise OperationError(space.w_StopIteration, space.w_None)
-        l = [None] * self.num_gears
-        for x in range(0, self.num_gears):
-            index, limit = self.indicies[x]
-            l[x] = self.gears[x][index]
-        self.roll_gears()
-        return space.newtuple(l)
+        w_result = space.newtuple(self.lst[:])
+        self.fill_next_result()
+        return w_result
 
 
 def W_Product__new__(space, w_subtype, __args__):

File pypy/module/itertools/test/test_itertools.py

View file
  • Ignore whitespace
         assert prod.next() == ()
         raises (StopIteration, prod.next)
 
+    def test_product_powers_of_two(self):
+        from itertools import product
+        assert list(product()) == [()]
+        assert list(product('ab')) == [('a',), ('b',)]
+        assert list(product('ab', 'cd')) == [
+            ('a', 'c'), ('a', 'd'),
+            ('b', 'c'), ('b', 'd')]
+        assert list(product('ab', 'cd', 'ef')) == [
+            ('a', 'c', 'e'), ('a', 'c', 'f'),
+            ('a', 'd', 'e'), ('a', 'd', 'f'),
+            ('b', 'c', 'e'), ('b', 'c', 'f'),
+            ('b', 'd', 'e'), ('b', 'd', 'f')]
+
+    def test_product_empty_item(self):
+        from itertools import product
+        assert list(product('')) == []
+        assert list(product('ab', '')) == []
+        assert list(product('', 'cd')) == []
+        assert list(product('ab', 'cd', '')) == []
+        assert list(product('ab', '', 'ef')) == []
+        assert list(product('', 'cd', 'ef')) == []
+
     def test_permutations(self):
         from itertools import permutations
         assert list(permutations('AB')) == [('A', 'B'), ('B', 'A')]

File pypy/module/struct/__init__.py

View file
  • Ignore whitespace
         'calcsize': 'interp_struct.calcsize',
         'pack': 'interp_struct.pack',
         'unpack': 'interp_struct.unpack',
-        }
+
+        'Struct': 'interp_struct.W_Struct',
+    }
 
     appleveldefs = {
         'error': 'app_struct.error',
         'pack_into': 'app_struct.pack_into',
         'unpack_from': 'app_struct.unpack_from',
-        'Struct': 'app_struct.Struct',
-        }
+    }

File pypy/module/struct/app_struct.py

View file
  • Ignore whitespace
 """
 import struct
 
+
 class error(Exception):
     """Exception raised on various occasions; argument is a string
     describing what is wrong."""
         raise error("unpack_from requires a buffer of at least %d bytes"
                     % (size,))
     return struct.unpack(fmt, data)
-
-# XXX inefficient
-class Struct(object):
-    def __init__(self, format):
-        self.format = format
-        self.size = struct.calcsize(format)
-
-    def pack(self, *args):
-        return struct.pack(self.format, *args)
-
-    def unpack(self, s):
-        return struct.unpack(self.format, s)
-
-    def pack_into(self, buffer, offset, *args):
-        return pack_into(self.format, buffer, offset, *args)
-
-    def unpack_from(self, buffer, offset=0):
-        return unpack_from(self.format, buffer, offset)

File pypy/module/struct/interp_struct.py

View file
  • Ignore whitespace
-from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import OperationError
-from pypy.module.struct.formatiterator import PackFormatIterator, UnpackFormatIterator
 from rpython.rlib import jit
 from rpython.rlib.rstruct.error import StructError, StructOverflowError
 from rpython.rlib.rstruct.formatiterator import CalcSizeFormatIterator
+from rpython.tool.sourcetools import func_with_new_name
+
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.typedef import TypeDef, interp_attrproperty
+from pypy.module.struct.formatiterator import (
+    PackFormatIterator, UnpackFormatIterator
+)
 
 
 @unwrap_spec(format=str)
 def calcsize(space, format):
     return space.wrap(_calcsize(space, format))
 
+
 def _calcsize(space, format):
     fmtiter = CalcSizeFormatIterator()
     try:
         w_error = space.getattr(w_module, space.wrap('error'))
         raise OperationError(w_error, space.wrap(e.msg))
     return space.newtuple(fmtiter.result_w[:])
+
+
+class W_Struct(W_Root):
+    _immutable_fields_ = ["format", "size"]
+
+    def __init__(self, space, format):
+        self.format = format
+        self.size = _calcsize(space, format)
+
+    @unwrap_spec(format=str)
+    def descr__new__(space, w_subtype, format):
+        self = space.allocate_instance(W_Struct, w_subtype)
+        W_Struct.__init__(self, space, format)
+        return self
+
+    def wrap_struct_method(name):
+        def impl(self, space, __args__):
+            w_module = space.getbuiltinmodule('struct')
+            w_method = space.getattr(w_module, space.wrap(name))
+            return space.call_obj_args(
+                w_method, space.wrap(self.format), __args__
+            )
+
+        return func_with_new_name(impl, 'descr_' + name)
+
+    descr_pack = wrap_struct_method("pack")
+    descr_unpack = wrap_struct_method("unpack")
+    descr_pack_into = wrap_struct_method("pack_into")
+    descr_unpack_from = wrap_struct_method("unpack_from")
+
+
+W_Struct.typedef = TypeDef("Struct",
+    __new__=interp2app(W_Struct.descr__new__.im_func),
+    format=interp_attrproperty("format", cls=W_Struct),
+    size=interp_attrproperty("size", cls=W_Struct),
+
+    pack=interp2app(W_Struct.descr_pack),
+    unpack=interp2app(W_Struct.descr_unpack),
+    pack_into=interp2app(W_Struct.descr_pack_into),
+    unpack_from=interp2app(W_Struct.descr_unpack_from),
+)

File pypy/objspace/std/bytesobject.py

View file
  • Ignore whitespace
     def str_w(self, space):
         return self._value
 
-    def listview_str(self):
-        return _create_list_from_string(self._value)
+    def listview_bytes(self):
+        return _create_list_from_bytes(self._value)
 
     def ord(self, space):
         if len(self._value) != 1:
     _title = _upper
 
     def _newlist_unwrapped(self, space, lst):
-        return space.newlist_str(lst)
+        return space.newlist_bytes(lst)
 
     @staticmethod
     @unwrap_spec(w_object = WrappedDefault(""))
         return tformat.formatter_field_name_split()
 
 
-def _create_list_from_string(value):
+def _create_list_from_bytes(value):
     # need this helper function to allow the jit to look inside and inline
-    # listview_str
+    # listview_bytes
     return [s for s in value]
 
 W_BytesObject.EMPTY = W_BytesObject('')

File pypy/objspace/std/celldict.py

View file
  • Ignore whitespace
     def w_keys(self, w_dict):
         space = self.space
         l = self.unerase(w_dict.dstorage).keys()
-        return space.newlist_str(l)
+        return space.newlist_bytes(l)
 
     def values(self, w_dict):
         iterator = self.unerase(w_dict.dstorage).itervalues

File pypy/objspace/std/dictmultiobject.py

View file
  • Ignore whitespace
             strategy = space.fromcache(MapDictStrategy)
         elif instance or strdict or module:
             assert w_type is None
-            strategy = space.fromcache(StringDictStrategy)
+            strategy = space.fromcache(BytesDictStrategy)
         elif kwargs:
             assert w_type is None
             from pypy.objspace.std.kwargsdict import EmptyKwargsDictStrategy
         if space.is_w(w_type, space.w_dict):
             w_dict = W_DictMultiObject.allocate_and_init_instance(space, w_type)
 
-            strlist = space.listview_str(w_keys)
-            if strlist is not None:
-                for key in strlist:
+            byteslist = space.listview_bytes(w_keys)
+            if byteslist is not None:
+                for key in byteslist:
                     w_dict.setitem_str(key, w_fill)
             else:
                 for w_key in space.listview(w_keys):
                     popitem delitem clear \
                     length w_keys values items \
                     iterkeys itervalues iteritems \
-                    listview_str listview_unicode listview_int \
+                    listview_bytes listview_unicode listview_int \
                     view_as_kwargs".split()
 
     def make_method(method):
         w_dict.strategy = strategy
         w_dict.dstorage = storage
 
-    def listview_str(self, w_dict):
+    def listview_bytes(self, w_dict):
         return None
 
     def listview_unicode(self, w_dict):
     def switch_to_correct_strategy(self, w_dict, w_key):
         withidentitydict = self.space.config.objspace.std.withidentitydict
         if type(w_key) is self.space.StringObjectCls:
-            self.switch_to_string_strategy(w_dict)
+            self.switch_to_bytes_strategy(w_dict)
             return
         elif type(w_key) is self.space.UnicodeObjectCls:
             self.switch_to_unicode_strategy(w_dict)
         else:
             self.switch_to_object_strategy(w_dict)
 
-    def switch_to_string_strategy(self, w_dict):
-        strategy = self.space.fromcache(StringDictStrategy)
+    def switch_to_bytes_strategy(self, w_dict):
+        strategy = self.space.fromcache(BytesDictStrategy)
         storage = strategy.get_empty_storage()
         w_dict.strategy = strategy
         w_dict.dstorage = storage
         w_dict.setitem(w_key, w_value)
 
     def setitem_str(self, w_dict, key, w_value):
-        self.switch_to_string_strategy(w_dict)
+        self.switch_to_bytes_strategy(w_dict)
         w_dict.setitem_str(key, w_value)
 
     def delitem(self, w_dict, w_key):
 create_iterator_classes(ObjectDictStrategy)
 
 
-class StringDictStrategy(AbstractTypedStrategy, DictStrategy):
-    erase, unerase = rerased.new_erasing_pair("string")
+class BytesDictStrategy(AbstractTypedStrategy, DictStrategy):
+    erase, unerase = rerased.new_erasing_pair("bytes")
     erase = staticmethod(erase)
     unerase = staticmethod(unerase)
 
         assert key is not None
         return self.unerase(w_dict.dstorage).get(key, None)
 
-    def listview_str(self, w_dict):
+    def listview_bytes(self, w_dict):
         return self.unerase(w_dict.dstorage).keys()
 
     def w_keys(self, w_dict):
-        return self.space.newlist_str(self.listview_str(w_dict))
+        return self.space.newlist_bytes(self.listview_bytes(w_dict))
 
     def wrapkey(space, key):
         return space.wrap(key)
             i += 1
         return keys, values
 
-create_iterator_classes(StringDictStrategy)
+create_iterator_classes(BytesDictStrategy)
 
 
 class UnicodeDictStrategy(AbstractTypedStrategy, DictStrategy):
     def _never_equal_to(self, w_lookup_type):
         return _never_equal_to_string(self.space, w_lookup_type)
 
-    # we should implement the same shortcuts as we do for StringDictStrategy
+    # we should implement the same shortcuts as we do for BytesDictStrategy
 
     ## def setitem_str(self, w_dict, key, w_value):
     ##     assert key is not None
         return self.unerase(w_dict.dstorage).keys()
 
     ## def w_keys(self, w_dict):
-    ##     return self.space.newlist_str(self.listview_str(w_dict))
+    ##     return self.space.newlist_bytes(self.listview_bytes(w_dict))
 
     def wrapkey(space, key):
         return space.wrap(key)

File pypy/objspace/std/dictproxyobject.py

View file
  • Ignore whitespace
 
     def w_keys(self, w_dict):
         space = self.space
-        return space.newlist_str(self.unerase(w_dict.dstorage).dict_w.keys())
+        return space.newlist_bytes(self.unerase(w_dict.dstorage).dict_w.keys())
 
     def values(self, w_dict):
         return [unwrap_cell(self.space, w_value) for w_value in self.unerase(w_dict.dstorage).dict_w.itervalues()]

File pypy/objspace/std/kwargsdict.py

View file
  • Ignore whitespace
 ## dict strategy (see dictmultiobject.py)
 
 from rpython.rlib import rerased, jit
-from pypy.objspace.std.dictmultiobject import (DictStrategy,
-                                               create_iterator_classes,
-                                               EmptyDictStrategy,
-                                               ObjectDictStrategy,
-                                               StringDictStrategy)
+from pypy.objspace.std.dictmultiobject import (
+    BytesDictStrategy, DictStrategy, EmptyDictStrategy, ObjectDictStrategy,
+    create_iterator_classes)
 
 
 class EmptyKwargsDictStrategy(EmptyDictStrategy):
-    def switch_to_string_strategy(self, w_dict):
+    def switch_to_bytes_strategy(self, w_dict):
         strategy = self.space.fromcache(KwargsDictStrategy)
         storage = strategy.get_empty_storage()
         w_dict.strategy = strategy
         else:
             # limit the size so that the linear searches don't become too long
             if len(keys) >= 16:
-                self.switch_to_string_strategy(w_dict)
+                self.switch_to_bytes_strategy(w_dict)
                 w_dict.setitem_str(key, w_value)
             else:
                 keys.append(key)
 
     def w_keys(self, w_dict):
         l = self.unerase(w_dict.dstorage)[0]
-        return self.space.newlist_str(l[:])
+        return self.space.newlist_bytes(l[:])
 
     def values(self, w_dict):
         return self.unerase(w_dict.dstorage)[1][:] # to make non-resizable
         w_dict.strategy = strategy
         w_dict.dstorage = strategy.erase(d_new)
 
-    def switch_to_string_strategy(self, w_dict):
-        strategy = self.space.fromcache(StringDictStrategy)
+    def switch_to_bytes_strategy(self, w_dict):
+        strategy = self.space.fromcache(BytesDictStrategy)
         keys, values_w = self.unerase(w_dict.dstorage)
         storage = strategy.get_empty_storage()
         d_new = strategy.unerase(storage)

File pypy/objspace/std/listobject.py

View file
  • Ignore whitespace
         if not type(w_obj) is W_BytesObject:
             break
     else:
-        return space.fromcache(StringListStrategy)
+        return space.fromcache(BytesListStrategy)
 
     # check for unicode
     for w_obj in list_w:
         return self
 
     @staticmethod
-    def newlist_str(space, list_s):
-        strategy = space.fromcache(StringListStrategy)
+    def newlist_bytes(space, list_s):
+        strategy = space.fromcache(BytesListStrategy)
         storage = strategy.erase(list_s)
         return W_ListObject.from_storage_and_strategy(space, storage, strategy)
 
         ObjectListStrategy."""
         return self.strategy.getitems_copy(self)
 
-    def getitems_str(self):
+    def getitems_bytes(self):
         """Return the items in the list as unwrapped strings. If the list does
         not use the list strategy, return None."""
-        return self.strategy.getitems_str(self)
+        return self.strategy.getitems_bytes(self)
 
     def getitems_unicode(self):
         """Return the items in the list as unwrapped unicodes. If the list does
     def getitems_copy(self, w_list):
         raise NotImplementedError
 
-    def getitems_str(self, w_list):
+    def getitems_bytes(self, w_list):
         return None
 
     def getitems_unicode(self, w_list):
         if type(w_item) is W_IntObject:
             strategy = self.space.fromcache(IntegerListStrategy)
         elif type(w_item) is W_BytesObject:
-            strategy = self.space.fromcache(StringListStrategy)
+            strategy = self.space.fromcache(BytesListStrategy)
         elif type(w_item) is W_UnicodeObject:
             strategy = self.space.fromcache(UnicodeListStrategy)
         elif type(w_item) is W_FloatObject:
             w_list.lstorage = strategy.erase(floatlist)
             return
 
-        strlist = space.listview_str(w_iterable)
-        if strlist is not None:
-            w_list.strategy = strategy = space.fromcache(StringListStrategy)
+        byteslist = space.listview_bytes(w_iterable)
+        if byteslist is not None:
+            w_list.strategy = strategy = space.fromcache(BytesListStrategy)
             # need to copy because intlist can share with w_iterable
-            w_list.lstorage = strategy.erase(strlist[:])
+            w_list.lstorage = strategy.erase(byteslist[:])
             return
 
         unilist = space.listview_unicode(w_iterable)
         return self.unerase(w_list.lstorage)
 
 
-class StringListStrategy(ListStrategy):
+class BytesListStrategy(ListStrategy):
     import_from_mixin(AbstractUnwrappedStrategy)
 
     _none_value = None
-    _applevel_repr = "str"
+    _applevel_repr = "bytes"
 
     def wrap(self, stringval):
         return self.space.wrap(stringval)
     def unwrap(self, w_string):
         return self.space.str_w(w_string)
 
-    erase, unerase = rerased.new_erasing_pair("string")
+    erase, unerase = rerased.new_erasing_pair("bytes")
     erase = staticmethod(erase)
     unerase = staticmethod(unerase)
 
         return type(w_obj) is W_BytesObject
 
     def list_is_correct_type(self, w_list):
-        return w_list.strategy is self.space.fromcache(StringListStrategy)
+        return w_list.strategy is self.space.fromcache(BytesListStrategy)
 
     def sort(self, w_list, reverse):
         l = self.unerase(w_list.lstorage)
         if reverse:
             l.reverse()
 
-    def getitems_str(self, w_list):
+    def getitems_bytes(self, w_list):
         return self.unerase(w_list.lstorage)
 
 

File pypy/objspace/std/mapdict.py

View file
  • Ignore whitespace
         self.delitem(w_dict, w_key)
         return (w_key, w_value)
 
-    # XXX could implement a more efficient w_keys based on space.newlist_str
+    # XXX could implement a more efficient w_keys based on space.newlist_bytes
 
     def iterkeys(self, w_dict):
         return MapDictIteratorKeys(self.space, self, w_dict)

File pypy/objspace/std/objspace.py

View file
  • Ignore whitespace
         assert not list_w or sizehint == -1
         return W_ListObject(self, list_w, sizehint)
 
-    def newlist_str(self, list_s):
-        return W_ListObject.newlist_str(self, list_s)
+    def newlist_bytes(self, list_s):
+        return W_ListObject.newlist_bytes(self, list_s)
 
     def newlist_unicode(self, list_u):
         return W_ListObject.newlist_unicode(self, list_u)
             raise self._wrap_expected_length(expected_length, len(t))
         return t
 
-    def listview_str(self, w_obj):
+    def listview_bytes(self, w_obj):
         # note: uses exact type checking for objects with strategies,
         # and isinstance() for others.  See test_listobject.test_uses_custom...
         if type(w_obj) is W_ListObject:
-            return w_obj.getitems_str()
+            return w_obj.getitems_bytes()
         if type(w_obj) is W_DictMultiObject:
-            return w_obj.listview_str()
+            return w_obj.listview_bytes()
         if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
-            return w_obj.listview_str()
+            return w_obj.listview_bytes()
         if isinstance(w_obj, W_BytesObject) and self._uses_no_iter(w_obj):
-            return w_obj.listview_str()
+            return w_obj.listview_bytes()
         if isinstance(w_obj, W_ListObject) and self._uses_list_iter(w_obj):
-            return w_obj.getitems_str()
+            return w_obj.getitems_bytes()
         return None
 
     def listview_unicode(self, w_obj):

File pypy/objspace/std/setobject.py

View file
  • Ignore whitespace
         """ Returns a dict with all elements of the set. Needed only for switching to ObjectSetStrategy. """
         return self.strategy.getdict_w(self)
 
-    def listview_str(self):
+    def listview_bytes(self):
         """ If this is a string set return its contents as a list of uwnrapped strings. Otherwise return None. """
-        return self.strategy.listview_str(self)
+        return self.strategy.listview_bytes(self)
 
     def listview_unicode(self):
         """ If this is a unicode set return its contents as a list of uwnrapped unicodes. Otherwise return None. """
         """ Returns an empty storage (erased) object. Used to initialize an empty set."""
         raise NotImplementedError
 
-    def listview_str(self, w_set):
+    def listview_bytes(self, w_set):
         return None
 
     def listview_unicode(self, w_set):
         if type(w_key) is W_IntObject:
             strategy = self.space.fromcache(IntegerSetStrategy)
         elif type(w_key) is W_BytesObject:
-            strategy = self.space.fromcache(StringSetStrategy)
+            strategy = self.space.fromcache(BytesSetStrategy)
         elif type(w_key) is W_UnicodeObject:
             strategy = self.space.fromcache(UnicodeSetStrategy)
         elif self.space.type(w_key).compares_by_identity():
         return self.wrap(result[0])
 
 
-class StringSetStrategy(AbstractUnwrappedSetStrategy, SetStrategy):
-    erase, unerase = rerased.new_erasing_pair("string")
+class BytesSetStrategy(AbstractUnwrappedSetStrategy, SetStrategy):
+    erase, unerase = rerased.new_erasing_pair("bytes")
     erase = staticmethod(erase)
     unerase = staticmethod(unerase)
 
     def get_empty_dict(self):
         return {}
 
-    def listview_str(self, w_set):
+    def listview_bytes(self, w_set):
         return self.unerase(w_set.sstorage).keys()
 
     def is_correct_type(self, w_key):
         return self.space.wrap(item)
 
     def iter(self, w_set):
-        return StringIteratorImplementation(self.space, self, w_set)
+        return BytesIteratorImplementation(self.space, self, w_set)
 
 
 class UnicodeSetStrategy(AbstractUnwrappedSetStrategy, SetStrategy):
         return type(w_key) is W_IntObject
 
     def may_contain_equal_elements(self, strategy):
-        if strategy is self.space.fromcache(StringSetStrategy):
+        if strategy is self.space.fromcache(BytesSetStrategy):
             return False
         elif strategy is self.space.fromcache(UnicodeSetStrategy):
             return False
             return False
         if strategy is self.space.fromcache(IntegerSetStrategy):
             return False
-        if strategy is self.space.fromcache(StringSetStrategy):
+        if strategy is self.space.fromcache(BytesSetStrategy):
             return False
         if strategy is self.space.fromcache(UnicodeSetStrategy):
             return False
         return None
 
 
-class StringIteratorImplementation(IteratorImplementation):
+class BytesIteratorImplementation(IteratorImplementation):
     def __init__(self, space, strategy, w_set):
         IteratorImplementation.__init__(self, space, strategy, w_set)
         d = strategy.unerase(w_set.sstorage)
         w_set.sstorage = w_iterable.get_storage_copy()
         return
 
-    stringlist = space.listview_str(w_iterable)
-    if stringlist is not None:
-        strategy = space.fromcache(StringSetStrategy)
+    byteslist = space.listview_bytes(w_iterable)
+    if byteslist is not None:
+        strategy = space.fromcache(BytesSetStrategy)
         w_set.strategy = strategy
-        w_set.sstorage = strategy.get_storage_from_unwrapped_list(stringlist)
+        w_set.sstorage = strategy.get_storage_from_unwrapped_list(byteslist)
         return
 
     unicodelist = space.listview_unicode(w_iterable)
         if type(w_item) is not W_BytesObject:
             break
     else:
-        w_set.strategy = space.fromcache(StringSetStrategy)
+        w_set.strategy = space.fromcache(BytesSetStrategy)
         w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)
         return
 

File pypy/objspace/std/stringmethods.py

View file
  • Ignore whitespace
         if (isinstance(self, W_BytearrayObject) and
             space.isinstance_w(w_sub, space.w_int)):
             char = space.int_w(w_sub)
-            if not 0 <= char < 256:
-                raise OperationError(space.w_ValueError,
-                                     space.wrap("byte must be in range(0, 256)"))
-            for c in self.data:
-                if ord(c) == char:
-                    return space.w_True
-            return space.w_False
+            return _descr_contains_bytearray(self.data, space, char)
         return space.newbool(self._val(space).find(self._op_val(space, w_sub)) >= 0)
 
     def descr_add(self, space, w_other):
                 assert start >= 0 and stop >= 0
                 return self._sliced(space, selfvalue, start, stop, self)
             else:
-                ret = [selfvalue[start + i*step] for i in range(sl)]
+                ret = _descr_getslice_slowpath(selfvalue, start, step, sl)
                 return self._new_from_list(ret)
 
         index = space.getindex_w(w_index, space.w_IndexError, "string index")
         return self._is_generic(space, '_isdigit')
 
     # this is only for bytes and bytesarray: unicodeobject overrides it
+    def _descr_islower_slowpath(self, space, v):
+        cased = False
+        for idx in range(len(v)):
+            if self._isupper(v[idx]):
+                return False
+            elif not cased and self._islower(v[idx]):
+                cased = True
+        return cased
+
     def descr_islower(self, space):
         v = self._val(space)
         if len(v) == 1:
             c = v[0]
             return space.newbool(self._islower(c))
-        cased = False
-        for idx in range(len(v)):
-            if self._isupper(v[idx]):
-                return space.w_False
-            elif not cased and self._islower(v[idx]):
-                cased = True
+        cased = self._descr_islower_slowpath(space, v)
         return space.newbool(cased)
 
     def descr_isspace(self, space):
         return space.newbool(cased)
 
     # this is only for bytes and bytesarray: unicodeobject overrides it
+    def _descr_isupper_slowpath(self, space, v):
+        cased = False
+        for idx in range(len(v)):
+            if self._islower(v[idx]):
+                return False
+            elif not cased and self._isupper(v[idx]):
+                cased = True
+        return cased
+
     def descr_isupper(self, space):
         v = self._val(space)
         if len(v) == 1:
             c = v[0]
             return space.newbool(self._isupper(c))
-        cased = False
-        for idx in range(len(v)):
-            if self._islower(v[idx]):
-                return space.w_False
-            elif not cased and self._isupper(v[idx]):
-                cased = True
+        cased = self._descr_isupper_slowpath(space, v)
         return space.newbool(cased)
 
     def descr_join(self, space, w_list):
         from pypy.objspace.std.unicodeobject import W_UnicodeObject
 
         if isinstance(self, W_BytesObject):
-            l = space.listview_str(w_list)
+            l = space.listview_bytes(w_list)
             if l is not None:
                 if len(l) == 1:
                     return space.wrap(l[0])
 
     def descr_getnewargs(self, space):
         return space.newtuple([self._new(self._val(space))])
+
+# ____________________________________________________________
+# helpers for slow paths, moved out because they contain loops
+
+def _descr_contains_bytearray(data, space, char):
+    if not 0 <= char < 256:
+        raise OperationError(space.w_ValueError,
+                             space.wrap("byte must be in range(0, 256)"))
+    for c in data:
+        if ord(c) == char:
+            return space.w_True
+    return space.w_False
+
+@specialize.argtype(0)
+def _descr_getslice_slowpath(selfvalue, start, step, sl):
+    return [selfvalue[start + i*step] for i in range(sl)]

File pypy/objspace/std/test/test_bytesobject.py

View file
  • Ignore whitespace
         w_slice = space.newslice(w(1), w_None, w(2))
         assert self.space.eq_w(space.getitem(w_str, w_slice), w('el'))
 
-    def test_listview_str(self):
+    def test_listview_bytes(self):
         w_str = self.space.wrap('abcd')
-        assert self.space.listview_str(w_str) == list("abcd")
+        assert self.space.listview_bytes(w_str) == list("abcd")
 
 class AppTestBytesObject:
 

File pypy/objspace/std/test/test_dictmultiobject.py

View file
  • Ignore whitespace
 import py
 
 from pypy.objspace.std.dictmultiobject import (W_DictMultiObject,
-    StringDictStrategy, ObjectDictStrategy)
+    BytesDictStrategy, ObjectDictStrategy)
 
 
 class TestW_DictObject(object):
         assert space.eq_w(w_d.getitem_str("a"), space.w_None)
         assert space.eq_w(w_d.getitem_str("b"), space.w_None)
 
-    def test_listview_str_dict(self):
+    def test_listview_bytes_dict(self):
         w = self.space.wrap
         w_d = self.space.newdict()
         w_d.initialize_content([(w("a"), w(1)), (w("b"), w(2))])
-        assert self.space.listview_str(w_d) == ["a", "b"]
+        assert self.space.listview_bytes(w_d) == ["a", "b"]
 
     def test_listview_unicode_dict(self):
         w = self.space.wrap
         w_l = self.space.call_method(w_d, "keys")
         assert sorted(self.space.listview_int(w_l)) == [1,2]
         
-        # make sure that .keys() calls newlist_str for string dicts
+        # make sure that .keys() calls newlist_bytes for string dicts
         def not_allowed(*args):
             assert False, 'should not be called'
         monkeypatch.setattr(self.space, 'newlist', not_allowed)
         w_d = self.space.newdict()
         w_d.initialize_content([(w("a"), w(1)), (w("b"), w(6))])
         w_l = self.space.call_method(w_d, "keys")
-        assert sorted(self.space.listview_str(w_l)) == ["a", "b"]
+        assert sorted(self.space.listview_bytes(w_l)) == ["a", "b"]
 
         # XXX: it would be nice if the test passed without monkeypatch.undo(),
         # but we need space.newlist_unicode for it
         d = {}
         assert "EmptyDictStrategy" in self.get_strategy(d)
         d["a"] = 1
-        assert "StringDictStrategy" in self.get_strategy(d)
+        assert "BytesDictStrategy" in self.get_strategy(d)
 
         class O(object):
             pass
         d = o.__dict__ = {}
         assert "EmptyDictStrategy" in self.get_strategy(d)
         o.a = 1
-        assert "StringDictStrategy" in self.get_strategy(d)
+        assert "BytesDictStrategy" in self.get_strategy(d)
 
     def test_empty_to_unicode(self):
         d = {}
     eq_w = eq
     def newlist(self, l):
         return l
-    def newlist_str(self, l):
+    def newlist_bytes(self, l):
         return l
     DictObjectCls = W_DictMultiObject
     def type(self, w_obj):
         assert "s" not in d.w_keys()
         assert F() not in d.w_keys()
 
-class TestStrDictImplementation(BaseTestRDictImplementation):
-    StrategyClass = StringDictStrategy
-    #ImplementionClass = StrDictImplementation
+class TestBytesDictImplementation(BaseTestRDictImplementation):
+    StrategyClass = BytesDictStrategy
+    #ImplementionClass = BytesDictImplementation
 
     def test_str_shortcut(self):
         self.fill_impl()
     def check_not_devolved(self):
         pass
 
-class TestDevolvedStrDictImplementation(BaseTestDevolvedDictImplementation):
-    StrategyClass = StringDictStrategy
+class TestDevolvedBytesDictImplementation(BaseTestDevolvedDictImplementation):
+    StrategyClass = BytesDictStrategy
 
 
 def test_module_uses_strdict():
     fakespace = FakeSpace()
     d = fakespace.newdict(module=True)
-    assert type(d.strategy) is StringDictStrategy
+    assert type(d.strategy) is BytesDictStrategy
 

File pypy/objspace/std/test/test_kwargsdict.py

View file
  • Ignore whitespace
     for i in range(100):
         assert d.setitem_str("d%s" % i, 4) is None
     assert d.strategy is not strategy
-    assert "StringDictStrategy" == d.strategy.__class__.__name__
+    assert "BytesDictStrategy" == d.strategy.__class__.__name__
 
 def test_keys_doesnt_wrap():
     space = FakeSpace()

File pypy/objspace/std/test/test_liststrategies.py

View file
  • Ignore whitespace
 import sys
-from pypy.objspace.std.listobject import W_ListObject, EmptyListStrategy, ObjectListStrategy, IntegerListStrategy, FloatListStrategy, StringListStrategy, RangeListStrategy, make_range_list, UnicodeListStrategy
+from pypy.objspace.std.listobject import W_ListObject, EmptyListStrategy, ObjectListStrategy, IntegerListStrategy, FloatListStrategy, BytesListStrategy, RangeListStrategy, make_range_list, UnicodeListStrategy
 from pypy.objspace.std import listobject
 from pypy.objspace.std.test.test_listobject import TestW_ListObject
 
         assert isinstance(W_ListObject(space, [w(1),w(2),w(3)]).strategy,
                           IntegerListStrategy)
         assert isinstance(W_ListObject(space, [w('a'), w('b')]).strategy,
-                          StringListStrategy)
+                          BytesListStrategy)
         assert isinstance(W_ListObject(space, [w(u'a'), w(u'b')]).strategy,
                           UnicodeListStrategy)
         assert isinstance(W_ListObject(space, [w(u'a'), w('b')]).strategy,
         l = W_ListObject(space, [])
         assert isinstance(l.strategy, EmptyListStrategy)
         l.append(w('a'))
-        assert isinstance(l.strategy, StringListStrategy)
+        assert isinstance(l.strategy, BytesListStrategy)
 
         l = W_ListObject(space, [])
         assert isinstance(l.strategy, EmptyListStrategy)
     def test_string_to_any(self):
         l = W_ListObject(self.space,
                          [self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
-        assert isinstance(l.strategy, StringListStrategy)
+        assert isinstance(l.strategy, BytesListStrategy)
         l.append(self.space.wrap('d'))
-        assert isinstance(l.strategy, StringListStrategy)
+        assert isinstance(l.strategy, BytesListStrategy)
         l.append(self.space.wrap(3))
         assert isinstance(l.strategy, ObjectListStrategy)
 
         l.setitem(0, w('d'))
         assert space.eq_w(l.getitem(0), w('d'))
 
-        assert isinstance(l.strategy, StringListStrategy)
+        assert isinstance(l.strategy, BytesListStrategy)
 
         # IntStrategy to ObjectStrategy
         l = W_ListObject(space, [w(1),w(2),w(3)])
         l.setitem(0, w('d'))
         assert isinstance(l.strategy, ObjectListStrategy)
 
-        # StringStrategy to ObjectStrategy
+        # BytesStrategy to ObjectStrategy
         l = W_ListObject(space, [w('a'),w('b'),w('c')])
-        assert isinstance(l.strategy, StringListStrategy)
+        assert isinstance(l.strategy, BytesListStrategy)
         l.setitem(0, w(2))
         assert isinstance(l.strategy, ObjectListStrategy)
 
         l.insert(3, w(4))
         assert isinstance(l.strategy, IntegerListStrategy)
 
-        # StringStrategy
+        # BytesStrategy
         l = W_ListObject(space, [w('a'),w('b'),w('c')])
-        assert isinstance(l.strategy, StringListStrategy)
+        assert isinstance(l.strategy, BytesListStrategy)
         l.insert(3, w(2))
         assert isinstance(l.strategy, ObjectListStrategy)
 
         l = W_ListObject(space, [])
         assert isinstance(l.strategy, EmptyListStrategy)
         l.insert(0, w('a'))
-        assert isinstance(l.strategy, StringListStrategy)
+        assert isinstance(l.strategy, BytesListStrategy)
 
         l = W_ListObject(space, [])
         assert isinstance(l.strategy, EmptyListStrategy)
         l.setslice(0, 1, 2, W_ListObject(space, [w('a'), w('b'), w('c')]))
         assert isinstance(l.strategy, ObjectListStrategy)
 
-        # StringStrategy to ObjectStrategy
+        # BytesStrategy to ObjectStrategy
         l = W_ListObject(space, [w('a'), w('b'), w('c')])
-        assert isinstance(l.strategy, StringListStrategy)
+        assert isinstance(l.strategy, BytesListStrategy)
         l.setslice(0, 1, 2, W_ListObject(space, [w(1), w(2), w(3)]))
         assert isinstance(l.strategy, ObjectListStrategy)
 
         l = W_ListObject(space, wrapitems(["a","b","c","d","e"]))
         other = W_ListObject(space, wrapitems(["a", "b", "c"]))
         keep_other_strategy(l, 0, 2, other.length(), other)
-        assert l.strategy is space.fromcache(StringListStrategy)
+        assert l.strategy is space.fromcache(BytesListStrategy)
 
         l = W_ListObject(space, wrapitems([u"a",u"b",u"c",u"d",u"e"]))
         other = W_ListObject(space, wrapitems([u"a", u"b", u"c"]))
         empty = W_ListObject(space, [])
         assert isinstance(empty.strategy, EmptyListStrategy)
         empty.extend(W_ListObject(space, [w("a"), w("b"), w("c")]))
-        assert isinstance(empty.strategy, StringListStrategy)
+        assert isinstance(empty.strategy, BytesListStrategy)
 
         empty = W_ListObject(space, [])
         assert isinstance(empty.strategy, EmptyListStrategy)
 
     def test_unicode(self):
         l1 = W_ListObject(self.space, [self.space.wrap("eins"), self.space.wrap("zwei")])
-        assert isinstance(l1.strategy, StringListStrategy)
+        assert isinstance(l1.strategy, BytesListStrategy)
         l2 = W_ListObject(self.space, [self.space.wrap(u"eins"), self.space.wrap(u"zwei")])
         assert isinstance(l2.strategy, UnicodeListStrategy)
         l3 = W_ListObject(self.space, [self.space.wrap("eins"), self.space.wrap(u"zwei")])
         assert isinstance(l3.strategy, ObjectListStrategy)
 
-    def test_listview_str(self):
+    def test_listview_bytes(self):
         space = self.space
-        assert space.listview_str(space.wrap(1)) == None
+        assert space.listview_bytes(space.wrap(1)) == None
         w_l = self.space.newlist([self.space.wrap('a'), self.space.wrap('b')])
-        assert space.listview_str(w_l) == ["a", "b"]
+        assert space.listview_bytes(w_l) == ["a", "b"]
 
     def test_listview_unicode(self):
         space = self.space
         w_l = self.space.newlist([self.space.wrap(u'a'), self.space.wrap(u'b')])
         assert space.listview_unicode(w_l) == [u"a", u"b"]
 
-    def test_string_join_uses_listview_str(self):
+    def test_string_join_uses_listview_bytes(self):
         space = self.space
         w_l = self.space.newlist([self.space.wrap('a'), self.space.wrap('b')])
         w_l.getitems = None
         w_l.getitems = None
         assert space.is_w(space.call_method(space.wrap(u" -- "), "join", w_l), w_text)
 
-    def test_newlist_str(self):
+    def test_newlist_bytes(self):
         space = self.space
         l = ['a', 'b']
-        w_l = self.space.newlist_str(l)
-        assert isinstance(w_l.strategy, StringListStrategy)
-        assert space.listview_str(w_l) is l
+        w_l = self.space.newlist_bytes(l)
+        assert isinstance(w_l.strategy, BytesListStrategy)
+        assert space.listview_bytes(w_l) is l
 
-    def test_string_uses_newlist_str(self):
+    def test_string_uses_newlist_bytes(self):
         space = self.space
         w_s = space.wrap("a b c")
         space.newlist = None
             w_l4 = space.call_method(w_s, "rsplit", space.wrap(" "))
         finally:
             del space.newlist
-        assert space.listview_str(w_l) == ["a", "b", "c"]
-        assert space.listview_str(w_l2) == ["a", "b", "c"]
-        assert space.listview_str(w_l3) == ["a", "b", "c"]
-        assert space.listview_str(w_l4) == ["a", "b", "c"]
+        assert space.listview_bytes(w_l) == ["a", "b", "c"]
+        assert space.listview_bytes(w_l2) == ["a", "b", "c"]
+        assert space.listview_bytes(w_l3) == ["a", "b", "c"]
+        assert space.listview_bytes(w_l4) == ["a", "b", "c"]
 
     def test_unicode_uses_newlist_unicode(self):
         space = self.space
         assert space.eq_w(w_l, w_l2)
 
 
-    def test_listview_str_list(self):
+    def test_listview_bytes_list(self):
         space = self.space
         w_l = W_ListObject(space, [space.wrap("a"), space.wrap("b")])
-        assert self.space.listview_str(w_l) == ["a", "b"]
+        assert self.space.listview_bytes(w_l) == ["a", "b"]
 
     def test_listview_unicode_list(self):
         space = self.space

File pypy/objspace/std/test/test_setobject.py

View file
  • Ignore whitespace
 
     def test_create_set_from_list(self):
         from pypy.interpreter.baseobjspace import W_Root
-        from pypy.objspace.std.setobject import ObjectSetStrategy, StringSetStrategy, UnicodeSetStrategy
+        from pypy.objspace.std.setobject import BytesSetStrategy, ObjectSetStrategy, UnicodeSetStrategy
         from pypy.objspace.std.floatobject import W_FloatObject
 
         w = self.space.wrap
         w_list = W_ListObject(self.space, [w("1"), w("2"), w("3")])
         w_set = W_SetObject(self.space)
         _initialize_set(self.space, w_set, w_list)
-        assert w_set.strategy is self.space.fromcache(StringSetStrategy)
+        assert w_set.strategy is self.space.fromcache(BytesSetStrategy)
         assert w_set.strategy.unerase(w_set.sstorage) == {"1":None, "2":None, "3":None}
 
         w_list = self.space.iter(W_ListObject(self.space, [w(u"1"), w(u"2"), w(u"3")]))
         # changed cached object, need to change it back for other tests to pass
         intstr.get_storage_from_list = tmp_func
 
-    def test_listview_str_int_on_set(self):
+    def test_listview_bytes_int_on_set(self):
         w = self.space.wrap
 
         w_a = W_SetObject(self.space)
         _initialize_set(self.space, w_a, w("abcdefg"))
-        assert sorted(self.space.listview_str(w_a)) == list("abcdefg")
+        assert sorted(self.space.listview_bytes(w_a)) == list("abcdefg")
         assert self.space.listview_int(w_a) is None
 
         w_b = W_SetObject(self.space)
         _initialize_set(self.space, w_b, self.space.newlist([w(1),w(2),w(3),w(4),w(5)]))
         assert sorted(self.space.listview_int(w_b)) == [1,2,3,4,5]
-        assert self.space.listview_str(w_b) is None
+        assert self.space.listview_bytes(w_b) is None
 
 class AppTestAppSetTest:
 

File pypy/objspace/std/test/test_setstrategies.py

View file
  • Ignore whitespace
 from pypy.objspace.std.setobject import W_SetObject
-from pypy.objspace.std.setobject import (IntegerSetStrategy, ObjectSetStrategy,
-                                         EmptySetStrategy, StringSetStrategy,
-                                         UnicodeSetStrategy,
-                                         IntegerIteratorImplementation,
-                                         StringIteratorImplementation,
-                                         UnicodeIteratorImplementation)
+from pypy.objspace.std.setobject import (
+    BytesIteratorImplementation, BytesSetStrategy, EmptySetStrategy,
+    IntegerIteratorImplementation, IntegerSetStrategy, ObjectSetStrategy,
+    UnicodeIteratorImplementation, UnicodeSetStrategy)
 from pypy.objspace.std.listobject import W_ListObject
 
 class TestW_SetStrategies:
         assert s.strategy is self.space.fromcache(EmptySetStrategy)
 
         s = W_SetObject(self.space, self.wrapped(["a", "b"]))
-        assert s.strategy is self.space.fromcache(StringSetStrategy)
+        assert s.strategy is self.space.fromcache(BytesSetStrategy)
 
         s = W_SetObject(self.space, self.wrapped([u"a", u"b"]))
         assert s.strategy is self.space.fromcache(UnicodeSetStrategy)
         #
         s = W_SetObject(space, self.wrapped(["a", "b"]))
         it = s.iter()
-        assert isinstance(it, StringIteratorImplementation)
+        assert isinstance(it, BytesIteratorImplementation)
         assert space.unwrap(it.next()) == "a"
         assert space.unwrap(it.next()) == "b"
         #
         assert sorted(space.listview_int(s)) == [1, 2]
         #
         s = W_SetObject(space, self.wrapped(["a", "b"]))
-        assert sorted(space.listview_str(s)) == ["a", "b"]
+        assert sorted(space.listview_bytes(s)) == ["a", "b"]
         #
         s = W_SetObject(space, self.wrapped([u"a", u"b"]))
         assert sorted(space.listview_unicode(s)) == [u"a", u"b"]

File pypy/objspace/std/unicodeobject.py

View file
  • Ignore whitespace
         """x.__getitem__(y) <==> x[y]"""
 
     def __getnewargs__():
-        """"""
+        ""
 
     def __getslice__():
         """x.__getslice__(i, j) <==> x[i:j]

File rpython/annotator/annrpython.py

View file
  • Ignore whitespace
 from rpython.flowspace.model import (Variable, Constant, FunctionGraph,
                                       c_last_exception, checkgraph)
 from rpython.translator import simplify, transform
-from rpython.annotator import model as annmodel, signature, unaryop, binaryop
+from rpython.annotator import model as annmodel, signature
 from rpython.annotator.bookkeeper import Bookkeeper
 
 import py
         # occour for this specific, typed operation.
         if block.exitswitch == c_last_exception:
             op = block.operations[-1]
-            if op.opname in binaryop.BINARY_OPERATIONS:
+            if op.dispatch == 2:
                 arg1 = self.binding(op.args[0])
                 arg2 = self.binding(op.args[1])
                 binop = getattr(pair(arg1, arg2), op.opname, None)
                 can_only_throw = annmodel.read_can_only_throw(binop, arg1, arg2)
-            elif op.opname in unaryop.UNARY_OPERATIONS:
+            elif op.dispatch == 1:
                 arg1 = self.binding(op.args[0])
                 opname = op.opname
                 if opname == 'contains': opname = 'op_contains'
     def noreturnvalue(self, op):
         return annmodel.s_ImpossibleValue  # no return value (hook method)
 
-    # XXX "contains" clash with SomeObject method
-    def consider_op_contains(self, seq, elem):
-        self.bookkeeper.count("contains", seq)
-        return seq.op_contains(elem)
-
-    def consider_op_newtuple(self, *args):
-        return annmodel.SomeTuple(items = args)
-
-    def consider_op_newlist(self, *args):
-        return self.bookkeeper.newlist(*args)
-
-    def consider_op_newdict(self):
-        return self.bookkeeper.newdict()
-
-
-    def _registeroperations(cls, unary_ops, binary_ops):
-        # All unary operations
-        d = {}
-        for opname in unary_ops:
-            fnname = 'consider_op_' + opname
-            exec py.code.Source("""
-def consider_op_%s(self, arg, *args):
-    return arg.%s(*args)
-""" % (opname, opname)).compile() in globals(), d
-            setattr(cls, fnname, d[fnname])
-        # All binary operations
-        for opname in binary_ops:
-            fnname = 'consider_op_' + opname
-            exec py.code.Source("""
-def consider_op_%s(self, arg1, arg2, *args):
-    return pair(arg1,arg2).%s(*args)
-""" % (opname, opname)).compile() in globals(), d
-            setattr(cls, fnname, d[fnname])
-    _registeroperations = classmethod(_registeroperations)
-
-# register simple operations handling
-RPythonAnnotator._registeroperations(unaryop.UNARY_OPERATIONS, binaryop.BINARY_OPERATIONS)
-
 
 class BlockedInference(Exception):
     """This exception signals the type inference engine that the situation

File rpython/annotator/binaryop.py

View file
  • Ignore whitespace
     SomeBuiltin, SomeIterator, SomePBC, SomeFloat, s_None, SomeByteArray,
     SomeWeakRef, SomeAddress, SomeTypedAddressAccess, SomeSingleFloat,
     SomeLongFloat, SomeType, SomeConstantType, unionof, UnionError,
-    missing_operation, read_can_only_throw, add_knowntypedata,
+    read_can_only_throw, add_knowntypedata,
     merge_knowntypedata,)
 from rpython.annotator.bookkeeper import getbookkeeper
 from rpython.flowspace.model import Variable, Constant
+from rpython.flowspace.operation import op
 from rpython.rlib import rarithmetic