[pypy-commit] pypy less-gettestobjspace: hg merge default

amauryfa noreply at buildbot.pypy.org
Mon Oct 29 22:40:31 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: less-gettestobjspace
Changeset: r58626:d6e7687c576c
Date: 2012-10-29 22:38 +0100
http://bitbucket.org/pypy/pypy/changeset/d6e7687c576c/

Log:	hg merge default

diff --git a/pypy/interpreter/buffer.py b/pypy/interpreter/buffer.py
--- a/pypy/interpreter/buffer.py
+++ b/pypy/interpreter/buffer.py
@@ -74,8 +74,11 @@
         elif step == 1:
             length = stop - start
             if length != len(newstring):
-                msg = "buffer slice assignment is wrong size"
-                raise OperationError(space.w_ValueError, space.wrap(msg))
+                if length < 0 and len(newstring) == 0:
+                    pass     # ok anyway
+                else:
+                    msg = "right operand length must match slice length"
+                    raise OperationError(space.w_ValueError, space.wrap(msg))
             self.setslice(start, newstring)
         else:
             raise OperationError(space.w_ValueError,
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -429,15 +429,17 @@
         source_start_box = self.get_constant_box(op.getarg(3))
         dest_start_box = self.get_constant_box(op.getarg(4))
         length = self.get_constant_box(op.getarg(5))
+        extrainfo = op.getdescr().get_extra_info()
         if (source_start_box and dest_start_box
             and length and (dest_value.is_virtual() or length.getint() <= 8) and
-            (source_value.is_virtual() or length.getint() <= 8)):
+            (source_value.is_virtual() or length.getint() <= 8) and
+            len(extrainfo.write_descrs_arrays) == 1):   # <-sanity check
             from pypy.jit.metainterp.optimizeopt.virtualize import VArrayValue
             source_start = source_start_box.getint()
             dest_start = dest_start_box.getint()
+            # XXX fish fish fish
+            arraydescr = extrainfo.write_descrs_arrays[0]
             for index in range(length.getint()):
-                # XXX fish fish fish
-                arraydescr = op.getdescr().get_extra_info().write_descrs_arrays[0]
                 if source_value.is_virtual():
                     assert isinstance(source_value, VArrayValue)
                     val = source_value.getitem(index + source_start)
diff --git a/pypy/module/__builtin__/test/test_buffer.py b/pypy/module/__builtin__/test/test_buffer.py
--- a/pypy/module/__builtin__/test/test_buffer.py
+++ b/pypy/module/__builtin__/test/test_buffer.py
@@ -116,6 +116,8 @@
         b[:] = '12345'
         assert a.tostring() == 'hello 12345'
         raises(IndexError, 'b[5] = "."')
+        b[4:2] = ''
+        assert a.tostring() == 'hello 12345'
 
         b = buffer(b, 2)
         assert len(b) == 3
diff --git a/pypy/module/_cffi_backend/cbuffer.py b/pypy/module/_cffi_backend/cbuffer.py
--- a/pypy/module/_cffi_backend/cbuffer.py
+++ b/pypy/module/_cffi_backend/cbuffer.py
@@ -1,6 +1,7 @@
 from pypy.interpreter.error import operationerrfmt
 from pypy.interpreter.buffer import RWBuffer
-from pypy.interpreter.gateway import unwrap_spec
+from pypy.interpreter.gateway import unwrap_spec, interp2app
+from pypy.interpreter.typedef import TypeDef
 from pypy.rpython.lltypesystem import rffi
 from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
 
@@ -34,6 +35,16 @@
         for i in range(len(string)):
             raw_cdata[i] = string[i]
 
+LLBuffer.typedef = TypeDef(
+    "buffer",
+    __module__ = "_cffi_backend",
+    __len__ = interp2app(RWBuffer.descr_len),
+    __getitem__ = interp2app(RWBuffer.descr_getitem),
+    __setitem__ = interp2app(RWBuffer.descr_setitem),
+    __buffer__ = interp2app(RWBuffer.descr__buffer__),
+    )
+LLBuffer.typedef.acceptable_as_base_class = False
+
 
 @unwrap_spec(cdata=cdataobj.W_CData, size=int)
 def buffer(space, cdata, size=-1):
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -5,8 +5,6 @@
     type_or_class = "type"
     mandatory_b_prefix = ''
     mandatory_u_prefix = 'u'
-    readbuf = str
-    bufchar = lambda x: x
     bytechr = chr
     class U(object):
         def __add__(self, other):
@@ -20,11 +18,6 @@
     unichr = chr
     mandatory_b_prefix = 'b'
     mandatory_u_prefix = ''
-    readbuf = lambda buf: buf.tobytes()
-    if sys.version_info < (3, 3):
-        bufchar = lambda x: bytes([ord(x)])
-    else:
-        bufchar = ord
     bytechr = lambda n: bytes([n])
     u = ""
 
@@ -1811,36 +1804,76 @@
     assert (p < s) ^ (p > s)
 
 def test_buffer():
+    import __builtin__
     BShort = new_primitive_type("short")
     s = newp(new_pointer_type(BShort), 100)
     assert sizeof(s) == size_of_ptr()
     assert sizeof(BShort) == 2
-    assert len(readbuf(buffer(s))) == 2
+    assert len(buffer(s)) == 2
     #
     BChar = new_primitive_type("char")
     BCharArray = new_array_type(new_pointer_type(BChar), None)
     c = newp(BCharArray, b"hi there")
+    #
     buf = buffer(c)
-    assert readbuf(buf) == b"hi there\x00"
+    assert str(buf).startswith('<_cffi_backend.buffer object at 0x')
+    # --mb_length--
     assert len(buf) == len(b"hi there\x00")
-    assert buf[0] == bufchar('h')
-    assert buf[2] == bufchar(' ')
-    assert list(buf) == list(map(bufchar, "hi there\x00"))
-    buf[2] = bufchar('-')
-    assert c[2] == b'-'
-    assert readbuf(buf) == b"hi-there\x00"
-    c[2] = b'!'
-    assert buf[2] == bufchar('!')
-    assert readbuf(buf) == b"hi!there\x00"
-    c[2] = b'-'
-    buf[:2] = b'HI'
-    assert string(c) == b'HI-there'
-    if sys.version_info < (3,) or sys.version_info >= (3, 3):
-        assert buf[:4:2] == b'H-'
-        if '__pypy__' not in sys.builtin_module_names:
-            # XXX pypy doesn't support the following assignment so far
-            buf[:4:2] = b'XY'
-            assert string(c) == b'XIYthere'
+    # --mb_item--
+    for i in range(-12, 12):
+        try:
+            expected = b"hi there\x00"[i]
+        except IndexError:
+            py.test.raises(IndexError, "buf[i]")
+        else:
+            assert buf[i] == expected
+    # --mb_slice--
+    assert buf[:] == b"hi there\x00"
+    for i in range(-12, 12):
+        assert buf[i:] == b"hi there\x00"[i:]
+        assert buf[:i] == b"hi there\x00"[:i]
+        for j in range(-12, 12):
+            assert buf[i:j] == b"hi there\x00"[i:j]
+    # --misc--
+    assert list(buf) == list(b"hi there\x00")
+    # --mb_as_buffer--
+    py.test.raises(TypeError, __builtin__.buffer, c)
+    bf1 = __builtin__.buffer(buf)
+    assert len(bf1) == len(buf) and bf1[3] == "t"
+    if hasattr(__builtin__, 'memoryview'):      # Python >= 2.7
+        py.test.raises(TypeError, memoryview, c)
+        mv1 = memoryview(buf)
+        assert len(mv1) == len(buf) and mv1[3] == "t"
+    # --mb_ass_item--
+    expected = list(b"hi there\x00")
+    for i in range(-12, 12):
+        try:
+            expected[i] = chr(i & 0xff)
+        except IndexError:
+            py.test.raises(IndexError, "buf[i] = chr(i & 0xff)")
+        else:
+            buf[i] = chr(i & 0xff)
+        assert list(buf) == expected
+    # --mb_ass_slice--
+    buf[:] = b"hi there\x00"
+    assert list(buf) == list(c) == list(b"hi there\x00")
+    py.test.raises(ValueError, 'buf[:] = b"shorter"')
+    py.test.raises(ValueError, 'buf[:] = b"this is much too long!"')
+    buf[4:2] = b""   # no effect, but should work
+    assert buf[:] == b"hi there\x00"
+    expected = list(b"hi there\x00")
+    x = 0
+    for i in range(-12, 12):
+        for j in range(-12, 12):
+            start = i if i >= 0 else i + len(buf)
+            stop  = j if j >= 0 else j + len(buf)
+            start = max(0, min(len(buf), start))
+            stop  = max(0, min(len(buf), stop))
+            sample = chr(x & 0xff) * (stop - start)
+            x += 1
+            buf[i:j] = sample
+            expected[i:j] = sample
+            assert list(buf) == expected
 
 def test_getcname():
     BUChar = new_primitive_type("unsigned char")
diff --git a/pypy/module/_multiprocessing/test/test_connection.py b/pypy/module/_multiprocessing/test/test_connection.py
--- a/pypy/module/_multiprocessing/test/test_connection.py
+++ b/pypy/module/_multiprocessing/test/test_connection.py
@@ -8,7 +8,8 @@
         from pypy.module._multiprocessing import interp_semaphore
 
 class AppTestBufferTooShort:
-    spaceconfig = dict(usemodules=['_multiprocessing', 'thread', 'signal'])
+    spaceconfig = dict(usemodules=['_multiprocessing', 'thread', 'signal',
+                                   'itertools'])
 
     def setup_class(cls):
         if cls.runappdirect:
diff --git a/pypy/module/_multiprocessing/test/test_memory.py b/pypy/module/_multiprocessing/test/test_memory.py
--- a/pypy/module/_multiprocessing/test/test_memory.py
+++ b/pypy/module/_multiprocessing/test/test_memory.py
@@ -1,6 +1,6 @@
 class AppTestMemory:
     spaceconfig = dict(usemodules=('_multiprocessing', 'mmap',
-                                   '_rawffi', '_ffi'))
+                                   '_rawffi', '_ffi', 'itertools'))
 
     def test_address_of(self):
         import _multiprocessing
diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py
--- a/pypy/module/bz2/interp_bz2.py
+++ b/pypy/module/bz2/interp_bz2.py
@@ -357,8 +357,8 @@
             buffering = 1024   # minimum amount of compressed data read at once
         self.buffering = buffering
 
-    def close(self):
-        self.stream.close()
+    def close1(self, closefileno):
+        self.stream.close1(closefileno)
 
     def tell(self):
         return self.readlength
@@ -479,9 +479,9 @@
         self.compressor = W_BZ2Compressor(space, compresslevel)
         self.writtenlength = 0
 
-    def close(self):
+    def close1(self, closefileno):
         self.stream.write(self.space.str_w(self.compressor.flush()))
-        self.stream.close()
+        self.stream.close1(closefileno)
 
     def write(self, data):
         self.stream.write(self.space.str_w(self.compressor.compress(data)))
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -198,8 +198,8 @@
 @specialize.memo()
 def make_frozendict(space):
     return space.appexec([], '''():
-    import collections
-    class FrozenDict(collections.Mapping):
+    import _abcoll
+    class FrozenDict(_abcoll.Mapping):
         def __init__(self, *args, **kwargs):
             self._d = dict(*args, **kwargs)
         def __iter__(self):
diff --git a/pypy/module/cpyext/test/test_import.py b/pypy/module/cpyext/test/test_import.py
--- a/pypy/module/cpyext/test/test_import.py
+++ b/pypy/module/cpyext/test/test_import.py
@@ -4,9 +4,9 @@
 
 class TestImport(BaseApiTest):
     def test_import(self, space, api):
-        pdb = api.PyImport_Import(space.wrap("pdb"))
-        assert pdb
-        assert space.getattr(pdb, space.wrap("pm"))
+        stat = api.PyImport_Import(space.wrap("stat"))
+        assert stat
+        assert space.getattr(stat, space.wrap("S_IMODE"))
 
     def test_addmodule(self, space, api):
         with rffi.scoped_str2charp("sys") as modname:
@@ -32,10 +32,10 @@
         assert space.is_true(space.contains(w_dict, space.wrap(testmod)))
 
     def test_reload(self, space, api):
-        pdb = api.PyImport_Import(space.wrap("pdb"))
-        space.delattr(pdb, space.wrap("set_trace"))
-        pdb = api.PyImport_ReloadModule(pdb)
-        assert space.getattr(pdb, space.wrap("set_trace"))
+        stat = api.PyImport_Import(space.wrap("stat"))
+        space.delattr(stat, space.wrap("S_IMODE"))
+        stat = api.PyImport_ReloadModule(stat)
+        assert space.getattr(stat, space.wrap("S_IMODE"))
 
 class AppTestImportLogic(AppTestCpythonExtensionBase):
     def test_import_logic(self):
diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py
--- a/pypy/module/imp/test/test_app.py
+++ b/pypy/module/imp/test/test_app.py
@@ -2,6 +2,8 @@
 MARKER = 42
 
 class AppTestImpModule:
+    spaceconfig = dict(usemodules=('imp', 'itertools'))
+
     def setup_class(cls):
         cls.w_imp = cls.space.getbuiltinmodule('imp')
         cls.w_file_module = cls.space.wrap(__file__)
diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -38,7 +38,7 @@
                     test_reload = "def test():\n    raise ValueError\n",
                     infinite_reload = "import infinite_reload; reload(infinite_reload)",
                     del_sys_module = "import sys\ndel sys.modules['del_sys_module']\n",
-                    itertools = "hello_world = 42\n",
+                    _md5 = "hello_world = 42\n",
                     gc = "should_never_be_seen = 42\n",
                     )
     root.ensure("notapackage", dir=1)    # empty, no __init__.py
@@ -146,7 +146,7 @@
     """)
 
 class AppTestImport:
-    spaceconfig = dict(usemodules=['itertools'])
+    spaceconfig = dict(usemodules=['_md5'])
 
     def setup_class(cls): # interpreter-level
         cls.w_runappdirect = cls.space.wrap(conftest.option.runappdirect)
@@ -597,34 +597,34 @@
 
     def test_shadow_extension_1(self):
         if self.runappdirect: skip("hard to test: module is already imported")
-        # 'import itertools' is supposed to find itertools.py if there is
+        # 'import _md5' is supposed to find _md5.py if there is
         # one in sys.path.
         import sys
-        assert 'itertools' not in sys.modules
-        import itertools
-        assert hasattr(itertools, 'hello_world')
-        assert not hasattr(itertools, 'count')
-        assert '(built-in)' not in repr(itertools)
-        del sys.modules['itertools']
+        assert '_md5' not in sys.modules
+        import _md5
+        assert hasattr(_md5, 'hello_world')
+        assert not hasattr(_md5, 'count')
+        assert '(built-in)' not in repr(_md5)
+        del sys.modules['_md5']
 
     def test_shadow_extension_2(self):
         if self.runappdirect: skip("hard to test: module is already imported")
-        # 'import itertools' is supposed to find the built-in module even
+        # 'import _md5' is supposed to find the built-in module even
         # if there is also one in sys.path as long as it is *after* the
         # special entry '.../lib_pypy/__extensions__'.  (Note that for now
-        # there is one in lib_pypy/itertools.py, which should not be seen
+        # there is one in lib_pypy/_md5.py, which should not be seen
         # either; hence the (built-in) test below.)
         import sys
-        assert 'itertools' not in sys.modules
+        assert '_md5' not in sys.modules
         sys.path.append(sys.path.pop(0))
         try:
-            import itertools
-            assert not hasattr(itertools, 'hello_world')
-            assert hasattr(itertools, 'izip')
-            assert '(built-in)' in repr(itertools)
+            import _md5
+            assert not hasattr(_md5, 'hello_world')
+            assert hasattr(_md5, 'digest_size')
+            assert '(built-in)' in repr(_md5)
         finally:
             sys.path.insert(0, sys.path.pop())
-        del sys.modules['itertools']
+        del sys.modules['_md5']
 
     def test_invalid_pathname(self):
         import imp
@@ -1003,7 +1003,7 @@
             os.environ['LANG'] = oldlang
 
 class AppTestImportHooks(object):
-    spaceconfig = dict(usemodules=('struct',))
+    spaceconfig = dict(usemodules=('struct', 'itertools'))
 
     def setup_class(cls):
         mydir = os.path.dirname(__file__)
diff --git a/pypy/module/math/test/test_math.py b/pypy/module/math/test/test_math.py
--- a/pypy/module/math/test/test_math.py
+++ b/pypy/module/math/test/test_math.py
@@ -4,7 +4,7 @@
 
 
 class AppTestMath:
-    spaceconfig = dict(usemodules=['math', 'struct'])
+    spaceconfig = dict(usemodules=['math', 'struct', 'itertools'])
 
     def setup_class(cls):
         cls.w_cases = cls.space.wrap(test_direct.MathTests.TESTCASES)
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -45,7 +45,7 @@
     def __init__(self, array):
         self.array = array
         self.offset = array.start
-        self.skip = array.strides[0]
+        self.skip = array.get_strides()[0]
         self.dtype = array.dtype
         self.index = 0
         self.size = array.get_shape()[0]
@@ -116,8 +116,8 @@
 class AxisIterator(base.BaseArrayIterator):
     def __init__(self, array, shape, dim):
         self.shape = shape
-        strides = array.strides
-        backstrides = array.backstrides
+        strides = array.get_strides()
+        backstrides = array.get_backstrides()
         if len(shape) == len(strides):
             # keepdims = True
             self.strides = strides[:dim] + [0] + strides[dim + 1:]
@@ -167,12 +167,24 @@
 class BaseConcreteArray(base.BaseArrayImplementation):
     start = 0
     parent = None
+
+    # JIT hints that length of all those arrays is a constant
     
     def get_shape(self):
         shape = self.shape
         jit.hint(len(shape), promote=True)
         return shape
 
+    def get_strides(self):
+        strides = self.strides
+        jit.hint(len(strides), promote=True)
+        return strides
+
+    def get_backstrides(self):
+        backstrides = self.backstrides
+        jit.hint(len(backstrides), promote=True)
+        return backstrides
+
     def getitem(self, index):
         return self.dtype.getitem(self, index)
 
@@ -197,7 +209,7 @@
         new_strides = None
         if self.size > 0:
             new_strides = calc_new_strides(new_shape, self.get_shape(),
-                                           self.strides, self.order)
+                                           self.get_strides(), self.order)
         if new_strides:
             # We can create a view, strides somehow match up.
             ndims = len(new_shape)
@@ -214,6 +226,7 @@
     @jit.unroll_safe
     def _lookup_by_index(self, space, view_w):
         item = self.start
+        strides = self.get_strides()
         for i, w_index in enumerate(view_w):
             if space.isinstance_w(w_index, space.w_slice):
                 raise IndexError
@@ -224,13 +237,14 @@
                 raise operationerrfmt(space.w_IndexError,
                       "index (%d) out of range (0<=index<%d", i, self.get_shape()[i],
                 )
-            item += idx * self.strides[i]
+            item += idx * strides[i]
         return item
 
     @jit.unroll_safe
     def _lookup_by_unwrapped_index(self, space, lst):
         item = self.start
         shape = self.get_shape()
+        strides = self.get_strides()
         assert len(lst) == len(shape)
         for i, idx in enumerate(lst):
             if idx < 0:
@@ -239,7 +253,7 @@
                 raise operationerrfmt(space.w_IndexError,
                       "index (%d) out of range (0<=index<%d", i, shape[i],
                 )
-            item += idx * self.strides[i]
+            item += idx * strides[i]
         return item
 
     def getitem_index(self, space, index):
@@ -344,8 +358,8 @@
         backstrides = []
         shape = []
         for i in range(len(self.get_shape()) - 1, -1, -1):
-            strides.append(self.strides[i])
-            backstrides.append(self.backstrides[i])
+            strides.append(self.get_strides()[i])
+            backstrides.append(self.get_backstrides()[i])
             shape.append(self.get_shape()[i])
         return SliceArray(self.start, strides,
                           backstrides, shape, self)
@@ -361,14 +375,14 @@
         return AxisIterator(self, shape, dim)
 
     def create_dot_iter(self, shape, skip):
-        r = calculate_dot_strides(self.strides, self.backstrides,
+        r = calculate_dot_strides(self.get_strides(), self.get_backstrides(),
                                   shape, skip)
         return MultiDimViewIterator(self, self.start, r[0], r[1], shape)
 
     def swapaxes(self, axis1, axis2):
         shape = self.get_shape()[:]
-        strides = self.strides[:]
-        backstrides = self.backstrides[:]
+        strides = self.get_strides()[:]
+        backstrides = self.get_backstrides()[:]
         shape[axis1], shape[axis2] = shape[axis2], shape[axis1]   
         strides[axis1], strides[axis2] = strides[axis2], strides[axis1]
         backstrides[axis1], backstrides[axis2] = backstrides[axis2], backstrides[axis1] 
@@ -394,7 +408,8 @@
     def create_iter(self, shape=None):
         if shape is None or shape == self.get_shape():
             return ConcreteArrayIterator(self)
-        r = calculate_broadcast_strides(self.strides, self.backstrides,
+        r = calculate_broadcast_strides(self.get_strides(),
+                                        self.get_backstrides(),
                                         self.get_shape(), shape)
         return MultiDimViewIterator(self, 0, r[0], r[1], shape)
 
@@ -430,14 +445,16 @@
 
     def create_iter(self, shape=None):
         if shape is not None and shape != self.get_shape():
-            r = calculate_broadcast_strides(self.strides, self.backstrides,
+            r = calculate_broadcast_strides(self.get_strides(),
+                                            self.get_backstrides(),
                                             self.get_shape(), shape)
             return MultiDimViewIterator(self.parent,
                                         self.start, r[0], r[1], shape)
         if len(self.get_shape()) == 1:
             return OneDimViewIterator(self)
-        return MultiDimViewIterator(self.parent, self.start, self.strides,
-                                    self.backstrides, self.get_shape())
+        return MultiDimViewIterator(self.parent, self.start,
+                                    self.get_strides(),
+                                    self.get_backstrides(), self.get_shape())
 
     def set_shape(self, space, new_shape):
         if len(self.get_shape()) < 2 or self.size == 0:
@@ -446,7 +463,7 @@
             strides = []
             backstrides = []
             dtype = self.dtype
-            s = self.strides[0] // dtype.get_size()
+            s = self.get_strides()[0] // dtype.get_size()
             if self.order == 'C':
                 new_shape.reverse()
             for sh in new_shape:
@@ -459,7 +476,8 @@
                 new_shape.reverse()
             return SliceArray(self.start, strides, backstrides, new_shape,
                               self)
-        new_strides = calc_new_strides(new_shape, self.get_shape(), self.strides,
+        new_strides = calc_new_strides(new_shape, self.get_shape(),
+                                       self.get_strides(),
                                        self.order)
         if new_strides is None:
             raise OperationError(space.w_AttributeError, space.wrap(
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -275,14 +275,6 @@
             arr.storage[i] = arg[i]
         return W_StringBox(arr, 0, arr.dtype)
 
-    # Running entire test suite needs this function to succeed,
-    # running single test_stringarray succeeds without it.
-    # With convert_to() test_ztranslation fails since 
-    # W_CharacterBox is not a W_GenericBox.
-    # Why is it needed for multiple tests?
-    #def convert_to(self, dtype):
-    #    xxx
-
 class W_UnicodeBox(W_CharacterBox):
     def descr__new__unicode_box(space, w_subtype, w_arg):
         from pypy.module.micronumpy.interp_dtype import new_unicode_dtype
diff --git a/pypy/module/micronumpy/iter.py b/pypy/module/micronumpy/iter.py
--- a/pypy/module/micronumpy/iter.py
+++ b/pypy/module/micronumpy/iter.py
@@ -59,8 +59,8 @@
     def apply(self, arr):
         ofs, subdtype = arr.dtype.fields[self.name]
         # strides backstrides are identical, ofs only changes start
-        return W_NDimArray.new_slice(arr.start + ofs, arr.strides,
-                                     arr.backstrides,
+        return W_NDimArray.new_slice(arr.start + ofs, arr.get_strides(),
+                                     arr.get_backstrides(),
                                      arr.shape, arr, subdtype)
 
 class Chunks(BaseChunk):
@@ -80,8 +80,8 @@
 
     def apply(self, arr):
         shape = self.extend_shape(arr.shape)
-        r = calculate_slice_strides(arr.shape, arr.start, arr.strides,
-                                    arr.backstrides, self.l)
+        r = calculate_slice_strides(arr.shape, arr.start, arr.get_strides(),
+                                    arr.get_backstrides(), self.l)
         _, start, strides, backstrides = r
         return W_NDimArray.new_slice(start, strides[:], backstrides[:],
                                      shape[:], arr)
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -110,6 +110,7 @@
             i //= shape[s]
     return coords, step, lngth
 
+ at jit.unroll_safe
 def shape_agreement(space, shape1, w_arr2, broadcast_down=True):
     if w_arr2 is None:
         return shape1
@@ -132,6 +133,7 @@
         )
     return ret
 
+ at jit.unroll_safe
 def _shape_agreement(shape1, shape2):
     """ Checks agreement about two shapes with respect to broadcasting. Returns
     the resulting shape.
diff --git a/pypy/module/micronumpy/support.py b/pypy/module/micronumpy/support.py
--- a/pypy/module/micronumpy/support.py
+++ b/pypy/module/micronumpy/support.py
@@ -8,6 +8,7 @@
         i *= x
     return i
 
+ at jit.unroll_safe
 def calc_strides(shape, dtype, order):
     strides = []
     backstrides = []
diff --git a/pypy/module/test_lib_pypy/test_itertools.py b/pypy/module/test_lib_pypy/test_itertools.py
--- a/pypy/module/test_lib_pypy/test_itertools.py
+++ b/pypy/module/test_lib_pypy/test_itertools.py
@@ -1,4 +1,6 @@
 class AppTestItertools:
+    spaceconfig = dict(usemodules=['itertools'])
+
     def setup_class(cls):
         cls.w_itertools = cls.space.appexec([], "(): import itertools; return itertools")
 
diff --git a/pypy/module/test_lib_pypy/test_pwd.py b/pypy/module/test_lib_pypy/test_pwd.py
--- a/pypy/module/test_lib_pypy/test_pwd.py
+++ b/pypy/module/test_lib_pypy/test_pwd.py
@@ -1,7 +1,8 @@
 import py, sys
 
 class AppTestPwd:
-    spaceconfig = dict(usemodules=('_ffi', '_rawffi'))
+    spaceconfig = dict(usemodules=('_ffi', '_rawffi', 'itertools'))
+
     def setup_class(cls):
         if sys.platform == 'win32':
             py.test.skip("Unix only")
diff --git a/pypy/module/zipimport/test/test_undocumented.py b/pypy/module/zipimport/test/test_undocumented.py
--- a/pypy/module/zipimport/test/test_undocumented.py
+++ b/pypy/module/zipimport/test/test_undocumented.py
@@ -17,7 +17,8 @@
                                ])
 
 class AppTestZipImport:
-    spaceconfig = dict(usemodules=['zipimport', 'rctime', 'struct'])
+    spaceconfig = dict(usemodules=['zipimport', 'rctime', 'struct',
+                                   'itertools'])
     def setup_class(cls):
         cls.w_created_paths = cls.space.wrap(created_paths)
     
diff --git a/pypy/module/zipimport/test/test_zipimport.py b/pypy/module/zipimport/test/test_zipimport.py
--- a/pypy/module/zipimport/test/test_zipimport.py
+++ b/pypy/module/zipimport/test/test_zipimport.py
@@ -14,7 +14,8 @@
     cpy's regression tests
     """
     compression = ZIP_STORED
-    spaceconfig = dict(usemodules=['zipimport', 'rctime', 'struct'])
+    spaceconfig = dict(usemodules=['zipimport', 'rctime', 'struct',
+                                   'itertools'])
     pathsep = os.path.sep
     
     @classmethod
@@ -49,6 +50,7 @@
         """).compile()
             
         space = cls.space
+
         tmpdir = udir.ensure('zipimport_%s' % cls.__name__, dir=1)
         now = time.time()
         cls.w_now = space.wrap(now)
@@ -353,7 +355,8 @@
 
 class AppTestZipimportDeflated(AppTestZipimport):
     compression = ZIP_DEFLATED
-    spaceconfig = dict(usemodules=['zipimport', 'zlib', 'rctime', 'struct'])
+    spaceconfig = dict(usemodules=['zipimport', 'zlib', 'rctime', 'struct',
+                                   'itertools'])
 
     def setup_class(cls):
         try:
diff --git a/pypy/objspace/std/test/test_iterobject.py b/pypy/objspace/std/test/test_iterobject.py
--- a/pypy/objspace/std/test/test_iterobject.py
+++ b/pypy/objspace/std/test/test_iterobject.py
@@ -68,7 +68,7 @@
         raises(TypeError, len, iter(iterable))
         
     def test_no_len_on_deque_iter(self):
-        from collections import deque
+        from _collections import deque
         iterable = deque([1,2,3,4])
         raises(TypeError, len, iter(iterable))
 
@@ -81,15 +81,14 @@
         it = reversed([5,6,7])
         raises(TypeError, len, it)
 
-    def test_no_len_on_UserList_iter(self):
+    def test_no_len_on_UserList_iter_reversed(self):
+        import sys, _abcoll
+        sys.modules['collections'] = _abcoll
         from UserList import UserList
         iterable = UserList([1,2,3,4])
         raises(TypeError, len, iter(iterable))
-
-    def test_no_len_on_UserList_reversed(self):
-        from UserList import UserList
-        iterable = UserList([1,2,3,4])
         raises(TypeError, len, reversed(iterable))
+        del sys.modules['collections']
 
     def test_no_len_on_set_iter(self):
         iterable = set([1,2,3,4])
diff --git a/pypy/objspace/std/test/test_methodcache.py b/pypy/objspace/std/test/test_methodcache.py
--- a/pypy/objspace/std/test/test_methodcache.py
+++ b/pypy/objspace/std/test/test_methodcache.py
@@ -203,8 +203,3 @@
             setattr(a, "a%s" % i, i)
         cache_counter = __pypy__.method_cache_counter("x")
         assert cache_counter[0] == 0 # 0 hits, because all the attributes are new
-
-    def test_get_module_from_namedtuple(self):
-        # this used to crash
-        from collections import namedtuple
-        assert namedtuple("a", "b").__module__
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -1062,6 +1062,19 @@
         A.__dict__['x'] = 5
         assert A.x == 5
 
+
+class AppTestWithMethodCacheCounter:
+    spaceconfig = {"objspace.std.withmethodcachecounter": True}
+
+    def test_module_from_handbuilt_type(self):
+        d = {'tuple': tuple, '__name__': 'foomod'}
+        exec """class foo(tuple): pass""" in d
+        t = d['foo']
+        t.__module__ = 'barmod'
+        # this last line used to crash; see ab926f846f39
+        assert t.__module__
+
+
 class AppTestMutableBuiltintypes:
     spaceconfig = {"objspace.std.mutable_builtintypes": True}
 
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -119,6 +119,17 @@
         self.size = size or len(digits)
         self.sign = sign
 
+    # __eq__ and __ne__ method exist for testingl only, they are not RPython!
+    def __eq__(self, other):
+        # NOT_RPYTHON
+        if not isinstance(other, rbigint):
+            return NotImplemented
+        return self.eq(other)
+
+    def __ne__(self, other):
+        # NOT_RPYTHON
+        return not (self == other)
+
     def digit(self, x):
         """Return the x'th digit, as an int."""
         return self._digits[x]
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -1,14 +1,19 @@
 from __future__ import division
+
+import operator
+import sys
+from random import random, randint, sample
+
 import py
-import operator, sys, array
-from random import random, randint, sample
-from pypy.rlib.rbigint import rbigint, SHIFT, MASK, KARATSUBA_CUTOFF
-from pypy.rlib.rbigint import _store_digit, _mask_digit
-from pypy.rlib.rfloat import NAN
+
 from pypy.rlib import rbigint as lobj
 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, intmask
+from pypy.rlib.rbigint import (rbigint, SHIFT, MASK, KARATSUBA_CUTOFF,
+    _store_digit, _mask_digit)
+from pypy.rlib.rfloat import NAN
 from pypy.rpython.test.test_llinterp import interpret
 
+
 class TestRLong(object):
     def test_simple(self):
         for op1 in [-2, -1, 0, 1, 2, 50]:
@@ -112,6 +117,17 @@
         rl = rbigint.fromint(sys.maxint).add(rbigint.fromint(42))
         assert rl.touint() == result
 
+    def test_eq_ne_operators(self):
+        a1 = rbigint.fromint(12)
+        a2 = rbigint.fromint(12)
+        a3 = rbigint.fromint(123)
+
+        assert a1 == a2
+        assert a1 != a3
+        assert not (a1 != a2)
+        assert not (a1 == a3)
+
+
 def gen_signs(l):
     for s in l:
         if s == 0:


More information about the pypy-commit mailing list