[pypy-commit] pypy kill-gen-store-back-in: merge fast-slowpath

fijal noreply at buildbot.pypy.org
Sat Jul 27 20:21:46 CEST 2013


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: kill-gen-store-back-in
Changeset: r65719:90fd45e09125
Date: 2013-07-27 15:16 +0200
http://bitbucket.org/pypy/pypy/changeset/90fd45e09125/

Log:	merge fast-slowpath

diff too long, truncating to 2000 out of 4227 lines

diff --git a/lib-python/2.7/distutils/sysconfig_pypy.py b/lib-python/2.7/distutils/sysconfig_pypy.py
--- a/lib-python/2.7/distutils/sysconfig_pypy.py
+++ b/lib-python/2.7/distutils/sysconfig_pypy.py
@@ -65,6 +65,11 @@
     g['SOABI'] = g['SO'].rsplit('.')[0]
     g['LIBDIR'] = os.path.join(sys.prefix, 'lib')
     g['CC'] = "gcc -pthread" # -pthread might not be valid on OS/X, check
+    g['OPT'] = ""
+    g['CFLAGS'] = ""
+    g['CPPFLAGS'] = ""
+    g['CCSHARED'] = '-shared -O2 -fPIC -Wimplicit'
+    g['LDSHARED'] = g['CC'] + ' -shared'
 
     global _config_vars
     _config_vars = g
@@ -122,13 +127,34 @@
     optional C speedup components.
     """
     if compiler.compiler_type == "unix":
-        compiler.compiler_so.extend(['-O2', '-fPIC', '-Wimplicit'])
+        cc, opt, cflags, ccshared, ldshared = get_config_vars(
+            'CC', 'OPT', 'CFLAGS', 'CCSHARED', 'LDSHARED')
+
         compiler.shared_lib_extension = get_config_var('SO')
-        if "CFLAGS" in os.environ:
-            cflags = os.environ["CFLAGS"].split()
-            compiler.compiler.extend(cflags)
-            compiler.compiler_so.extend(cflags)
-            compiler.linker_so.extend(cflags)
+
+        if 'LDSHARED' in os.environ:
+            ldshared = os.environ['LDSHARED']
+        if 'CPP' in os.environ:
+            cpp = os.environ['CPP']
+        else:
+            cpp = cc + " -E"           # not always
+        if 'LDFLAGS' in os.environ:
+            ldshared = ldshared + ' ' + os.environ['LDFLAGS']
+        if 'CFLAGS' in os.environ:
+            cflags = opt + ' ' + os.environ['CFLAGS']
+            ldshared = ldshared + ' ' + os.environ['CFLAGS']
+        if 'CPPFLAGS' in os.environ:
+            cpp = cpp + ' ' + os.environ['CPPFLAGS']
+            cflags = cflags + ' ' + os.environ['CPPFLAGS']
+            ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
+
+        cc_cmd = cc + ' ' + cflags
+
+        compiler.set_executables(
+            preprocessor=cpp,
+            compiler=cc_cmd,
+            compiler_so=cc_cmd + ' ' + ccshared,
+            linker_so=ldshared)
 
 
 from sysconfig_cpython import (
diff --git a/lib-python/2.7/test/test_os.py b/lib-python/2.7/test/test_os.py
--- a/lib-python/2.7/test/test_os.py
+++ b/lib-python/2.7/test/test_os.py
@@ -275,7 +275,7 @@
         try:
             result.f_bfree = 1
             self.fail("No exception thrown")
-        except TypeError:
+        except (TypeError, AttributeError):
             pass
 
         try:
diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py
--- a/lib_pypy/greenlet.py
+++ b/lib_pypy/greenlet.py
@@ -1,3 +1,4 @@
+import sys
 import _continuation
 
 __version__ = "0.4.0"
@@ -5,7 +6,7 @@
 # ____________________________________________________________
 # Exceptions
 
-class GreenletExit(Exception):
+class GreenletExit(BaseException):
     """This special exception does not propagate to the parent greenlet; it
 can be used to kill a single greenlet."""
 
@@ -75,6 +76,15 @@
             # up the 'parent' explicitly.  Good enough, because a Ctrl-C
             # will show that the program is caught in this loop here.)
             target = target.parent
+            # convert a "raise GreenletExit" into "return GreenletExit"
+            if methodname == 'throw':
+                try:
+                    raise baseargs[0], baseargs[1]
+                except GreenletExit, e:
+                    methodname = 'switch'
+                    baseargs = (((e,), {}),)
+                except:
+                    baseargs = sys.exc_info()[:2] + baseargs[2:]
         #
         try:
             unbound_method = getattr(_continulet, methodname)
@@ -147,5 +157,8 @@
     _tls.current = greenlet
     try:
         raise exc, value, tb
+    except GreenletExit, e:
+        res = e
     finally:
         _continuation.permute(greenlet, greenlet.parent)
+    return ((res,), None)
diff --git a/pypy/doc/coding-guide.rst b/pypy/doc/coding-guide.rst
--- a/pypy/doc/coding-guide.rst
+++ b/pypy/doc/coding-guide.rst
@@ -626,7 +626,7 @@
 
 Here is the order in which PyPy looks up Python modules:
 
-*pypy/modules*
+*pypy/module*
 
     mixed interpreter/app-level builtin modules, such as
     the ``sys`` and ``__builtin__`` module.
@@ -657,7 +657,7 @@
 on some classes being old-style.
 
 We just maintain those changes in place,
-to see what is changed we have a branch called `vendot/stdlib`
+to see what is changed we have a branch called `vendor/stdlib`
 wich contains the unmodified cpython stdlib
 
 .. _`mixed module mechanism`:
diff --git a/pypy/doc/getting-started-dev.rst b/pypy/doc/getting-started-dev.rst
--- a/pypy/doc/getting-started-dev.rst
+++ b/pypy/doc/getting-started-dev.rst
@@ -4,6 +4,12 @@
 
 .. contents::
 
+.. warning::
+
+    Please `read this FAQ entry`_ first!
+
+.. _`read this FAQ entry`: http://doc.pypy.org/en/latest/faq.html#do-i-have-to-rewrite-my-programs-in-rpython
+
 RPython is a subset of Python that can be statically compiled. The PyPy
 interpreter is written mostly in RPython (with pieces in Python), while
 the RPython compiler is written in Python. The hard to understand part
diff --git a/pypy/doc/how-to-release.rst b/pypy/doc/how-to-release.rst
--- a/pypy/doc/how-to-release.rst
+++ b/pypy/doc/how-to-release.rst
@@ -30,7 +30,7 @@
 * update README
 * change the tracker to have a new release tag to file bugs against
 * go to pypy/tool/release and run:
-  force-builds.py /release/<release branch>
+  force-builds.py <release branch>
 * wait for builds to complete, make sure there are no failures
 * upload binaries to https://bitbucket.org/pypy/pypy/downloads
 
diff --git a/pypy/doc/release-2.1.0-beta2.rst b/pypy/doc/release-2.1.0-beta2.rst
new file mode 100644
--- /dev/null
+++ b/pypy/doc/release-2.1.0-beta2.rst
@@ -0,0 +1,60 @@
+===============
+PyPy 2.1 beta 2
+===============
+
+We're pleased to announce the second beta of the upcoming 2.1 release of PyPy.
+This beta does not add any new features to the 2.1 release, but contains several bugfixes listed below.
+
+Highlights
+==========
+
+* Fixed issue `1533`_: fix an RPython-level OverflowError for space.float_w(w_big_long_number). 
+
+* Fixed issue `1552`_: GreenletExit should inherit from BaseException
+
+* Fixed issue `1537`_: numpypy __array_interface__
+  
+* Fixed issue `1238`_: Writing to an SSL socket in pypy sometimes failed with a "bad write retry" message.
+
+* `distutils`_: copy CPython's implementation of customize_compiler, dont call
+  split on environment variables, honour CFLAGS, CPPFLAGS, LDSHARED and
+  LDFLAGS.
+
+* During packaging, compile the CFFI tk extension.
+
+.. _`1533`: https://bugs.pypy.org/issue1533
+.. _`1552`: https://bugs.pypy.org/issue1552
+.. _`1537`: https://bugs.pypy.org/issue1537
+.. _`1238`: https://bugs.pypy.org/issue1238
+.. _`distutils`: https://bitbucket.org/pypy/pypy/src/0c6eeae0316c11146f47fcf83e21e24f11378be1/?at=distutils-cppldflags
+
+
+What is PyPy?
+=============
+
+PyPy is a very compliant Python interpreter, almost a drop-in replacement for
+CPython 2.7.3. It's fast due to its integrated tracing JIT compiler.
+
+This release supports x86 machines running Linux 32/64, Mac OS X 64 or Windows
+32. Also this release supports ARM machines running Linux 32bit - anything with
+``ARMv6`` (like the Raspberry Pi) or ``ARMv7`` (like Beagleboard,
+Chromebook, Cubieboard, etc.) that supports ``VFPv3`` should work.
+
+Windows 64 work is still stalling, we would welcome a volunteer
+to handle that.
+
+How to use PyPy?
+================
+
+We suggest using PyPy from a `virtualenv`_. Once you have a virtualenv
+installed, you can follow instructions from `pypy documentation`_ on how
+to proceed. This document also covers other `installation schemes`_.
+
+.. _`pypy documentation`: http://doc.pypy.org/en/latest/getting-started.html#installing-using-virtualenv
+.. _`virtualenv`: http://www.virtualenv.org/en/latest/
+.. _`installation schemes`: http://doc.pypy.org/en/latest/getting-started.html#installing-pypy
+.. _`PyPy and pip`: http://doc.pypy.org/en/latest/getting-started.html#installing-pypy
+
+
+Cheers,
+The PyPy Team.
diff --git a/pypy/doc/rffi.rst b/pypy/doc/rffi.rst
--- a/pypy/doc/rffi.rst
+++ b/pypy/doc/rffi.rst
@@ -43,7 +43,7 @@
 See cbuild_ for more info on ExternalCompilationInfo.
 
 .. _`low level types`: rtyper.html#low-level-type
-.. _cbuild: https://bitbucket.org/pypy/pypy/src/tip/pypy/translator/tool/cbuild.py
+.. _cbuild: https://bitbucket.org/pypy/pypy/src/tip/rpython/translator/tool/cbuild.py
 
 
 Types
@@ -69,9 +69,3 @@
 as a fake low-level implementation for tests performed by an llinterp.
 
 .. _`extfunc.py`: https://bitbucket.org/pypy/pypy/src/tip/pypy/rpython/extfunc.py
-
-
-OO backends
------------
-
-XXX to be written
diff --git a/pypy/doc/whatsnew-2.1.rst b/pypy/doc/whatsnew-2.1.rst
--- a/pypy/doc/whatsnew-2.1.rst
+++ b/pypy/doc/whatsnew-2.1.rst
@@ -76,3 +76,8 @@
 
 .. branch: inline-identityhash
 Inline the fast path of id() and hash()
+
+.. branch: package-tk
+Adapt package.py script to compile CFFI tk extension. Add a --without-tk switch
+to optionally skip it.
+
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -12,3 +12,28 @@
 .. branch: improve-str2charp
 Improve the performance of I/O writing up to 15% by using memcpy instead of
 copying char-by-char in str2charp and get_nonmovingbuffer
+
+.. branch: flowoperators
+Simplify rpython/flowspace/ code by using more metaprogramming.  Create
+SpaceOperator class to gather static information about flow graph operations.
+
+.. branch: package-tk
+Adapt package.py script to compile CFFI tk extension. Add a --without-tk switch
+to optionally skip it.
+
+.. branch: distutils-cppldflags
+Copy CPython's implementation of customize_compiler, dont call split on
+environment variables, honour CFLAGS, CPPFLAGS, LDSHARED and LDFLAGS on Unices.
+
+.. branch: precise-instantiate
+When an RPython class is instantiated via an indirect call (that is, which
+class is being instantiated isn't known precisely) allow the optimizer to have
+more precise information about which functions can be called. Needed for Topaz.
+
+.. branch: ssl_moving_write_buffer
+
+.. branch: add-statvfs
+Added os.statvfs and os.fstatvfs
+
+.. branch: statvfs_tests
+Added some addition tests for statvfs.
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -196,6 +196,11 @@
     print >> sys.stderr, "Python", sys.version
     raise SystemExit
 
+
+def funroll_loops(*args):
+    print("Vroom vroom, I'm a racecar!")
+
+
 def set_jit_option(options, jitparam, *args):
     if jitparam == 'help':
         _print_jit_help()
@@ -381,6 +386,7 @@
     'Q':         (div_option,      Ellipsis),
     '--info':    (print_info,      None),
     '--jit':     (set_jit_option,  Ellipsis),
+    '-funroll-loops': (funroll_loops, None),
     '--':        (end_options,     None),
     }
 
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -370,7 +370,7 @@
         from pypy.module._pickle_support import maker # helper fns
         from pypy.interpreter.pycode import PyCode
         from pypy.interpreter.module import Module
-        args_w = space.unpackiterable(w_args)
+        args_w = space.unpackiterable(w_args, 18)
         w_f_back, w_builtin, w_pycode, w_valuestack, w_blockstack, w_exc_value, w_tb,\
             w_globals, w_last_instr, w_finished, w_f_lineno, w_fastlocals, w_f_locals, \
             w_f_trace, w_instr_lb, w_instr_ub, w_instr_prev_plus_one, w_cells = args_w
diff --git a/pypy/interpreter/test/test_zzpickle_and_slow.py b/pypy/interpreter/test/test_zzpickle_and_slow.py
--- a/pypy/interpreter/test/test_zzpickle_and_slow.py
+++ b/pypy/interpreter/test/test_zzpickle_and_slow.py
@@ -226,6 +226,10 @@
         restore_top_frame(f1, saved) 
         f2     = pickle.loads(pckl)
 
+    def test_frame_setstate_crash(self):
+        import sys
+        raises(ValueError, sys._getframe().__setstate__, [])
+
     def test_pickle_traceback(self):
         def f():
             try:
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -36,6 +36,20 @@
     }
 
 
+class IntOpModule(MixedModule):
+    appleveldefs = {}
+    interpleveldefs = {
+        'int_add':         'interp_intop.int_add',
+        'int_sub':         'interp_intop.int_sub',
+        'int_mul':         'interp_intop.int_mul',
+        'int_floordiv':    'interp_intop.int_floordiv',
+        'int_mod':         'interp_intop.int_mod',
+        'int_lshift':      'interp_intop.int_lshift',
+        'int_rshift':      'interp_intop.int_rshift',
+        'uint_rshift':     'interp_intop.uint_rshift',
+    }
+
+
 class Module(MixedModule):
     appleveldefs = {
     }
@@ -67,6 +81,7 @@
         "builders": BuildersModule,
         "time": TimeModule,
         "thread": ThreadModule,
+        "intop": IntOpModule,
     }
 
     def setup_after_space_initialization(self):
diff --git a/pypy/module/__pypy__/interp_intop.py b/pypy/module/__pypy__/interp_intop.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/interp_intop.py
@@ -0,0 +1,39 @@
+from pypy.interpreter.gateway import unwrap_spec
+from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rlib.rarithmetic import r_uint, intmask
+
+
+ at unwrap_spec(n=int, m=int)
+def int_add(space, n, m):
+    return space.wrap(llop.int_add(lltype.Signed, n, m))
+
+ at unwrap_spec(n=int, m=int)
+def int_sub(space, n, m):
+    return space.wrap(llop.int_sub(lltype.Signed, n, m))
+
+ at unwrap_spec(n=int, m=int)
+def int_mul(space, n, m):
+    return space.wrap(llop.int_mul(lltype.Signed, n, m))
+
+ at unwrap_spec(n=int, m=int)
+def int_floordiv(space, n, m):
+    return space.wrap(llop.int_floordiv(lltype.Signed, n, m))
+
+ at unwrap_spec(n=int, m=int)
+def int_mod(space, n, m):
+    return space.wrap(llop.int_mod(lltype.Signed, n, m))
+
+ at unwrap_spec(n=int, m=int)
+def int_lshift(space, n, m):
+    return space.wrap(llop.int_lshift(lltype.Signed, n, m))
+
+ at unwrap_spec(n=int, m=int)
+def int_rshift(space, n, m):
+    return space.wrap(llop.int_rshift(lltype.Signed, n, m))
+
+ at unwrap_spec(n=int, m=int)
+def uint_rshift(space, n, m):
+    n = r_uint(n)
+    x = llop.uint_rshift(lltype.Unsigned, n, m)
+    return space.wrap(intmask(x))
diff --git a/pypy/module/__pypy__/test/test_intop.py b/pypy/module/__pypy__/test/test_intop.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/test/test_intop.py
@@ -0,0 +1,104 @@
+
+
+class AppTestIntOp:
+    spaceconfig = dict(usemodules=['__pypy__'])
+
+    def w_intmask(self, n):
+        import sys
+        n &= (sys.maxsize*2+1)
+        if n > sys.maxsize:
+            n -= 2*(sys.maxsize+1)
+        return int(n)
+
+    def test_intmask(self):
+        import sys
+        assert self.intmask(sys.maxsize) == sys.maxsize
+        assert self.intmask(sys.maxsize+1) == -sys.maxsize-1
+        assert self.intmask(-sys.maxsize-2) == sys.maxsize
+        N = 2 ** 128
+        assert self.intmask(N+sys.maxsize) == sys.maxsize
+        assert self.intmask(N+sys.maxsize+1) == -sys.maxsize-1
+        assert self.intmask(N-sys.maxsize-2) == sys.maxsize
+
+    def test_int_add(self):
+        import sys
+        from __pypy__ import intop
+        assert intop.int_add(40, 2) == 42
+        assert intop.int_add(sys.maxsize, 1) == -sys.maxsize-1
+        assert intop.int_add(-2, -sys.maxsize) == sys.maxsize
+
+    def test_int_sub(self):
+        import sys
+        from __pypy__ import intop
+        assert intop.int_sub(40, -2) == 42
+        assert intop.int_sub(sys.maxsize, -1) == -sys.maxsize-1
+        assert intop.int_sub(-2, sys.maxsize) == sys.maxsize
+
+    def test_int_mul(self):
+        import sys
+        from __pypy__ import intop
+        assert intop.int_mul(40, -2) == -80
+        assert intop.int_mul(-sys.maxsize, -sys.maxsize) == (
+            self.intmask(sys.maxsize ** 2))
+
+    def test_int_floordiv(self):
+        import sys
+        from __pypy__ import intop
+        assert intop.int_floordiv(41, 3) == 13
+        assert intop.int_floordiv(41, -3) == -13
+        assert intop.int_floordiv(-41, 3) == -13
+        assert intop.int_floordiv(-41, -3) == 13
+        assert intop.int_floordiv(-sys.maxsize, -1) == sys.maxsize
+        assert intop.int_floordiv(sys.maxsize, -1) == -sys.maxsize
+
+    def test_int_mod(self):
+        import sys
+        from __pypy__ import intop
+        assert intop.int_mod(41, 3) == 2
+        assert intop.int_mod(41, -3) == 2
+        assert intop.int_mod(-41, 3) == -2
+        assert intop.int_mod(-41, -3) == -2
+        assert intop.int_mod(-sys.maxsize, -1) == 0
+        assert intop.int_mod(sys.maxsize, -1) == 0
+
+    def test_int_lshift(self):
+        import sys
+        from __pypy__ import intop
+        if sys.maxsize == 2**31-1:
+            bits = 32
+        else:
+            bits = 64
+        assert intop.int_lshift(42, 3) == 42 << 3
+        assert intop.int_lshift(0, 3333) == 0
+        assert intop.int_lshift(1, bits-2) == 1 << (bits-2)
+        assert intop.int_lshift(1, bits-1) == -sys.maxsize-1 == (-1) << (bits-1)
+        assert intop.int_lshift(-1, bits-2) == (-1) << (bits-2)
+        assert intop.int_lshift(-1, bits-1) == -sys.maxsize-1
+        assert intop.int_lshift(sys.maxsize // 3, 2) == (
+            self.intmask((sys.maxsize // 3) << 2))
+        assert intop.int_lshift(-sys.maxsize // 3, 2) == (
+            self.intmask((-sys.maxsize // 3) << 2))
+
+    def test_int_rshift(self):
+        from __pypy__ import intop
+        assert intop.int_rshift(42, 3) == 42 >> 3
+        assert intop.int_rshift(-42, 3) == (-42) >> 3
+        assert intop.int_rshift(0, 3333) == 0
+        assert intop.int_rshift(-1, 0) == -1
+        assert intop.int_rshift(-1, 1) == -1
+
+    def test_uint_rshift(self):
+        import sys
+        from __pypy__ import intop
+        if sys.maxsize == 2**31-1:
+            bits = 32
+        else:
+            bits = 64
+        N = 1 << bits
+        assert intop.uint_rshift(42, 3) == 42 >> 3
+        assert intop.uint_rshift(-42, 3) == (N-42) >> 3
+        assert intop.uint_rshift(0, 3333) == 0
+        assert intop.uint_rshift(-1, 0) == -1
+        assert intop.uint_rshift(-1, 1) == sys.maxsize
+        assert intop.uint_rshift(-1, bits-2) == 3
+        assert intop.uint_rshift(-1, bits-1) == 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
@@ -1219,6 +1219,54 @@
     for i, f in enumerate(flist):
         assert f(-142) == -142 + i
 
+def test_callback_receiving_tiny_struct():
+    BSChar = new_primitive_type("signed char")
+    BInt = new_primitive_type("int")
+    BStruct = new_struct_type("struct foo")
+    BStructPtr = new_pointer_type(BStruct)
+    complete_struct_or_union(BStruct, [('a', BSChar, -1),
+                                       ('b', BSChar, -1)])
+    def cb(s):
+        return s.a + 10 * s.b
+    BFunc = new_function_type((BStruct,), BInt)
+    f = callback(BFunc, cb)
+    p = newp(BStructPtr, [-2, -4])
+    n = f(p[0])
+    assert n == -42
+
+def test_callback_returning_tiny_struct():
+    BSChar = new_primitive_type("signed char")
+    BInt = new_primitive_type("int")
+    BStruct = new_struct_type("struct foo")
+    BStructPtr = new_pointer_type(BStruct)
+    complete_struct_or_union(BStruct, [('a', BSChar, -1),
+                                       ('b', BSChar, -1)])
+    def cb(n):
+        return newp(BStructPtr, [-n, -3*n])[0]
+    BFunc = new_function_type((BInt,), BStruct)
+    f = callback(BFunc, cb)
+    s = f(10)
+    assert typeof(s) is BStruct
+    assert repr(s) == "<cdata 'struct foo' owning 2 bytes>"
+    assert s.a == -10
+    assert s.b == -30
+
+def test_callback_receiving_struct():
+    BSChar = new_primitive_type("signed char")
+    BInt = new_primitive_type("int")
+    BDouble = new_primitive_type("double")
+    BStruct = new_struct_type("struct foo")
+    BStructPtr = new_pointer_type(BStruct)
+    complete_struct_or_union(BStruct, [('a', BSChar, -1),
+                                       ('b', BDouble, -1)])
+    def cb(s):
+        return s.a + int(s.b)
+    BFunc = new_function_type((BStruct,), BInt)
+    f = callback(BFunc, cb)
+    p = newp(BStructPtr, [-2, 44.444])
+    n = f(p[0])
+    assert n == 42
+
 def test_callback_returning_struct():
     BSChar = new_primitive_type("signed char")
     BInt = new_primitive_type("int")
@@ -1238,6 +1286,30 @@
     assert s.a == -10
     assert s.b == 1E-42
 
+def test_callback_receiving_big_struct():
+    BInt = new_primitive_type("int")
+    BStruct = new_struct_type("struct foo")
+    BStructPtr = new_pointer_type(BStruct)
+    complete_struct_or_union(BStruct, [('a', BInt, -1),
+                                       ('b', BInt, -1),
+                                       ('c', BInt, -1),
+                                       ('d', BInt, -1),
+                                       ('e', BInt, -1),
+                                       ('f', BInt, -1),
+                                       ('g', BInt, -1),
+                                       ('h', BInt, -1),
+                                       ('i', BInt, -1),
+                                       ('j', BInt, -1)])
+    def cb(s):
+        for i, name in enumerate("abcdefghij"):
+            assert getattr(s, name) == 13 - i
+        return 42
+    BFunc = new_function_type((BStruct,), BInt)
+    f = callback(BFunc, cb)
+    p = newp(BStructPtr, list(range(13, 3, -1)))
+    n = f(p[0])
+    assert n == 42
+
 def test_callback_returning_big_struct():
     BInt = new_primitive_type("int")
     BStruct = new_struct_type("struct foo")
@@ -2760,6 +2832,20 @@
     assert wr() is None
     py.test.raises(RuntimeError, from_handle, cast(BCharP, 0))
 
+def test_new_handle_cycle():
+    import _weakref
+    BVoidP = new_pointer_type(new_void_type())
+    class A(object):
+        pass
+    o = A()
+    o.cycle = newp_handle(BVoidP, o)
+    wr = _weakref.ref(o)
+    del o
+    for i in range(3):
+        if wr() is not None:
+            import gc; gc.collect()
+    assert wr() is None
+
 def _test_bitfield_details(flag):
     BChar = new_primitive_type("char")
     BShort = new_primitive_type("short")
diff --git a/pypy/module/_ffi/test/test_type_converter.py b/pypy/module/_ffi/test/test_type_converter.py
--- a/pypy/module/_ffi/test/test_type_converter.py
+++ b/pypy/module/_ffi/test/test_type_converter.py
@@ -150,7 +150,7 @@
         return self.do_and_wrap(w_ffitype)
 
 
-class TestFromAppLevel(object):
+class TestToAppLevel(object):
     spaceconfig = dict(usemodules=('_ffi',))
 
     def setup_class(cls):
diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -1107,6 +1107,14 @@
         S2E = _rawffi.Structure([('bah', (EMPTY, 1))])
         S2E.get_ffi_type()     # does not hang
 
+    def test_overflow_error(self):
+        import _rawffi
+        A = _rawffi.Array('d')
+        arg1 = A(1)
+        raises(OverflowError, "arg1[0] = 10**900")
+        arg1.free()
+
+
 class AppTestAutoFree:
     spaceconfig = dict(usemodules=['_rawffi', 'struct'])
 
diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -473,7 +473,7 @@
                     option_ptr = rffi.cast(rffi.INTP, value_ptr)
                     option_ptr[0] = space.int_w(w_option)
                 elif cmd == _c.SIO_KEEPALIVE_VALS:
-                    w_onoff, w_time, w_interval = space.unpackiterable(w_option)
+                    w_onoff, w_time, w_interval = space.unpackiterable(w_option, 3)
                     option_ptr = rffi.cast(lltype.Ptr(_c.tcp_keepalive), value_ptr)
                     option_ptr.c_onoff = space.uint_w(w_onoff)
                     option_ptr.c_keepalivetime = space.uint_w(w_time)
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -722,7 +722,10 @@
     libssl_SSL_CTX_set_verify(ss.ctx, verification_mode, None)
     ss.ssl = libssl_SSL_new(ss.ctx) # new ssl struct
     libssl_SSL_set_fd(ss.ssl, sock_fd) # set the socket for SSL
-    libssl_SSL_set_mode(ss.ssl, SSL_MODE_AUTO_RETRY)
+    # The ACCEPT_MOVING_WRITE_BUFFER flag is necessary because the address
+    # of a str object may be changed by the garbage collector.
+    libssl_SSL_set_mode(ss.ssl, 
+                        SSL_MODE_AUTO_RETRY | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER)
 
     # If the socket is in non-blocking mode or timeout mode, set the BIO
     # to non-blocking mode (blocking is the default)
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -74,7 +74,7 @@
     return space.newtuple([w_fileobj, w_filename, w_import_info])
 
 def load_module(space, w_name, w_file, w_filename, w_info):
-    w_suffix, w_filemode, w_modtype = space.unpackiterable(w_info)
+    w_suffix, w_filemode, w_modtype = space.unpackiterable(w_info, 3)
 
     filename = space.str0_w(w_filename)
     filemode = space.str_w(w_filemode)
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
@@ -679,6 +679,10 @@
         assert module.__name__ == 'a'
         assert module.__file__ == 'invalid_path_name'
 
+    def test_crash_load_module(self):
+        import imp
+        raises(ValueError, imp.load_module, "", "", "", [1, 2, 3, 4])
+
 
 class TestAbi:
     def test_abi_tag(self):
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
@@ -280,7 +280,7 @@
                                      backstrides, shape, self, orig_arr)
 
     def get_storage_as_int(self, space):
-        return rffi.cast(lltype.Signed, self.storage)
+        return rffi.cast(lltype.Signed, self.storage) + self.start
 
     def get_storage(self):
         return self.storage
diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -318,7 +318,7 @@
             if not base.issequence_w(space, w_shape):
                 w_shape = space.newtuple([w_shape,])
         else:
-            w_fldname, w_flddesc = space.fixedview(w_elem)
+            w_fldname, w_flddesc = space.fixedview(w_elem, 2)
         subdtype = descr__new__(space, space.gettypefor(W_Dtype), w_flddesc, w_shape=w_shape)
         fldname = space.str_w(w_fldname)
         if fldname in fields:
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -2212,6 +2212,11 @@
         a = a[::2]
         i = a.__array_interface__
         assert isinstance(i['data'][0], int)
+        b = array(range(9), dtype=int)
+        c = b[3:5]
+        b_data = b.__array_interface__['data'][0]
+        c_data = c.__array_interface__['data'][0]
+        assert b_data + 3 * b.dtype.itemsize == c_data
 
     def test_array_indexing_one_elem(self):
         from numpypy import array, arange
diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -17,12 +17,13 @@
     'setregid', 'setreuid', 'setsid', 'setuid', 'stat_float_times', 'statvfs',
     'statvfs_result', 'symlink', 'sysconf', 'sysconf_names', 'tcgetpgrp', 'tcsetpgrp',
     'ttyname', 'uname', 'wait', 'wait3', 'wait4'
-    ]
+]
 
 # the Win32 urandom implementation isn't going to translate on JVM or CLI so
 # we have to remove it
 lltype_only_defs.append('urandom')
 
+
 class Module(MixedModule):
     """This module provides access to operating system functionality that is
 standardized by the C Standard and the POSIX standard (a thinly
@@ -32,20 +33,21 @@
     applevel_name = os.name
 
     appleveldefs = {
-    'error'      : 'app_posix.error',
-    'stat_result': 'app_posix.stat_result',
-    'fdopen'     : 'app_posix.fdopen',
-    'tmpfile'    : 'app_posix.tmpfile',
-    'popen'      : 'app_posix.popen',
-    'tmpnam'     : 'app_posix.tmpnam',
-    'tempnam'    : 'app_posix.tempnam',
+        'error': 'app_posix.error',
+        'stat_result': 'app_posix.stat_result',
+        'statvfs_result': 'app_posix.statvfs_result',
+        'fdopen': 'app_posix.fdopen',
+        'tmpfile': 'app_posix.tmpfile',
+        'popen': 'app_posix.popen',
+        'tmpnam': 'app_posix.tmpnam',
+        'tempnam': 'app_posix.tempnam',
     }
     if os.name == 'nt':
         appleveldefs.update({
-                'popen2' : 'app_posix.popen2',
-                'popen3' : 'app_posix.popen3',
-                'popen4' : 'app_posix.popen4',
-                })
+            'popen2': 'app_posix.popen2',
+            'popen3': 'app_posix.popen3',
+            'popen4': 'app_posix.popen4',
+        })
 
     if hasattr(os, 'wait'):
         appleveldefs['wait'] = 'app_posix.wait'
@@ -53,44 +55,46 @@
         appleveldefs['wait3'] = 'app_posix.wait3'
     if hasattr(os, 'wait4'):
         appleveldefs['wait4'] = 'app_posix.wait4'
-        
+
     interpleveldefs = {
-    'open'      : 'interp_posix.open',
-    'lseek'     : 'interp_posix.lseek',
-    'write'     : 'interp_posix.write',
-    'isatty'    : 'interp_posix.isatty',
-    'read'      : 'interp_posix.read',
-    'close'     : 'interp_posix.close',
-    'closerange': 'interp_posix.closerange',
-    'fstat'     : 'interp_posix.fstat',
-    'stat'      : 'interp_posix.stat',
-    'lstat'     : 'interp_posix.lstat',
-    'stat_float_times' : 'interp_posix.stat_float_times',
-    'dup'       : 'interp_posix.dup',
-    'dup2'      : 'interp_posix.dup2',
-    'access'    : 'interp_posix.access',
-    'times'     : 'interp_posix.times',
-    'system'    : 'interp_posix.system',
-    'unlink'    : 'interp_posix.unlink',
-    'remove'    : 'interp_posix.remove',
-    'getcwd'    : 'interp_posix.getcwd',
-    'getcwdu'   : 'interp_posix.getcwdu',
-    'chdir'     : 'interp_posix.chdir',
-    'mkdir'     : 'interp_posix.mkdir',
-    'rmdir'     : 'interp_posix.rmdir',
-    'environ'   : 'interp_posix.get(space).w_environ',
-    'listdir'   : 'interp_posix.listdir',
-    'strerror'  : 'interp_posix.strerror',
-    'pipe'      : 'interp_posix.pipe',
-    'chmod'     : 'interp_posix.chmod',
-    'rename'    : 'interp_posix.rename',
-    'umask'     : 'interp_posix.umask',
-    '_exit'     : 'interp_posix._exit',
-    'utime'     : 'interp_posix.utime',
-    '_statfields': 'interp_posix.getstatfields(space)',
-    'kill'      : 'interp_posix.kill',
-    'abort'     : 'interp_posix.abort',
-    'urandom'   : 'interp_posix.urandom',
+        'open': 'interp_posix.open',
+        'lseek': 'interp_posix.lseek',
+        'write': 'interp_posix.write',
+        'isatty': 'interp_posix.isatty',
+        'read': 'interp_posix.read',
+        'close': 'interp_posix.close',
+        'closerange': 'interp_posix.closerange',
+
+        'fstat': 'interp_posix.fstat',
+        'stat': 'interp_posix.stat',
+        'lstat': 'interp_posix.lstat',
+        'stat_float_times': 'interp_posix.stat_float_times',
+
+        'dup': 'interp_posix.dup',
+        'dup2': 'interp_posix.dup2',
+        'access': 'interp_posix.access',
+        'times': 'interp_posix.times',
+        'system': 'interp_posix.system',
+        'unlink': 'interp_posix.unlink',
+        'remove': 'interp_posix.remove',
+        'getcwd': 'interp_posix.getcwd',
+        'getcwdu': 'interp_posix.getcwdu',
+        'chdir': 'interp_posix.chdir',
+        'mkdir': 'interp_posix.mkdir',
+        'rmdir': 'interp_posix.rmdir',
+        'environ': 'interp_posix.get(space).w_environ',
+        'listdir': 'interp_posix.listdir',
+        'strerror': 'interp_posix.strerror',
+        'pipe': 'interp_posix.pipe',
+        'chmod': 'interp_posix.chmod',
+        'rename': 'interp_posix.rename',
+        'umask': 'interp_posix.umask',
+        '_exit': 'interp_posix._exit',
+        'utime': 'interp_posix.utime',
+        '_statfields': 'interp_posix.getstatfields(space)',
+        'kill': 'interp_posix.kill',
+        'abort': 'interp_posix.abort',
+        'urandom': 'interp_posix.urandom',
     }
 
     if hasattr(os, 'chown'):
@@ -167,9 +171,9 @@
         interpleveldefs['getlogin'] = 'interp_posix.getlogin'
 
     for name in ['setsid', 'getuid', 'geteuid', 'getgid', 'getegid', 'setuid',
-                 'seteuid', 'setgid', 'setegid', 'getgroups', 'getpgrp', 
-                 'setpgrp', 'getppid', 'getpgid', 'setpgid', 'setreuid', 
-                 'setregid', 'getsid', 'setsid']:
+                 'seteuid', 'setgid', 'setegid', 'getgroups', 'getpgrp',
+                 'setpgrp', 'getppid', 'getpgid', 'setpgid', 'setreuid',
+                 'setregid', 'getsid', 'setsid', 'fstatvfs', 'statvfs']:
         if hasattr(os, name):
             interpleveldefs[name] = 'interp_posix.%s' % (name,)
     # not visible via os, inconsistency in nt:
@@ -177,7 +181,7 @@
         interpleveldefs['_getfullpathname'] = 'interp_posix._getfullpathname'
     if hasattr(os, 'chroot'):
         interpleveldefs['chroot'] = 'interp_posix.chroot'
-    
+
     for name in RegisterOs.w_star:
         if hasattr(os, name):
             interpleveldefs[name] = 'interp_posix.' + name
@@ -186,7 +190,7 @@
         # if it's an ootype translation, remove all the defs that are lltype
         # only
         backend = space.config.translation.backend
-        if backend == 'cli' or backend == 'jvm':
+        if backend == 'cli' or backend == 'jvm' :
             for name in lltype_only_defs:
                 self.interpleveldefs.pop(name, None)
         MixedModule.__init__(self, space, w_name)
@@ -194,7 +198,7 @@
     def startup(self, space):
         from pypy.module.posix import interp_posix
         interp_posix.get(space).startup(space)
-        
+
 for constant in dir(os):
     value = getattr(os, constant)
     if constant.isupper() and type(value) is int:
diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -65,6 +65,23 @@
         if self.st_ctime is None:
             self.__dict__['st_ctime'] = self[9]
 
+
+class statvfs_result:
+    __metaclass__ = structseqtype
+
+    name = osname + ".statvfs_result"
+
+    f_bsize = structseqfield(0)
+    f_frsize = structseqfield(1)
+    f_blocks = structseqfield(2)
+    f_bfree = structseqfield(3)
+    f_bavail = structseqfield(4)
+    f_files = structseqfield(5)
+    f_ffree = structseqfield(6)
+    f_favail = structseqfield(7)
+    f_flag = structseqfield(8)
+    f_namemax = structseqfield(9)
+
 if osname == 'posix':
     # POSIX: we want to check the file descriptor when fdopen() is called,
     # not later when we read or write data.  So we call fstat(), letting
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -1,15 +1,17 @@
-from pypy.interpreter.gateway import unwrap_spec
+import os
+import sys
+
 from rpython.rlib import rposix, objectmodel, rurandom
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rarithmetic import r_longlong
 from rpython.rlib.unroll import unrolling_iterable
+from rpython.rtyper.module import ll_os_stat
+from rpython.rtyper.module.ll_os import RegisterOs
+
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.error import OperationError, wrap_oserror, wrap_oserror2
-from rpython.rtyper.module.ll_os import RegisterOs
-from rpython.rtyper.module import ll_os_stat
 from pypy.module.sys.interp_encoding import getfilesystemencoding
 
-import os
-import sys
 
 _WIN32 = sys.platform == 'win32'
 if _WIN32:
@@ -213,6 +215,7 @@
 STAT_FIELDS = unrolling_iterable(enumerate(ll_os_stat.STAT_FIELDS))
 PORTABLE_STAT_FIELDS = unrolling_iterable(
                                  enumerate(ll_os_stat.PORTABLE_STAT_FIELDS))
+STATVFS_FIELDS = unrolling_iterable(enumerate(ll_os_stat.STATVFS_FIELDS))
 
 def build_stat_result(space, st):
     if space.config.translation.type_system == 'ootype':
@@ -253,6 +256,16 @@
                                   space.wrap('stat_result'))
     return space.call_function(w_stat_result, w_tuple, w_keywords)
 
+
+def build_statvfs_result(space, st):
+    vals_w = [None] * len(ll_os_stat.STATVFS_FIELDS)
+    for i, (name, _) in STATVFS_FIELDS:
+        vals_w[i] = space.wrap(getattr(st, name))
+    w_tuple = space.newtuple(vals_w)
+    w_statvfs_result = space.getattr(space.getbuiltinmodule(os.name), space.wrap('statvfs_result'))
+    return space.call_function(w_statvfs_result, w_tuple)
+
+
 @unwrap_spec(fd=c_int)
 def fstat(space, fd):
     """Perform a stat system call on the file referenced to by an open
@@ -314,6 +327,26 @@
     else:
         state.stat_float_times = space.bool_w(w_value)
 
+
+ at unwrap_spec(fd=c_int)
+def fstatvfs(space, fd):
+    try:
+        st = os.fstatvfs(fd)
+    except OSError as e:
+        raise wrap_oserror(space, e)
+    else:
+        return build_statvfs_result(space, st)
+
+
+def statvfs(space, w_path):
+    try:
+        st = dispatch_filename(rposix.statvfs)(space, w_path)
+    except OSError as e:
+        raise wrap_oserror2(space, e, w_path)
+    else:
+        return build_statvfs_result(space, st)
+
+
 @unwrap_spec(fd=c_int)
 def dup(space, fd):
     """Create a copy of the file descriptor.  Return the new file
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -169,7 +169,8 @@
         assert stat.S_ISDIR(st.st_mode)
 
     def test_stat_exception(self):
-        import sys, errno
+        import sys
+        import errno
         for fn in [self.posix.stat, self.posix.lstat]:
             try:
                 fn("nonexistentdir/nonexistentfile")
@@ -183,6 +184,15 @@
                     assert isinstance(e, WindowsError)
                     assert e.winerror == 3
 
+    def test_statvfs(self):
+        st = self.posix.statvfs(".")
+        assert isinstance(st, self.posix.statvfs_result)
+        for field in [
+            'f_bsize', 'f_frsize', 'f_blocks', 'f_bfree', 'f_bavail',
+            'f_files', 'f_ffree', 'f_favail', 'f_flag', 'f_namemax',
+        ]:
+            assert hasattr(st, field)
+
     def test_pickle(self):
         import pickle, os
         st = self.posix.stat(os.curdir)
diff --git a/pypy/module/pypyjit/interp_resop.py b/pypy/module/pypyjit/interp_resop.py
--- a/pypy/module/pypyjit/interp_resop.py
+++ b/pypy/module/pypyjit/interp_resop.py
@@ -125,6 +125,9 @@
         self.llbox = llbox
 
     def descr_getint(self, space):
+        if not jit_hooks.box_isint(self.llbox):
+            raise OperationError(space.w_NotImplementedError,
+                                 space.wrap("Box has no int value"))
         return space.wrap(jit_hooks.box_getint(self.llbox))
 
 @unwrap_spec(no=int)
@@ -182,7 +185,12 @@
 
     @unwrap_spec(no=int)
     def descr_getarg(self, space, no):
-        return WrappedBox(jit_hooks.resop_getarg(self.op, no))
+        try:
+            box = jit_hooks.resop_getarg(self.op, no)
+        except IndexError:
+            raise OperationError(space.w_IndexError,
+                                 space.wrap("Index out of range"))
+        return WrappedBox(box)
 
     @unwrap_spec(no=int, w_box=WrappedBox)
     def descr_setarg(self, space, no, w_box):
@@ -232,7 +240,8 @@
     getarg = interp2app(WrappedOp.descr_getarg),
     setarg = interp2app(WrappedOp.descr_setarg),
     result = GetSetProperty(WrappedOp.descr_getresult,
-                            WrappedOp.descr_setresult)
+                            WrappedOp.descr_setresult),
+    offset = interp_attrproperty("offset", cls=WrappedOp),
 )
 WrappedOp.acceptable_as_base_class = False
 
@@ -342,6 +351,10 @@
                                doc="bridge number (if a bridge)"),
     type = interp_attrproperty('type', cls=W_JitLoopInfo,
                                doc="Loop type"),
+    asmaddr = interp_attrproperty('asmaddr', cls=W_JitLoopInfo,
+                                  doc="Address of machine code"),
+    asmlen = interp_attrproperty('asmlen', cls=W_JitLoopInfo,
+                                  doc="Length of machine code"),
     __repr__ = interp2app(W_JitLoopInfo.descr_repr),
 )
 W_JitLoopInfo.acceptable_as_base_class = False
diff --git a/pypy/module/pypyjit/test/test_jit_hook.py b/pypy/module/pypyjit/test/test_jit_hook.py
--- a/pypy/module/pypyjit/test/test_jit_hook.py
+++ b/pypy/module/pypyjit/test/test_jit_hook.py
@@ -71,7 +71,7 @@
                    greenkey)
         di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                         oplist, 'loop', greenkey)
-        di_loop.asminfo = AsmInfo(offset, 0, 0)
+        di_loop.asminfo = AsmInfo(offset, 0x42, 12)
         di_bridge = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                  oplist, 'bridge', fail_descr=BasicFailDescr())
         di_bridge.asminfo = AsmInfo(offset, 0, 0)
@@ -123,6 +123,8 @@
         assert info.greenkey[2] == False
         assert info.loop_no == 0
         assert info.type == 'loop'
+        assert info.asmaddr == 0x42
+        assert info.asmlen == 12
         raises(TypeError, 'info.bridge_no')
         assert len(info.operations) == 4
         int_add = info.operations[0]
@@ -132,8 +134,10 @@
         assert dmp.greenkey == (self.f.func_code, 0, False)
         assert dmp.call_depth == 0
         assert dmp.call_id == 0
+        assert dmp.offset == -1
         assert int_add.name == 'int_add'
         assert int_add.num == self.int_add_num
+        assert int_add.offset == 0
         self.on_compile_bridge()
         expected = ('<JitLoopInfo pypyjit, 4 operations, starting at '
                     '<(%s, 0, False)>>' % repr(self.f.func_code))
@@ -160,6 +164,20 @@
         assert 'jit hook' in s.getvalue()
         assert 'ZeroDivisionError' in s.getvalue()
 
+    def test_on_compile_crashes(self):
+        import pypyjit
+        loops = []
+        def hook(loop):
+            loops.append(loop)
+        pypyjit.set_compile_hook(hook)
+        self.on_compile()
+        loop = loops[0]
+        op = loop.operations[2]
+        # Should not crash the interpreter
+        raises(IndexError, op.getarg, 2)
+        assert op.name == 'guard_nonnull'
+        raises(NotImplementedError, op.getarg(0).getint)
+
     def test_non_reentrant(self):
         import pypyjit
         l = []
diff --git a/pypy/module/rctime/test/test_rctime.py b/pypy/module/rctime/test/test_rctime.py
--- a/pypy/module/rctime/test/test_rctime.py
+++ b/pypy/module/rctime/test/test_rctime.py
@@ -43,6 +43,7 @@
         assert isinstance(res, str)
         rctime.ctime(rctime.time())
         raises(ValueError, rctime.ctime, 1E200)
+        raises(OverflowError, rctime.ctime, 10**900)
 
     def test_gmtime(self):
         import time as rctime
diff --git a/pypy/module/test_lib_pypy/support.py b/pypy/module/test_lib_pypy/support.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/support.py
@@ -0,0 +1,33 @@
+import py
+
+from pypy.conftest import option
+from pypy.interpreter.error import OperationError
+
+def import_lib_pypy(space, name, skipmsg=None):
+    """Import a top level module ensuring it's sourced from the lib_pypy
+    package.
+
+    Raises a pytest Skip on ImportError if a skip message was specified.
+    """
+    if option.runappdirect:
+        try:
+            mod = __import__('lib_pypy.' + name)
+        except ImportError as e:
+            if skipmsg is not None:
+                py.test.skip('%s (%s))' % (skipmsg, str(e)))
+            raise
+        return getattr(mod, name)
+
+    try:
+        # app-level import should find it from the right place (we
+        # assert so afterwards) as long as a builtin module doesn't
+        # overshadow it
+        failed = ("%s didn't import from lib_pypy. Is a usemodules directive "
+                  "overshadowing it?" % name)
+        importline = ("(): import %s; assert 'lib_pypy' in %s.__file__, %r; "
+                      "return %s" % (name, name, failed, name))
+        return space.appexec([], importline)
+    except OperationError as e:
+        if skipmsg is None or not e.match(space, space.w_ImportError):
+            raise
+        py.test.skip('%s (%s))' % (skipmsg, str(e)))
diff --git a/pypy/module/test_lib_pypy/test_collections.py b/pypy/module/test_lib_pypy/test_collections.py
--- a/pypy/module/test_lib_pypy/test_collections.py
+++ b/pypy/module/test_lib_pypy/test_collections.py
@@ -2,44 +2,51 @@
 Extra tests for the pure Python PyPy _collections module
 (not used in normal PyPy's)
 """
+from pypy.module.test_lib_pypy.support import import_lib_pypy
 
-from __future__ import absolute_import
-from lib_pypy import _collections as collections
-import py
 
-class TestDeque:
-    def setup_method(self, method):
-        self.n = 10
-        self.d = collections.deque(range(self.n))
+class AppTestDeque:
+
+    def setup_class(cls):
+        space = cls.space
+        cls.w_collections = import_lib_pypy(space, '_collections')
+        cls.w_n = space.wrap(10)
+
+    def w_get_deque(self):
+        return self.collections.deque(range(self.n))
 
     def test_deque(self):
-        assert len(self.d) == self.n
+        d = self.get_deque()
+        assert len(d) == self.n
         for i in range(self.n):
-            assert i == self.d[i]
+            assert i == d[i]
         for i in range(self.n-1, -1, -1):
-            assert self.d.pop() == i
-        assert len(self.d) == 0
+            assert d.pop() == i
+        assert len(d) == 0
 
     def test_deque_iter(self):
-        it = iter(self.d)
-        py.test.raises(TypeError, len, it)
+        d = self.get_deque()
+        it = iter(d)
+        raises(TypeError, len, it)
         assert it.next() == 0
-        self.d.pop()
-        py.test.raises(RuntimeError, it.next)
+        d.pop()
+        raises(RuntimeError, it.next)
 
     def test_deque_reversed(self):
-        it = reversed(self.d)
-        py.test.raises(TypeError, len, it)
+        d = self.get_deque()
+        it = reversed(d)
+        raises(TypeError, len, it)
         assert it.next() == self.n-1
         assert it.next() == self.n-2
-        self.d.pop()
-        py.test.raises(RuntimeError, it.next)
+        d.pop()
+        raises(RuntimeError, it.next)
 
     def test_deque_remove(self):
-        d = self.d
-        py.test.raises(ValueError, d.remove, "foobar")
+        d = self.get_deque()
+        raises(ValueError, d.remove, "foobar")
 
     def test_mutate_during_remove(self):
+        collections = self.collections
         # Handle evil mutator
         class MutateCmp:
             def __init__(self, deque, result):
@@ -52,24 +59,33 @@
         for match in (True, False):
             d = collections.deque(['ab'])
             d.extend([MutateCmp(d, match), 'c'])
-            py.test.raises(IndexError, d.remove, 'c')
+            raises(IndexError, d.remove, 'c')
             assert len(d) == 0
 
-class TestDequeExtra:
+class AppTestDequeExtra:
+
+    spaceconfig = dict(usemodules=('binascii', 'struct',))
+
+    def setup_class(cls):
+        cls.w_collections = import_lib_pypy(cls.space, '_collections')
+
     def test_remove_empty(self):
+        collections = self.collections
         d = collections.deque([])
-        py.test.raises(ValueError, d.remove, 1)
+        raises(ValueError, d.remove, 1)
 
     def test_remove_mutating(self):
+        collections = self.collections
         class MutatingCmp(object):
             def __eq__(self, other):
                 d.clear()
                 return True
 
         d = collections.deque([MutatingCmp()])
-        py.test.raises(IndexError, d.remove, 1)
+        raises(IndexError, d.remove, 1)
 
     def test_remove_failing(self):
+        collections = self.collections
         class FailingCmp(object):
             def __eq__(self, other):
                 assert False
@@ -77,10 +93,11 @@
         f = FailingCmp()
         d = collections.deque([1, 2, 3, f, 4, 5])
         d.remove(3)
-        py.test.raises(AssertionError, d.remove, 4)
+        raises(AssertionError, d.remove, 4)
         assert d == collections.deque([1, 2, f, 4, 5])
 
     def test_maxlen(self):
+        collections = self.collections
         d = collections.deque([], 3)
         d.append(1); d.append(2); d.append(3); d.append(4)
         assert list(d) == [2, 3, 4]
@@ -95,11 +112,13 @@
         assert repr(d3) == "deque([2, 3, 4], maxlen=3)"
 
     def test_count(self):
+        collections = self.collections
         d = collections.deque([1, 2, 2, 3, 2])
         assert d.count(2) == 3
         assert d.count(4) == 0
 
     def test_reverse(self):
+        collections = self.collections
         d = collections.deque([1, 2, 2, 3, 2])
         d.reverse()
         assert list(d) == [2, 3, 2, 2, 1]
@@ -109,6 +128,7 @@
         assert list(d) == range(99, -1, -1)
 
     def test_subclass_with_kwargs(self):
+        collections = self.collections
         class SubclassWithKwargs(collections.deque):
             def __init__(self, newarg=1):
                 collections.deque.__init__(self)
@@ -116,11 +136,13 @@
         # SF bug #1486663 -- this used to erroneously raise a TypeError
         SubclassWithKwargs(newarg=1)
 
-def foobar():
-    return list
+class AppTestDefaultDict:
 
-class TestDefaultDict:
+    def setup_class(cls):
+        cls.w_collections = import_lib_pypy(cls.space, '_collections')
+
     def test_basic(self):
+        collections = self.collections
         d1 = collections.defaultdict()
         assert d1.default_factory is None
         d1.default_factory = list
@@ -148,20 +170,23 @@
         assert 12 not in d2.keys()
         d2.default_factory = None
         assert d2.default_factory == None
-        py.test.raises(KeyError, d2.__getitem__, 15)
-        py.test.raises(TypeError, collections.defaultdict, 1)
+        raises(KeyError, d2.__getitem__, 15)
+        raises(TypeError, collections.defaultdict, 1)
 
     def test_constructor(self):
+        collections = self.collections
         assert collections.defaultdict(None) == {}
         assert collections.defaultdict(None, {1: 2}) == {1: 2}
 
     def test_missing(self):
+        collections = self.collections
         d1 = collections.defaultdict()
-        py.test.raises(KeyError, d1.__missing__, 42)
+        raises(KeyError, d1.__missing__, 42)
         d1.default_factory = list
         assert d1.__missing__(42) == []
 
     def test_repr(self):
+        collections = self.collections
         d1 = collections.defaultdict()
         assert d1.default_factory == None
         assert repr(d1) == "defaultdict(None, {})"
@@ -181,6 +206,7 @@
         assert repr(d4) == "defaultdict(%s, {14: defaultdict(None, {})})" % repr(int)
 
     def test_recursive_repr(self):
+        collections = self.collections
         # Issue2045: stack overflow when default_factory is a bound method
         class sub(collections.defaultdict):
             def __init__(self):
@@ -192,6 +218,7 @@
             "defaultdict(<bound method sub._factory of defaultdict(...")
 
     def test_copy(self):
+        collections = self.collections
         d1 = collections.defaultdict()
         d2 = d1.copy()
         assert type(d2) == collections.defaultdict
@@ -212,6 +239,9 @@
 
     def test_shallow_copy(self):
         import copy
+        collections = self.collections
+        def foobar():
+            return list
         d1 = collections.defaultdict(foobar, {1: 1})
         d2 = copy.copy(d1)
         assert d2.default_factory == foobar
@@ -223,6 +253,9 @@
 
     def test_deep_copy(self):
         import copy
+        collections = self.collections
+        def foobar():
+            return list
         d1 = collections.defaultdict(foobar, {1: [1]})
         d2 = copy.deepcopy(d1)
         assert d2.default_factory == foobar
@@ -232,4 +265,3 @@
         d2 = copy.deepcopy(d1)
         assert d2.default_factory == list
         assert d2 == d1
-
diff --git a/pypy/module/test_lib_pypy/test_ctypes_config_cache.py b/pypy/module/test_lib_pypy/test_ctypes_config_cache.py
--- a/pypy/module/test_lib_pypy/test_ctypes_config_cache.py
+++ b/pypy/module/test_lib_pypy/test_ctypes_config_cache.py
@@ -33,10 +33,8 @@
 
 
 def test_resource():
-    try:
-        import lib_pypy.resource
-    except ImportError:
-        py.test.skip('no syslog on this platform')
+    if sys.platform == 'win32':
+        py.test.skip('no resource module on this platform')
     d = run('resource.ctc.py', '_resource_cache.py')
     assert 'RLIM_NLIMITS' in d
 
diff --git a/pypy/module/test_lib_pypy/test_greenlet.py b/pypy/module/test_lib_pypy/test_greenlet.py
--- a/pypy/module/test_lib_pypy/test_greenlet.py
+++ b/pypy/module/test_lib_pypy/test_greenlet.py
@@ -341,3 +341,40 @@
         assert main.switch(3, x=5) == ((3,), {'x': 5})
         assert main.switch(3, x=5, y=6) == ((3,), {'x': 5, 'y': 6})
         assert main.switch(2, 3, x=6) == ((2, 3), {'x': 6})
+
+    def test_throw_GreenletExit_not_started(self):
+        import greenlet
+        def f():
+            never_executed
+        g = greenlet.greenlet(f)
+        e = greenlet.GreenletExit()
+        x = g.throw(e)
+        assert x is e
+
+    def test_throw_GreenletExit_already_finished(self):
+        import greenlet
+        def f():
+            pass
+        g = greenlet.greenlet(f)
+        g.switch()
+        e = greenlet.GreenletExit()
+        x = g.throw(e)
+        assert x is e
+
+    def test_throw_exception_already_finished(self):
+        import greenlet
+        def f():
+            pass
+        g = greenlet.greenlet(f)
+        g.switch()
+        seen = []
+        class MyException(Exception):
+            def __init__(self):
+                seen.append(1)
+        try:
+            g.throw(MyException)
+        except MyException:
+            pass
+        else:
+            raise AssertionError("no exception??")
+        assert seen == [1]
diff --git a/pypy/module/test_lib_pypy/test_grp_extra.py b/pypy/module/test_lib_pypy/test_grp_extra.py
--- a/pypy/module/test_lib_pypy/test_grp_extra.py
+++ b/pypy/module/test_lib_pypy/test_grp_extra.py
@@ -1,26 +1,32 @@
-from __future__ import absolute_import
-import py
-try:
-    from lib_pypy import grp
-except ImportError:
-    py.test.skip("No grp module on this platform")
+from pypy.module.test_lib_pypy.support import import_lib_pypy
 
-def test_basic():
-    g = grp.getgrnam("root")
-    assert g.gr_gid == 0
-    assert g.gr_mem == ['root'] or g.gr_mem == []
-    assert g.gr_name == 'root'
-    assert isinstance(g.gr_passwd, str)    # usually just 'x', don't hope :-)
 
-def test_extra():
-    py.test.raises(TypeError, grp.getgrnam, False)
-    py.test.raises(TypeError, grp.getgrnam, None)
+class AppTestGrp:
 
-def test_struct_group():
-    g = grp.struct_group((10, 20, 30, 40))
-    assert len(g) == 4
-    assert list(g) == [10, 20, 30, 40]
-    assert g.gr_name == 10
-    assert g.gr_passwd == 20
-    assert g.gr_gid == 30
-    assert g.gr_mem == 40
+    spaceconfig = dict(usemodules=('_ffi', '_rawffi', 'itertools'))
+
+    def setup_class(cls):
+        cls.w_grp = import_lib_pypy(cls.space, 'grp',
+                                    "No grp module on this platform")
+
+    def test_basic(self):
+        g = self.grp.getgrnam("root")
+        assert g.gr_gid == 0
+        assert g.gr_mem == ['root'] or g.gr_mem == []
+        assert g.gr_name == 'root'
+        assert isinstance(g.gr_passwd, str)    # usually just 'x', don't hope :-)
+
+    def test_extra(self):
+        grp = self.grp
+        print(grp.__file__)
+        raises(TypeError, grp.getgrnam, False)
+        raises(TypeError, grp.getgrnam, None)
+
+    def test_struct_group(self):
+        g = self.grp.struct_group((10, 20, 30, 40))
+        assert len(g) == 4
+        assert list(g) == [10, 20, 30, 40]
+        assert g.gr_name == 10
+        assert g.gr_passwd == 20
+        assert g.gr_gid == 30
+        assert g.gr_mem == 40
diff --git a/pypy/module/test_lib_pypy/test_md5_extra.py b/pypy/module/test_lib_pypy/test_md5_extra.py
--- a/pypy/module/test_lib_pypy/test_md5_extra.py
+++ b/pypy/module/test_lib_pypy/test_md5_extra.py
@@ -1,227 +1,226 @@
 """A test script to compare MD5 implementations.
 
-A note about performance: the pure Python MD5 takes roughly
-160 sec. per MB of data on a 233 MHz Intel Pentium CPU.
+A note about performance: the pure Python MD5 takes roughly 160 sec. per
+MB of data on a 233 MHz Intel Pentium CPU.
 """
+import md5
 
-from __future__ import absolute_import
-import md5                              # CPython's implementation in C.
-from lib_pypy import _md5 as pymd5  
+from pypy.module.test_lib_pypy.support import import_lib_pypy
 
 
-# Helpers...
+def compare_host(message, d2, d2h):
+    """Compare results against the host Python's builtin md5.
 
-def formatHex(str):
-    "Print a string's HEX code in groups of two digits."
-
-    d = map(None, str)
-    d = map(ord, d)
-    d = map(lambda x:"%02x" % x, d)
-    return ' '.join(d)
-
-
-def format(str):
-    "Print a string as-is in groups of two characters."
-
-    s = ''
-    for i in range(0, len(str)-1, 2):
-        s = s + "%03s" % str[i:i+2] 
-    return s[1:] 
-
-
-def printDiff(message, d1, d2, expectedResult=None):
-    "Print different outputs for same message."
-    
-    print "Message: '%s'" % message
-    print "Message length: %d" % len(message)
-    if expectedResult:
-        print "%-48s (expected)" % format(expectedResult)
-    print "%-48s (Std. lib. MD5)" % formatHex(d1)
-    print "%-48s (Pure Python MD5)" % formatHex(d2)
-    print
-
-
-# The real comparison function.
-
-def compareImp(message):
-    """Compare two MD5 implementations, C vs. pure Python module.
-
-    For equal digests this returns None, otherwise it returns
-    a tuple of both digests.
+    For equal digests this returns None, otherwise it returns a tuple of
+    both digests.
     """
-
-    # Use Python's standard library MD5 compiled C module.    
+    # Use the host Python's standard library MD5 compiled C module.
     m1 = md5.md5()
     m1.update(message)
     d1 = m1.digest()
     d1h = m1.hexdigest()
-    
-    # Use MD5 module in pure Python.
-    m2 = pymd5.new()
-    m2.update(message)
-    d2 = m2.digest()
-    d2h = m2.hexdigest()
+    # Return None if equal or the different digests if not equal.
+    return None if d1 == d2 and d1h == d2h else (d1, d2)
 
-    # Return None if equal or the different digests if not equal.
-    if d1 == d2 and d1h == d2h:
-        return
-    else:
-        return d1, d2
 
+class TestMD5Update:
 
-class TestMD5Compare:
-    "Compare pure Python MD5 against Python's std. lib. version."
-    
+    spaceconfig = dict(usemodules=('struct',))
+
+    def test_update(self):
+        """Test updating cloned objects."""
+        cases = (
+            "123",
+            "1234",
+            "12345",
+            "123456",
+            "1234567",
+            "12345678",
+            "123456789 123456789 123456789 ",
+            "123456789 123456789 ",
+            "123456789 123456789 1",
+            "123456789 123456789 12",
+            "123456789 123456789 123",
+            "123456789 123456789 1234",
+            "123456789 123456789 123456789 1",
+            "123456789 123456789 123456789 12",
+            "123456789 123456789 123456789 123",
+            "123456789 123456789 123456789 1234",
+            "123456789 123456789 123456789 12345",
+            "123456789 123456789 123456789 123456",
+            "123456789 123456789 123456789 1234567",
+            "123456789 123456789 123456789 12345678",
+            )
+        space = self.space
+        w__md5 = import_lib_pypy(space, '_md5')
+
+        # Load both with same prefix.
+        prefix1 = 2**10 * 'a'
+
+        # The host md5
+        m1 = md5.md5()
+        m1.update(prefix1)
+        m1c = m1.copy()
+
+        # The app-level _md5
+        w_m2 = space.call_method(w__md5, 'new')
+        space.call_method(w_m2, 'update', space.wrap(prefix1))
+        w_m2c = space.call_method(w_m2, 'copy')
+
+        # Update and compare...
+        for i in range(len(cases)):
+            message = cases[i][0]
+
+            m1c.update(message)
+            d1 = m1c.hexdigest()
+
+            space.call_method(w_m2c, 'update', space.wrap(message))
+            w_d2 = space.call_method(w_m2c, 'hexdigest')
+            d2 = space.str_w(w_d2)
+
+            assert d1 == d2
+
+
+class AppTestMD5Compare:
+    """Compare pure Python MD5 against Python's std. lib. version."""
+
+    spaceconfig = dict(usemodules=('struct',))
+
+    def setup_class(cls):
+        from pypy.interpreter import gateway
+        space = cls.space
+        cls.w__md5 = import_lib_pypy(space, '_md5')
+        if cls.runappdirect:
+            # interp2app doesn't work in appdirect mode
+            cls.w_compare_host = staticmethod(compare_host)
+        else:
+            compare_host.unwrap_spec = [str, str, str]
+            cls.w_compare_host = space.wrap(gateway.interp2app(compare_host))
+
+    def w_compare(self, message):
+        # Generate results against the app-level pure Python MD5 and
+        # pass them off for comparison against the host Python's MD5
+        m2 = self._md5.new()
+        m2.update(message)
+        return self.compare_host(message, m2.digest(), m2.hexdigest())
+
+    def w__format_hex(self, string):
+        """Print a string's HEX code in groups of two digits."""
+        d = map(None, string)
+        d = map(ord, d)
+        d = map(lambda x: "%02x" % x, d)
+        return ' '.join(d)
+
+    def w__format(self, string):
+        """Print a string as-is in groups of two characters."""
+        s = ''
+        for i in range(0, len(string) - 1, 2):
+            s = s + "%03s" % string[i:i + 2]
+        return s[1:]
+
+    def w_print_diff(self, message, d1, d2, expectedResult=None):
+        """Print different outputs for same message."""
+        print("Message: '%s'" % message)
+        print("Message length: %d" % len(message))
+        if expectedResult:
+            print("%-48s (expected)" % self._format(expectedResult))
+        print("%-48s (Std. lib. MD5)" % self._format_hex(d1))
+        print("%-48s (Pure Python MD5)" % self._format_hex(d2))
+        print()
+
     def test1(self):
-        "Test cases with known digest result."
-        
+        """Test cases with known digest result."""
         cases = (
-          ("",
-           "d41d8cd98f00b204e9800998ecf8427e"),
-          ("a",
-           "0cc175b9c0f1b6a831c399e269772661"),
-          ("abc",
-           "900150983cd24fb0d6963f7d28e17f72"),
-          ("message digest",
-           "f96b697d7cb7938d525a2f31aaf161d0"),
-          ("abcdefghijklmnopqrstuvwxyz",
-           "c3fcd3d76192e4007dfb496cca67e13b"),
-          ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
-           "d174ab98d277d9f5a5611c2c9f419d9f"),
-          ("1234567890"*8,
-           "57edf4a22be3c955ac49da2e2107b67a"),
-        )
+            ("",
+             "d41d8cd98f00b204e9800998ecf8427e"),
+            ("a",
+             "0cc175b9c0f1b6a831c399e269772661"),
+            ("abc",
+             "900150983cd24fb0d6963f7d28e17f72"),
+            ("message digest",
+             "f96b697d7cb7938d525a2f31aaf161d0"),
+            ("abcdefghijklmnopqrstuvwxyz",
+             "c3fcd3d76192e4007dfb496cca67e13b"),
+            ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+             "d174ab98d277d9f5a5611c2c9f419d9f"),
+            ("1234567890"*8,
+             "57edf4a22be3c955ac49da2e2107b67a"),
+            )
 
-        for i in xrange(len(cases)):
-            res = compareImp(cases[i][0])
+        for i in range(len(cases)):
+            res = self.compare(cases[i][0])
             if res is not None:
                 d1, d2 = res
                 message, expectedResult = cases[i][0], None
                 if len(cases[i]) == 2:
                     expectedResult = cases[i][1]
-                printDiff(message, d1, d2, expectedResult)
+                self.print_diff(message, d1, d2, expectedResult)
             assert res is None
 
+    def test2(self):
+        """Test cases without known digest result."""
+        cases = (
+            "123",
+            "1234",
+            "12345",
+            "123456",
+            "1234567",
+            "12345678",
+            "123456789 123456789 123456789 ",
+            "123456789 123456789 ",
+            "123456789 123456789 1",
+            "123456789 123456789 12",
+            "123456789 123456789 123",
+            "123456789 123456789 1234",
+            "123456789 123456789 123456789 1",
+            "123456789 123456789 123456789 12",
+            "123456789 123456789 123456789 123",
+            "123456789 123456789 123456789 1234",
+            "123456789 123456789 123456789 12345",
+            "123456789 123456789 123456789 123456",
+            "123456789 123456789 123456789 1234567",
+            "123456789 123456789 123456789 12345678",
+            )
 
-    def test2(self):
-        "Test cases without known digest result."
-        
-        cases = (
-          "123",
-          "1234",
-          "12345",
-          "123456",
-          "1234567",
-          "12345678",
-          "123456789 123456789 123456789 ",
-          "123456789 123456789 ",
-          "123456789 123456789 1",
-          "123456789 123456789 12",
-          "123456789 123456789 123",
-          "123456789 123456789 1234",
-          "123456789 123456789 123456789 1",
-          "123456789 123456789 123456789 12",
-          "123456789 123456789 123456789 123",
-          "123456789 123456789 123456789 1234",
-          "123456789 123456789 123456789 12345",
-          "123456789 123456789 123456789 123456",
-          "123456789 123456789 123456789 1234567",
-          "123456789 123456789 123456789 12345678",
-         )
-
-        for i in xrange(len(cases)):
-            res = compareImp(cases[i][0])
+        for i in range(len(cases)):
+            res = self.compare(cases[i][0])
             if res is not None:
                 d1, d2 = res
                 message = cases[i][0]
-                printDiff(message, d1, d2)
+                self.print_diff(message, d1, d2)
             assert res is None
 
+    def test3(self):
+        """Test cases with long messages (can take a while)."""
+        cases = (
+            (2**10*'a',),
+            (2**10*'abcd',),
+            #(2**20*'a',),  # 1 MB, takes about 160 sec. on a 233 Mhz Pentium.
+            )
 
-    def test3(self):
-        "Test cases with long messages (can take a while)."
-        
-        cases = (
-          (2**10*'a',),
-          (2**10*'abcd',),
-##          (2**20*'a',),  ## 1 MB, takes about 160 sec. on a 233 Mhz Pentium.
-         )
-
-        for i in xrange(len(cases)):
-            res = compareImp(cases[i][0])
+        for i in range(len(cases)):
+            res = self.compare(cases[i][0])
             if res is not None:
                 d1, d2 = res
                 message = cases[i][0]
-                printDiff(message, d1, d2)
+                self.print_diff(message, d1, d2)
             assert res is None
 
-
     def test4(self):
-        "Test cases with increasingly growing message lengths."
-
+        """Test cases with increasingly growing message lengths."""
         i = 0
-        while i  < 2**5:
+        while i < 2**5:
             message = i * 'a'
-            res = compareImp(message)
+            res = self.compare(message)
             if res is not None:
                 d1, d2 = res
-                printDiff(message, d1, d2)
+                self.print_diff(message, d1, d2)
             assert res is None
-            i = i + 1
+            i += 1
 
-
-    def test5(self):
-        "Test updating cloned objects."
-
-        cases = (
-          "123",
-          "1234",
-          "12345",
-          "123456",
-          "1234567",
-          "12345678",
-          "123456789 123456789 123456789 ",
-          "123456789 123456789 ",
-          "123456789 123456789 1",
-          "123456789 123456789 12",
-          "123456789 123456789 123",
-          "123456789 123456789 1234",
-          "123456789 123456789 123456789 1",
-          "123456789 123456789 123456789 12",
-          "123456789 123456789 123456789 123",
-          "123456789 123456789 123456789 1234",
-          "123456789 123456789 123456789 12345",
-          "123456789 123456789 123456789 123456",
-          "123456789 123456789 123456789 1234567",
-          "123456789 123456789 123456789 12345678",
-         )
-
-        # Load both with same prefix.    
-        prefix1 = 2**10 * 'a'
-
-        m1 = md5.md5()
-        m1.update(prefix1)
-        m1c = m1.copy()
-
-        m2 = pymd5.new()
-        m2.update(prefix1)
-        m2c = m2.copy()
-
-        # Update and compare...
-        for i in xrange(len(cases)):
-            message = cases[i][0]
-
-            m1c.update(message)
-            d1 = m1c.hexdigest()
-
-            m2c.update(message)
-            d2 = m2c.hexdigest()
-
-            assert d1 == d2
-
-
-def test_attributes():
-    assert pymd5.digest_size == 16
-    assert pymd5.new().digest_size == 16
-    assert pymd5.new().digestsize == 16
-    assert pymd5.new().block_size == 64
+    def test_attributes(self):
+        _md5 = self._md5
+        assert _md5.digest_size == 16
+        assert _md5.new().digest_size == 16
+        assert _md5.new().digestsize == 16
+        assert _md5.new().block_size == 64
diff --git a/pypy/module/test_lib_pypy/test_os_wait.py b/pypy/module/test_lib_pypy/test_os_wait.py
--- a/pypy/module/test_lib_pypy/test_os_wait.py
+++ b/pypy/module/test_lib_pypy/test_os_wait.py
@@ -1,18 +1,29 @@
 # Generates the resource cache (it might be there already, but maybe not)
 from __future__ import absolute_import
-from lib_pypy.ctypes_config_cache import rebuild
-rebuild.rebuild_one('resource.ctc.py')
-
 import os
 
-if hasattr(os, 'wait3'):
-    from lib_pypy._pypy_wait import wait3
-    def test_os_wait3():
+import py
+
+from lib_pypy.ctypes_config_cache import rebuild
+from pypy.module.test_lib_pypy.support import import_lib_pypy
+


More information about the pypy-commit mailing list