1. Pypy
  2. Untitled project
  3. pypy

Commits

Amaury Forgeot d'Arc  committed 814d7c7 Merge

hg merge default

  • Participants
  • Parent commits e2e5c86, 5fcd51b
  • Branches py3k

Comments (0)

Files changed (67)

File pypy/doc/whatsnew-head.rst

View file
  • Ignore whitespace
 
 .. branch: length-hint
 Implement __lenght_hint__ according to PEP 424
-   
+
 .. branches we don't care about
 .. branch: autoreds
 
 .. branch: release-2.0-beta1
 
 .. branch: remove-PYPY_NOT_MAIN_FILE
+
+.. branch: fix-lookinside-iff-oopspec
+Fixed the interaction between two internal tools for controlling the JIT.

File pypy/interpreter/baseobjspace.py

View file
  • Ignore whitespace
-from pypy.interpreter.executioncontext import ExecutionContext, ActionFlag
-from pypy.interpreter.executioncontext import UserDelAction, FrameTraceAction
-from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.error import new_exception_class, typed_unwrap_error_msg
+import sys
+
+from pypy.interpreter.executioncontext import (ExecutionContext, ActionFlag,
+    UserDelAction, FrameTraceAction)
+from pypy.interpreter.error import (OperationError, operationerrfmt,
+    new_exception_class, typed_unwrap_error_msg)
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.miscutils import ThreadLocals
 from pypy.tool.cache import Cache
 from pypy.tool.uid import HUGEVAL_BYTES
+from pypy.rlib import jit
+from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib.objectmodel import we_are_translated, newlist_hint,\
      compute_unique_id
-from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib.rarithmetic import r_uint
-from pypy.rlib import jit
-import os, sys
+
 
 __all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
 
         for name, w_type in types_w:
             self.setitem(self.builtin.w_dict, self.wrap(name), w_type)
 
-        # install mixed and faked modules
+        # install mixed modules
         for mixedname in self.get_builtinmodule_to_install():
-            if (mixedname not in bootstrap_modules
-                and not mixedname.startswith('faked+')):
+            if mixedname not in bootstrap_modules:
                 self.install_mixedmodule(mixedname, installed_builtin_modules)
-        for mixedname in self.get_builtinmodule_to_install():
-            if mixedname.startswith('faked+'):
-                modname = mixedname[6:]
-                self.install_faked_module(modname, installed_builtin_modules)
 
         installed_builtin_modules.sort()
         w_builtin_module_names = self.newtuple(
                 "app-level module %r" % (modname,))
             installed_builtin_modules.append(modname)
 
-    def load_cpython_module(self, modname):
-        "NOT_RPYTHON. Steal a module from CPython."
-        cpy_module = __import__(modname, {}, {}, ['*'])
-        return cpy_module
-
-    def install_faked_module(self, modname, installed_builtin_modules):
-        """NOT_RPYTHON"""
-        if modname in installed_builtin_modules:
-            return
-        try:
-            module = self.load_cpython_module(modname)
-        except ImportError:
-            return
-        else:
-            w_modules = self.sys.get('modules')
-            self.setitem(w_modules, self.wrap(modname), self.wrap(module))
-            installed_builtin_modules.append(modname)
-
     def setup_builtin_modules(self):
         "NOT_RPYTHON: only for initializing the space."
         if self.config.objspace.usemodules.cpyext:

File pypy/interpreter/pycode.py

View file
  • Ignore whitespace
 
     @classmethod
     def _from_code(cls, space, code, hidden_applevel=False, code_hook=None):
-        """ Initialize the code object from a real (CPython) one.
-            This is just a hack, until we have our own compile.
-            At the moment, we just fake this.
-            This method is called by our compile builtin function.
+        """
+        Hack to initialize the code object from a real (CPython) one.
         """
         assert isinstance(code, types.CodeType)
         newconsts_w = [None] * len(code.co_consts)
                       list(code.co_cellvars),
                       hidden_applevel, cpython_magic)
 
-
     def _compute_flatcall(self):
         # Speed hack!
         self.fast_natural_arity = eval.Code.HOPELESS

File pypy/interpreter/test/test_main.py

View file
  • Ignore whitespace
 
 testresultoutput = '11\n'
 
-def checkoutput(space, expected_output,f,*args):
+
+def checkoutput(space, expected_output, f, *args):
     w_oldout = space.sys.get('stdout')
     capturefn = udir.join('capturefile')
-    capturefile = capturefn.open('w')
+    w_capturefile = space.call_method(space.builtin, "open", space.wrap(str(capturefn)), space.wrap("w"))
     w_sys = space.sys.getmodule('sys')
-    space.setattr(w_sys, space.wrap("stdout"), space.wrap(capturefile))
+    space.setattr(w_sys, space.wrap("stdout"), w_capturefile)
     try:
         f(*(args + (space,)))
     finally:
         space.setattr(w_sys, space.wrap("stdout"), w_oldout)
-    capturefile.close()
+    space.call_method(w_capturefile, "close")
     assert capturefn.read(mode='rU') == expected_output
 
 testfn = udir.join('tmp_hello_world.py')

File pypy/interpreter/test/test_objspace.py

View file
  • Ignore whitespace
 
 class TestModuleMinimal: 
     def test_sys_exists(self):
-        assert self.space.sys 
+        assert self.space.sys
 
     def test_import_exists(self):
         space = self.space
-        assert space.builtin 
+        assert space.builtin
         w_name = space.wrap('__import__')
         w_builtin = space.sys.getmodule('builtins')
-        w_import = self.space.getattr(w_builtin, w_name) 
+        w_import = self.space.getattr(w_builtin, w_name)
         assert space.is_true(w_import)
 
     def test_sys_import(self):
         from pypy.interpreter.main import run_string
         run_string('import sys', space=self.space)
 
-    def test_get_builtinmodule_to_install(self):
-        space = self.space
-        try:
-            # force rebuilding with this fake builtin
-            space.ALL_BUILTIN_MODULES.append('this_doesnt_exist')
-            del space._builtinmodule_list
-            mods = space.get_builtinmodule_to_install()
-            
-            assert '__pypy__' in mods                # real builtin
-            assert '_functools' not in mods               # in lib_pypy
-            assert 'faked+_functools' not in mods         # in lib_pypy
-            assert 'this_doesnt_exist' not in mods   # not in lib_pypy
-            assert 'faked+this_doesnt_exist' in mods # not in lib_pypy, but in
-                                                     # ALL_BUILTIN_MODULES
-        finally:
-            # rebuild the original list
-            space.ALL_BUILTIN_MODULES.pop()
-            del space._builtinmodule_list
-            mods = space.get_builtinmodule_to_install()
-
     def test_dont_reload_builtin_mods_on_startup(self):
         from pypy.tool.option import make_config, make_objspace
         config = make_config(None)

File pypy/interpreter/test/test_zzpickle_and_slow.py

View file
  • Ignore whitespace
     space.delitem(space.builtin.w_dict,
                   space.wrap('restore_top_frame'))
 
+
 class AppTestInterpObjectPickling:
     pytestmark = py.test.mark.skipif("config.option.runappdirect")
-    spaceconfig = dict(usemodules=['struct'])
+    spaceconfig = {
+        "usemodules": ["struct", "binascii"]
+    }
 
     def setup_class(cls):
         _attach_helpers(cls.space)

File pypy/interpreter/typedef.py

View file
  • Ignore whitespace
         self.rawdict = {}
         self.acceptable_as_base_class = '__new__' in rawdict
         self.applevel_subclasses_base = None
-        # xxx used by faking
-        self.fakedcpytype = None
         self.add_entries(**rawdict)
         assert __total_ordering__ in (None, 'auto'), "Unknown value for __total_ordering"
         if __total_ordering__ == 'auto':

File pypy/jit/codewriter/test/test_codewriter.py

View file
  • Ignore whitespace
 import py
+
+from pypy.jit.codewriter import support
 from pypy.jit.codewriter.codewriter import CodeWriter
-from pypy.jit.codewriter import support
 from pypy.jit.metainterp.history import AbstractDescr
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
+from pypy.translator.backendopt.all import backend_optimizations
+
 
 class FakeCallDescr(AbstractDescr):
     def __init__(self, FUNC, ARGS, RESULT, effectinfo):
     rtyper = support.annotate(f, [-1])
     jitdriver_sd = FakeJitDriverSD(rtyper.annotator.translator.graphs[0])
     cw = CodeWriter(FakeCPU(rtyper), [jitdriver_sd])
-    cw.find_all_graphs(FakePolicy())
+    graphs = cw.find_all_graphs(FakePolicy())
+    backend_optimizations(rtyper.annotator.translator, graphs=graphs)
     cw.make_jitcodes(verbose=True)
     s = jitdriver_sd.mainjitcode.dump()
     assert 'int_force_ge_zero' in s

File pypy/module/__pypy__/__init__.py

View file
  • Ignore whitespace
     def setup_after_space_initialization(self):
         """NOT_RPYTHON"""
         if not self.space.config.translating:
-            self.extra_interpdef('isfake', 'interp_magic.isfake')
             self.extra_interpdef('interp_pdb', 'interp_magic.interp_pdb')
         if self.space.config.objspace.std.withmethodcachecounter:
             self.extra_interpdef('method_cache_counter',

File pypy/module/__pypy__/interp_magic.py

View file
  • Ignore whitespace
 from pypy.objspace.std.mapdict import IndexCache
 from pypy.rlib import rposix
 
+
 def internal_repr(space, w_object):
     return space.wrap('%r' % (w_object,))
 
-def isfake(space, w_obj):
-    """Return whether the argument is faked (stolen from CPython). This is
-    always False after translation."""
-    if we_are_translated():
-        return space.w_False
-    return space.wrap(bool(w_obj.typedef.fakedcpytype))
-    #return space.wrap(bool(getattr(w_obj.typedef, 'fakedcpytype', None)))
 
 def interp_pdb(space):
     """Run an interp-level pdb.
     import pdb
     pdb.set_trace()
 
+
 @unwrap_spec(name=str)
 def method_cache_counter(space, name):
     """Return a tuple (method_cache_hits, method_cache_misses) for calls to

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

View file
  • Ignore whitespace
 import py
+
+from pypy.interpreter.gateway import interp2app
 from pypy.rlib import debug
 
+
 class AppTestDebug:
     spaceconfig = dict(usemodules=['__pypy__'])
 
     def setup_class(cls):
         if cls.runappdirect:
             py.test.skip("not meant to be run with -A")
-        cls.w_check_log = cls.space.wrap(cls.check_log)
+        cls.w_check_log = cls.space.wrap(interp2app(cls.check_log))
 
     def setup_method(self, meth):
         debug._log = debug.DebugLog()
     def teardown_method(self, meth):
         debug._log = None
 
-    @classmethod
-    def check_log(cls, expected):
-        assert list(debug._log) == expected
+    @staticmethod
+    def check_log(space, w_expected):
+        assert list(debug._log) == space.unwrap(w_expected)
 
     def test_debug_print(self):
         from __pypy__ import debug_start, debug_stop, debug_print

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

View file
  • Ignore whitespace
         if cls.runappdirect:
             py.test.skip("does not make sense on pypy-c")
 
-    def test__isfake(self):
-        from __pypy__ import isfake
-        assert not isfake(map)
-        assert not isfake(object)
-        assert not isfake(isfake)
-
-    def test__isfake_currently_true(self):
-        from __pypy__ import isfake
-        import select
-        assert isfake(select)
-
     def test_cpumodel(self):
         import __pypy__
         assert hasattr(__pypy__, 'cpumodel')

File pypy/module/_ast/test/test_ast.py

View file
  • Ignore whitespace
 import py
 
+
 class AppTestAST:
-    spaceconfig = dict(usemodules=['struct'])
+    spaceconfig = {
+        "usemodules": ['struct', 'binascii'],
+    }
 
     def setup_class(cls):
         cls.w_ast = cls.space.getbuiltinmodule('_ast')

File pypy/module/_codecs/test/test_codecs.py

View file
  • Ignore whitespace
 
 
 class AppTestCodecs:
-    spaceconfig = dict(usemodules=('binascii', 'struct', 'unicodedata'))
+    spaceconfig = {
+        "usemodules": ['unicodedata', 'struct', 'binascii'],
+    }
 
     def test_register_noncallable(self):
         import _codecs
     def test_ucs4(self):
         x = '\U00100000'
         y = x.encode("raw-unicode-escape").decode("raw-unicode-escape")
-        assert x == y 
+        assert x == y
 
     def test_named_unicode(self):
         assert str(b'\\N{SPACE}','unicode-escape') == " "

File pypy/module/_continuation/test/test_zpickle.py

View file
  • Ignore whitespace
 
 class AppTestPickle:
     version = 0
-    spaceconfig = dict(usemodules=['_continuation', 'struct'],
-                       continuation=True,
-                       CALL_METHOD=True)
+    spaceconfig = {
+        "usemodules": ['_continuation', 'struct', 'binascii'],
+        "continuation": True,
+        "CALL_METHOD": True,
+    }
 
     def setup_class(cls):
         py.test.py3k_skip("_continuation not supported yet")

File pypy/module/_ffi/test/test_struct.py

View file
  • Ignore whitespace
-import sys
+from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.module._ffi.interp_ffitype import app_types, W_FFIType
+from pypy.module._ffi.interp_struct import compute_size_and_alignement, W_Field
 from pypy.module._ffi.test.test_funcptr import BaseAppTestFFI
-from pypy.module._ffi.interp_struct import compute_size_and_alignement, W_Field
-from pypy.module._ffi.interp_ffitype import app_types, W_FFIType
 
 
 class TestStruct(object):
         assert self.sizeof([T.slonglong, T.sbyte, T.sbyte, T.sbyte]) == llong_size + llong_align
         assert self.sizeof([T.slonglong, T.sbyte, T.sbyte, T.sbyte, T.sbyte]) == llong_size + llong_align
 
+
 class AppTestStruct(BaseAppTestFFI):
 
     def setup_class(cls):
         BaseAppTestFFI.setup_class.im_func(cls)
-        #
-        def read_raw_mem(self, addr, typename, length):
+
+        @unwrap_spec(addr=int, typename=str, length=int)
+        def read_raw_mem(space, addr, typename, length):
             import ctypes
             addr = ctypes.cast(addr, ctypes.c_void_p)
             c_type = getattr(ctypes, typename)
             ptr_array = ctypes.cast(addr, array_type)
             array = ptr_array[0]
             lst = [array[i] for i in range(length)]
-            return lst
-        cls.w_read_raw_mem = cls.space.wrap(read_raw_mem)
+            return space.wrap(lst)
+        cls.w_read_raw_mem = cls.space.wrap(interp2app(read_raw_mem))
         #
         from pypy.rlib import clibffi
         from pypy.rlib.rarithmetic import r_uint

File pypy/module/_hashlib/test/test_hashlib.py

View file
  • Ignore whitespace
-import py
-
 class AppTestHashlib:
-    spaceconfig = dict(usemodules=['_hashlib', 'array', 'struct'])
+    spaceconfig = {
+        "usemodules": ['_hashlib', 'array', 'struct', 'binascii'],
+    }
 
     def test_method_names(self):
         import _hashlib

File pypy/module/_lsprof/test/test_cprofile.py

View file
  • Ignore whitespace
 class AppTestCProfile(object):
-    spaceconfig = dict(usemodules=('_lsprof',))
+    spaceconfig = {
+        "usemodules": ['_lsprof', 'rctime'],
+    }
 
     def setup_class(cls):
         cls.w_expected_output = cls.space.wrap(expected_output)

File pypy/module/_md5/test/test_md5.py

View file
  • Ignore whitespace
         """
         assert self.md5.md5().digest_size == 16
 
-
     def test_MD5Type(self):
         """
         Test the construction of an md5 object.
         md5 = self.md5
         d = md5.md5()
 
-
     def test_md5object(self):
         """
         Feed example strings into a md5 object and check the digest and
            "c3fcd3d76192e4007dfb496cca67e13b"),
           (b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
            "d174ab98d277d9f5a5611c2c9f419d9f"),
-          (b"1234567890"*8,
+          (b"1234567890" * 8,
            "57edf4a22be3c955ac49da2e2107b67a"),
         )
         for input, expected in cases:
             assert d.hexdigest() == expected
             assert d.digest() == binascii.unhexlify(expected.encode('ascii'))
 
-
     def test_copy(self):
         """
         Test the copy() method.
         assert d1.hexdigest() == 'e570e7110ecef72fcb772a9c05d03373'
         assert d2.hexdigest() == 'e8dc4081b13434b45189a720b77b6818'
 
-
     def test_buffer(self):
         """
         Test passing a buffer object.
         d1.update(memoryview(b"jkl"))
         assert d1.hexdigest() == 'e570e7110ecef72fcb772a9c05d03373'
 
-
     def test_unicode(self):
         """
         Test passing unicode strings.

File pypy/module/_multiprocessing/test/test_connection.py

View file
  • Ignore whitespace
 
         return multiprocessing.Pipe(duplex=False)
 
+
 class AppTestSocketConnection(BaseConnectionTest):
-    spaceconfig = dict(usemodules=('_multiprocessing', 'thread', 'signal',
-                                   'struct', 'array', '_socket'))
+    spaceconfig = {
+        "usemodules": [
+            '_multiprocessing', 'thread', 'signal', 'struct', 'array',
+            '_socket', 'binascii',
+        ]
+    }
+
     def setup_class(cls):
         cls.w_connections = cls.space.newlist([])
 
-        def socketpair(space):
-            "A socket.socketpair() that works on Windows"
-            import socket, errno
-            serverSocket = socket.socket()
-            serverSocket.bind(('127.0.0.1', 0))
-            serverSocket.listen(1)
+    def w_socketpair(self):
+        "A socket.socketpair() that works on Windows"
+        import errno
+        import socket
 
-            client = socket.socket()
-            client.setblocking(False)
-            try:
-                client.connect(('127.0.0.1', serverSocket.getsockname()[1]))
-            except socket.error, e:
-                assert e.args[0] in (errno.EINPROGRESS, errno.EWOULDBLOCK)
-            server, addr = serverSocket.accept()
+        serverSocket = socket.socket()
+        serverSocket.bind(('127.0.0.1', 0))
+        serverSocket.listen(1)
 
-            # keep sockets alive during the test
-            space.call_method(cls.w_connections, "append", space.wrap(server))
-            space.call_method(cls.w_connections, "append", space.wrap(client))
+        client = socket.socket()
+        client.setblocking(False)
+        try:
+            client.connect(('127.0.0.1', serverSocket.getsockname()[1]))
+        except socket.error, e:
+            assert e.args[0] in (errno.EINPROGRESS, errno.EWOULDBLOCK)
+        server, addr = serverSocket.accept()
 
-            return space.wrap((server.fileno(), client.fileno()))
-        if cls.runappdirect:
-            cls.w_socketpair = lambda self: socketpair(cls.space)
-        else:
-            cls.w_socketpair = cls.space.wrap(interp2app(socketpair))
+        # keep sockets alive during the test
+        self.connections.append(server)
+        self.connections.append(client)
+
+        return server.fileno(), client.fileno()
 
     def w_make_pair(self):
         import _multiprocessing
-        import os
 
         fd1, fd2 = self.socketpair()
         rhandle = _multiprocessing.Connection(fd1, writable=False)
         assert data1 == b'\x00\x00\x00\x03abc'
         data2 = sock.recv(8)
         assert data2 == b'\x00\x00\x00\x04defg'
-

File pypy/module/_random/test/test_random.py

View file
  • Ignore whitespace
 class AppTestRandom:
-    spaceconfig = dict(usemodules=['_random'])
+    spaceconfig = {
+        "usemodules": ['_random', 'rctime'],
+    }
 
     def test_dict(self):
         import _random

File pypy/module/_ssl/test/test_ssl.py

View file
  • Ignore whitespace
 
 
 class AppTestConnectedSSL:
-    spaceconfig = dict(usemodules=('_ssl', '_socket', 'struct', 'array'))
+    spaceconfig = {
+        "usemodules": ['_ssl', '_socket', 'struct', 'array', 'binascii'],
+    }
 
     def setup_method(self, method):
         # https://www.verisign.net/

File pypy/module/array/test/test_array.py

View file
  • Ignore whitespace
         cls.tempfile = str(py.test.ensuretemp('array').join('tmpfile'))
         cls.maxint = sys.maxint
 
+
 class AppTestArray(BaseArrayTests):
-    spaceconfig = dict(usemodules=('array', 'struct', '_rawffi'))
+    spaceconfig = {'usemodules': ['array', 'struct', '_rawffi', 'binascii']}
 
     def setup_class(cls):
         cls.w_array = cls.space.appexec([], """():
         cls.w_tempfile = cls.space.wrap(
             str(py.test.ensuretemp('array').join('tmpfile')))
         cls.w_maxint = cls.space.wrap(sys.maxint)
-    
+
     def test_buffer_info(self):
         a = self.array('b', b'Hi!')
         bi = a.buffer_info()

File pypy/module/array/test/test_array_old.py

View file
  • Ignore whitespace
 
 
 class AppTestArray(BaseArrayTests):
-    spaceconfig = dict(usemodules=['struct', 'array'])
+    spaceconfig = {'usemodules': ['struct', 'array', 'binascii']}
 
     def setup_class(cls):
         """Import the array module and make it available as self.array."""

File pypy/module/bz2/test/test_bz2_compdecomp.py

View file
  • Ignore whitespace
+import os
+
+import py
+
+from pypy.interpreter.gateway import interp2app
 from pypy.module.bz2.test.support import CheckAllocation
 from pypy.module.bz2 import interp_bz2
 from pypy.interpreter.gateway import interp2app
 def setup_module(mod):
     DATA = 'BZh91AY&SY.\xc8N\x18\x00\x01>_\x80\x00\x10@\x02\xff\xf0\x01\x07n\x00?\xe7\xff\xe00\x01\x99\xaa\x00\xc0\x03F\x86\x8c#&\x83F\x9a\x03\x06\xa6\xd0\xa6\x93M\x0fQ\xa7\xa8\x06\x804hh\x12$\x11\xa4i4\xf14S\xd2<Q\xb5\x0fH\xd3\xd4\xdd\xd5\x87\xbb\xf8\x94\r\x8f\xafI\x12\xe1\xc9\xf8/E\x00pu\x89\x12]\xc9\xbbDL\nQ\x0e\t1\x12\xdf\xa0\xc0\x97\xac2O9\x89\x13\x94\x0e\x1c7\x0ed\x95I\x0c\xaaJ\xa4\x18L\x10\x05#\x9c\xaf\xba\xbc/\x97\x8a#C\xc8\xe1\x8cW\xf9\xe2\xd0\xd6M\xa7\x8bXa<e\x84t\xcbL\xb3\xa7\xd9\xcd\xd1\xcb\x84.\xaf\xb3\xab\xab\xad`n}\xa0lh\tE,\x8eZ\x15\x17VH>\x88\xe5\xcd9gd6\x0b\n\xe9\x9b\xd5\x8a\x99\xf7\x08.K\x8ev\xfb\xf7xw\xbb\xdf\xa1\x92\xf1\xdd|/";\xa2\xba\x9f\xd5\xb1#A\xb6\xf6\xb3o\xc9\xc5y\\\xebO\xe7\x85\x9a\xbc\xb6f8\x952\xd5\xd7"%\x89>V,\xf7\xa6z\xe2\x9f\xa3\xdf\x11\x11"\xd6E)I\xa9\x13^\xca\xf3r\xd0\x03U\x922\xf26\xec\xb6\xed\x8b\xc3U\x13\x9d\xc5\x170\xa4\xfa^\x92\xacDF\x8a\x97\xd6\x19\xfe\xdd\xb8\xbd\x1a\x9a\x19\xa3\x80ankR\x8b\xe5\xd83]\xa9\xc6\x08\x82f\xf6\xb9"6l$\xb8j@\xc0\x8a\xb0l1..\xbak\x83ls\x15\xbc\xf4\xc1\x13\xbe\xf8E\xb8\x9d\r\xa8\x9dk\x84\xd3n\xfa\xacQ\x07\xb1%y\xaav\xb4\x08\xe0z\x1b\x16\xf5\x04\xe9\xcc\xb9\x08z\x1en7.G\xfc]\xc9\x14\xe1B@\xbb!8`'
 
-    def decompress(data):
+    def decompress(space, w_data):
         import popen2
         import bz2
+        data = space.bytes_w(w_data)
         pop = popen2.Popen3("bunzip2", capturestderr=1)
         pop.tochild.write(data)
         pop.tochild.close()
         pop.fromchild.close()
         if pop.wait() != 0:
             res = bz2.decompress(data)
-        return res
+        return space.wrapbytes(res)
 
     mod.TEXT = 'root:x:0:0:root:/root:/bin/bash\nbin:x:1:1:bin:/bin:\ndaemon:x:2:2:daemon:/sbin:\nadm:x:3:4:adm:/var/adm:\nlp:x:4:7:lp:/var/spool/lpd:\nsync:x:5:0:sync:/sbin:/bin/sync\nshutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\nhalt:x:7:0:halt:/sbin:/sbin/halt\nmail:x:8:12:mail:/var/spool/mail:\nnews:x:9:13:news:/var/spool/news:\nuucp:x:10:14:uucp:/var/spool/uucp:\noperator:x:11:0:operator:/root:\ngames:x:12:100:games:/usr/games:\ngopher:x:13:30:gopher:/usr/lib/gopher-data:\nftp:x:14:50:FTP User:/var/ftp:/bin/bash\nnobody:x:65534:65534:Nobody:/home:\npostfix:x:100:101:postfix:/var/spool/postfix:\nniemeyer:x:500:500::/home/niemeyer:/bin/bash\npostgres:x:101:102:PostgreSQL Server:/var/lib/pgsql:/bin/bash\nmysql:x:102:103:MySQL server:/var/lib/mysql:/bin/bash\nwww:x:103:104::/var/www:/bin/false\n'
     mod.DATA = DATA
 
     def setup_class(cls):
         cls.w_TEXT = cls.space.wrapbytes(TEXT)
+        cls.w_decompress = cls.space.wrap(interp2app(decompress))
         cls.w_HUGE_OK = cls.space.wrap(HUGE_OK)
-        def decompress_w(space, w_data):
-            return space.wrapbytes(decompress(space.bytes_w(w_data)))
-        cls.w_decompress = cls.space.wrap(interp2app(decompress_w))
-        
+
     def test_creation(self):
         from bz2 import BZ2Compressor
         
         data += bz2c.flush()
         assert self.decompress(data) == self.TEXT
 
+
 class AppTestBZ2Decompressor(CheckAllocation):
     spaceconfig = dict(usemodules=('bz2',))
 
         assert decompressed_data == b''
         raises(IOError, bz2d.decompress, self.BUGGY_DATA)
 
+
 class AppTestBZ2ModuleFunctions(CheckAllocation):
     spaceconfig = dict(usemodules=('bz2',))
 
     def setup_class(cls):
         cls.w_TEXT = cls.space.wrapbytes(TEXT)
         cls.w_DATA = cls.space.wrapbytes(DATA)
+        cls.w_decompress = cls.space.wrap(interp2app(decompress))
         cls.w_HUGE_OK = cls.space.wrap(HUGE_OK)
-        def decompress_w(space, w_data):
-            return space.wrapbytes(decompress(space.bytes_w(w_data)))
-        cls.w_decompress = cls.space.wrap(interp2app(decompress_w))
 
     def test_compress_function(self):
         from bz2 import compress

File pypy/module/bz2/test/test_bz2_file.py

View file
  • Ignore whitespace
 from __future__ import with_statement
 
-import py
 from pypy.module.bz2.test.support import CheckAllocation
-from pypy.interpreter.gateway import interp2app
 import os
 import random
 
+import py
+
+from pypy.interpreter.gateway import unwrap_spec, interp2app
+
+
 if os.name == "nt":
     from py.test import skip
     skip("bz2 module is not available on Windows")
-        
+
 def setup_module(mod):
     DATA = 'BZh91AY&SY.\xc8N\x18\x00\x01>_\x80\x00\x10@\x02\xff\xf0\x01\x07n\x00?\xe7\xff\xe00\x01\x99\xaa\x00\xc0\x03F\x86\x8c#&\x83F\x9a\x03\x06\xa6\xd0\xa6\x93M\x0fQ\xa7\xa8\x06\x804hh\x12$\x11\xa4i4\xf14S\xd2<Q\xb5\x0fH\xd3\xd4\xdd\xd5\x87\xbb\xf8\x94\r\x8f\xafI\x12\xe1\xc9\xf8/E\x00pu\x89\x12]\xc9\xbbDL\nQ\x0e\t1\x12\xdf\xa0\xc0\x97\xac2O9\x89\x13\x94\x0e\x1c7\x0ed\x95I\x0c\xaaJ\xa4\x18L\x10\x05#\x9c\xaf\xba\xbc/\x97\x8a#C\xc8\xe1\x8cW\xf9\xe2\xd0\xd6M\xa7\x8bXa<e\x84t\xcbL\xb3\xa7\xd9\xcd\xd1\xcb\x84.\xaf\xb3\xab\xab\xad`n}\xa0lh\tE,\x8eZ\x15\x17VH>\x88\xe5\xcd9gd6\x0b\n\xe9\x9b\xd5\x8a\x99\xf7\x08.K\x8ev\xfb\xf7xw\xbb\xdf\xa1\x92\xf1\xdd|/";\xa2\xba\x9f\xd5\xb1#A\xb6\xf6\xb3o\xc9\xc5y\\\xebO\xe7\x85\x9a\xbc\xb6f8\x952\xd5\xd7"%\x89>V,\xf7\xa6z\xe2\x9f\xa3\xdf\x11\x11"\xd6E)I\xa9\x13^\xca\xf3r\xd0\x03U\x922\xf26\xec\xb6\xed\x8b\xc3U\x13\x9d\xc5\x170\xa4\xfa^\x92\xacDF\x8a\x97\xd6\x19\xfe\xdd\xb8\xbd\x1a\x9a\x19\xa3\x80ankR\x8b\xe5\xd83]\xa9\xc6\x08\x82f\xf6\xb9"6l$\xb8j@\xc0\x8a\xb0l1..\xbak\x83ls\x15\xbc\xf4\xc1\x13\xbe\xf8E\xb8\x9d\r\xa8\x9dk\x84\xd3n\xfa\xacQ\x07\xb1%y\xaav\xb4\x08\xe0z\x1b\x16\xf5\x04\xe9\xcc\xb9\x08z\x1en7.G\xfc]\xc9\x14\xe1B@\xbb!8`'
     DATA_CRLF = 'BZh91AY&SY\xaez\xbbN\x00\x01H\xdf\x80\x00\x12@\x02\xff\xf0\x01\x07n\x00?\xe7\xff\xe0@\x01\xbc\xc6`\x86*\x8d=M\xa9\x9a\x86\xd0L@\x0fI\xa6!\xa1\x13\xc8\x88jdi\x8d@\x03@\x1a\x1a\x0c\x0c\x83 \x00\xc4h2\x19\x01\x82D\x84e\t\xe8\x99\x89\x19\x1ah\x00\r\x1a\x11\xaf\x9b\x0fG\xf5(\x1b\x1f?\t\x12\xcf\xb5\xfc\x95E\x00ps\x89\x12^\xa4\xdd\xa2&\x05(\x87\x04\x98\x89u\xe40%\xb6\x19\'\x8c\xc4\x89\xca\x07\x0e\x1b!\x91UIFU%C\x994!DI\xd2\xfa\xf0\xf1N8W\xde\x13A\xf5\x9cr%?\x9f3;I45A\xd1\x8bT\xb1<l\xba\xcb_\xc00xY\x17r\x17\x88\x08\x08@\xa0\ry@\x10\x04$)`\xf2\xce\x89z\xb0s\xec\x9b.iW\x9d\x81\xb5-+t\x9f\x1a\'\x97dB\xf5x\xb5\xbe.[.\xd7\x0e\x81\xe7\x08\x1cN`\x88\x10\xca\x87\xc3!"\x80\x92R\xa1/\xd1\xc0\xe6mf\xac\xbd\x99\xcca\xb3\x8780>\xa4\xc7\x8d\x1a\\"\xad\xa1\xabyBg\x15\xb9l\x88\x88\x91k"\x94\xa4\xd4\x89\xae*\xa6\x0b\x10\x0c\xd6\xd4m\xe86\xec\xb5j\x8a\x86j\';\xca.\x01I\xf2\xaaJ\xe8\x88\x8cU+t3\xfb\x0c\n\xa33\x13r2\r\x16\xe0\xb3(\xbf\x1d\x83r\xe7M\xf0D\x1365\xd8\x88\xd3\xa4\x92\xcb2\x06\x04\\\xc1\xb0\xea//\xbek&\xd8\xe6+t\xe5\xa1\x13\xada\x16\xder5"w]\xa2i\xb7[\x97R \xe2IT\xcd;Z\x04dk4\xad\x8a\t\xd3\x81z\x10\xf1:^`\xab\x1f\xc5\xdc\x91N\x14$+\x9e\xae\xd3\x80'
 
-    def create_temp_file(self, crlf=False):
+    @unwrap_spec(crlf=bool)
+    def create_temp_file(space, crlf=False):
         f = py.test.ensuretemp("bz2").join("foo")
         data = (DATA, DATA_CRLF)[crlf]
         f.write(data, 'wb')
 
-    def create_broken_temp_file(self):
+    def create_broken_temp_file():
         f = py.test.ensuretemp("bz2").join("foo")
         data = DATA[:100]
         f.write(data, 'wb')
-    
-    def decompress(data):
+
+    @unwrap_spec(data=str)
+    def decompress(space, data):
         import popen2
         import bz2
         pop = popen2.Popen3("bunzip2", capturestderr=1)
         pop.fromchild.close()
         if pop.wait() != 0:
             res = bz2.decompress(data)
-        return res
+        return space.wrapbytes(res)
 
     mod.TEXT = 'root:x:0:0:root:/root:/bin/bash\nbin:x:1:1:bin:/bin:\ndaemon:x:2:2:daemon:/sbin:\nadm:x:3:4:adm:/var/adm:\nlp:x:4:7:lp:/var/spool/lpd:\nsync:x:5:0:sync:/sbin:/bin/sync\nshutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\nhalt:x:7:0:halt:/sbin:/sbin/halt\nmail:x:8:12:mail:/var/spool/mail:\nnews:x:9:13:news:/var/spool/news:\nuucp:x:10:14:uucp:/var/spool/uucp:\noperator:x:11:0:operator:/root:\ngames:x:12:100:games:/usr/games:\ngopher:x:13:30:gopher:/usr/lib/gopher-data:\nftp:x:14:50:FTP User:/var/ftp:/bin/bash\nnobody:x:65534:65534:Nobody:/home:\npostfix:x:100:101:postfix:/var/spool/postfix:\nniemeyer:x:500:500::/home/niemeyer:/bin/bash\npostgres:x:101:102:PostgreSQL Server:/var/lib/pgsql:/bin/bash\nmysql:x:102:103:MySQL server:/var/lib/mysql:/bin/bash\nwww:x:103:104::/var/www:/bin/false\n'
     mod.DATA = DATA
     s = 'abcdefghijklmnop'
     mod.RANDOM_DATA = ''.join([s[int(random.random() * len(s))] for i in range(30000)])
 
+
 class AppTestBZ2File: #(CheckAllocation):
     # XXX for unknown reasons, we cannot do allocation checks, as sth is
     # keeping those objects alive (BZ2File objects)
 
-    spaceconfig = dict(usemodules=('bz2', 'thread'))
+    spaceconfig = {
+        "usemodules": ["bz2", "thread", "binascii", "rctime"]
+    }
 
     def setup_class(cls):
         cls.w_TEXT = cls.space.wrapbytes(TEXT)
         cls.w_DATA_CRLF = cls.space.wrapbytes(DATA_CRLF)
         cls.w_temppath = cls.space.wrap(
             str(py.test.ensuretemp("bz2").join("foo")))
-        cls.w_create_temp_file = cls.space.wrap(create_temp_file)
-        def decompress_w(space, w_data):
-            return space.wrapbytes(decompress(space.bytes_w(w_data)))
-        cls.w_decompress = cls.space.wrap(interp2app(decompress_w))
-        cls.w_create_broken_temp_file = cls.space.wrap(create_broken_temp_file)
+        cls.w_create_temp_file = cls.space.wrap(interp2app(create_temp_file))
+        cls.w_decompress = cls.space.wrap(interp2app(decompress))
+        cls.w_create_broken_temp_file = cls.space.wrap(interp2app(create_broken_temp_file))
         cls.w_random_data = cls.space.wrapbytes(RANDOM_DATA)
-        
+
     def test_attributes(self):
         from bz2 import BZ2File
-        
+
         bz2f = BZ2File(self.temppath, mode="w")
         assert bz2f.closed == False
         bz2f.close()

File pypy/module/cpyext/api.py

  • Ignore whitespace
File contents unchanged.

File pypy/module/cpyext/state.py

View file
  • Ignore whitespace
         from pypy.module.cpyext.api import INIT_FUNCTIONS
 
         setup_new_method_def(space)
-        if not we_are_translated():
-            space.setattr(space.wrap(self),
-                          space.wrap('api_lib'),
-                          space.wrap(self.api_lib))
-        else:
+        if we_are_translated():
             refcountstate = space.fromcache(RefcountState)
             refcountstate.init_r2w_from_w2r()
 

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

View file
  • Ignore whitespace
 import py
 
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.rpython.lltypesystem import rffi, lltype, ll2ctypes
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.translator import platform
         assert 'PyModule_Check' in api.FUNCTIONS
         assert api.FUNCTIONS['PyModule_Check'].argtypes == [api.PyObject]
 
-def compile_module(space, modname, **kwds):
+def compile_extension_module(space, modname, **kwds):
     """
     Build an extension module and return the filename of the resulting native
     code file.
     Any extra keyword arguments are passed on to ExternalCompilationInfo to
     build the module (so specify your source with one of those).
     """
+    state = space.fromcache(State)
+    api_library = state.api_lib
+    if sys.platform == 'win32':
+        kwds["libraries"] = [api_library]
+        # '%s' undefined; assuming extern returning int
+        kwds["compile_extra"] = ["/we4013"]
+    else:
+        kwds["link_files"] = [str(api_library + '.so')]
+        if sys.platform.startswith('linux'):
+            kwds["compile_extra"]=["-Werror=implicit-function-declaration"]
+
     modname = modname.split('.')[-1]
     eci = ExternalCompilationInfo(
         export_symbols=['PyInit_%s' % (modname,)],
 
 class LeakCheckingTest(object):
     """Base class for all cpyext tests."""
-    spaceconfig = dict(usemodules=['cpyext', 'thread', '_rawffi', 'array'])
+    spaceconfig = dict(usemodules=['cpyext', 'thread', '_rawffi', 'array',
+                                   'itertools', 'rctime', 'binascii'])
     enable_leak_checking = True
 
     @staticmethod
         state = cls.space.fromcache(RefcountState)
         state.non_heaptypes_w[:] = []
 
-    def compile_module(self, name, **kwds):
-        """
-        Build an extension module linked against the cpyext api library.
-        """
-        state = self.space.fromcache(State)
-        api_library = state.api_lib
-        if sys.platform == 'win32':
-            kwds["libraries"] = [api_library]
-            # '%s' undefined; assuming extern returning int
-            kwds["compile_extra"] = ["/we4013"]
-        else:
-            kwds["link_files"] = [str(api_library + '.so')]
-            if sys.platform.startswith('linux'):
-                kwds["compile_extra"]=["-Werror=implicit-function-declaration"]
-        return compile_module(self.space, name, **kwds)
+    def setup_method(self, func):
+        @unwrap_spec(name=str)
+        def compile_module(space, name,
+                           w_separate_module_files=None,
+                           w_separate_module_sources=None):
+            """
+            Build an extension module linked against the cpyext api library.
+            """
+            if not space.is_none(w_separate_module_files):
+                separate_module_files = space.unwrap(w_separate_module_files)
+                assert separate_module_files is not None
+            else:
+                separate_module_files = []
+            if not space.is_none(w_separate_module_sources):
+                separate_module_sources = space.listview_str(w_separate_module_sources)
+                assert separate_module_sources is not None
+            else:
+                separate_module_sources = []
+            pydname = compile_extension_module(
+                space, name,
+                separate_module_files=separate_module_files,
+                separate_module_sources=separate_module_sources)
+            return space.wrap(pydname)
 
+        @unwrap_spec(name=str, init='str_or_None', body=str,
+                     load_it=bool, filename='str_or_None')
+        def import_module(space, name, init=None, body='',
+                          load_it=True, filename=None):
+            """
+            init specifies the overall template of the module.
 
-    def import_module(self, name, init=None, body='', load_it=True, filename=None):
-        """
-        init specifies the overall template of the module.
+            if init is None, the module source will be loaded from a file in this
+            test direcory, give a name given by the filename parameter.
 
-        if init is None, the module source will be loaded from a file in this
-        test direcory, give a name given by the filename parameter.
+            if filename is None, the module name will be used to construct the
+            filename.
+            """
+            name = name.encode()
+            if body or init:
+                body = body.encode()
+                if init is None:
+                    init = "return PyModule_Create(&moduledef);"
+                else:
+                    init = init.encode()
+                code = """
+                #include <Python.h>
+                %(body)s
 
-        if filename is None, the module name will be used to construct the
-        filename.
-        """
-        name = name.encode()
-        if body or init:
-            body = body.encode()
-            if init is None:
-                init = "return PyModule_Create(&moduledef);"
+                PyObject* PyInit_%(name)s(void) {
+                %(init)s
+                }
+                """ % dict(name=name, init=init, body=body)
+                kwds = dict(separate_module_sources=[code])
             else:
-                init = init.encode()
-            code = """
-            #include <Python.h>
-            %(body)s
+                if filename is None:
+                    filename = name
+                filename = py.path.local(autopath.pypydir) / 'module' \
+                        / 'cpyext'/ 'test' / (filename + ".c")
+                kwds = dict(separate_module_files=[filename])
 
-            PyObject* PyInit_%(name)s(void) {
-            %(init)s
-            }
-            """ % dict(name=name, init=init, body=body)
-            kwds = dict(separate_module_sources=[code])
-        else:
-            if filename is None:
-                filename = name
-            filename = py.path.local(autopath.pypydir) / 'module' \
-                    / 'cpyext'/ 'test' / (filename + ".c")
-            kwds = dict(separate_module_files=[filename])
+            mod = compile_extension_module(space, name, **kwds)
 
-        mod = self.compile_module(name, **kwds)
+            if load_it:
+                api.load_extension_module(space, mod, name)
+                self.imported_module_names.append(name)
+                return space.getitem(
+                    space.sys.get('modules'),
+                    space.wrap(name))
+            else:
+                return os.path.dirname(mod)
 
-        if load_it:
-            api.load_extension_module(self.space, mod, name)
+        @unwrap_spec(mod=str, name=str)
+        def reimport_module(space, mod, name):
+            api.load_extension_module(space, mod, name)
+            return self.space.getitem(
+                space.sys.get('modules'),
+                space.wrap(name))
+
+        @unwrap_spec(modname=str, prologue=str)
+        def import_extension(space, modname, w_functions, prologue=""):
+            functions = space.unwrap(w_functions)
+            methods_table = []
+            codes = []
+            for funcname, flags, code in functions:
+                cfuncname = "%s_%s" % (modname, funcname)
+                methods_table.append("{\"%s\", %s, %s}," %
+                                     (funcname, cfuncname, flags))
+                func_code = """
+                static PyObject* %s(PyObject* self, PyObject* args)
+                {
+                %s
+                }
+                """ % (cfuncname, code)
+                codes.append(func_code)
+
+            body = prologue + "\n".join(codes) + """
+            static PyMethodDef methods[] = {
+            %(methods)s
+            { NULL }
+            };
+            static struct PyModuleDef moduledef = {
+                PyModuleDef_HEAD_INIT,
+                "%(modname)s",  /* m_name */
+                NULL,           /* m_doc */
+                -1,             /* m_size */
+                &methods        /* m_methods */
+            };
+            """ % dict(methods='\n'.join(methods_table), modname=modname)
+            init = """PyObject *mod = PyModule_Create(&moduledef);"""
+            return import_module(space, name=modname, init=init, body=body)
+
+        @unwrap_spec(name=str)
+        def record_imported_module(name):
+            """
+            Record a module imported in a test so that it can be cleaned up in
+            teardown before the check for leaks is done.
+
+            name gives the name of the module in the space's sys.modules.
+            """
             self.imported_module_names.append(name)
-            return self.space.getitem(
-                self.space.sys.get('modules'),
-                self.space.wrap(name))
-        else:
-            return os.path.dirname(mod)
 
-    def reimport_module(self, mod, name):
-        mod = mod.encode('ascii')
-        name = name.encode('ascii')
-        api.load_extension_module(self.space, mod, name)
-        return self.space.getitem(
-            self.space.sys.get('modules'),
-            self.space.wrap(name))
-
-    def import_extension(self, modname, functions, prologue=""):
-        methods_table = []
-        codes = []
-        for funcname, flags, code in functions:
-            cfuncname = "%s_%s" % (modname, funcname)
-            methods_table.append("{\"%s\", %s, %s}," %
-                                 (funcname, cfuncname, flags))
-            func_code = """
-            static PyObject* %s(PyObject* self, PyObject* args)
-            {
-            %s
-            }
-            """ % (cfuncname, code)
-            codes.append(func_code)
-
-        body = prologue + "\n".join(codes) + """
-        static PyMethodDef methods[] = {
-        %(methods)s
-        { NULL }
-        };
-        static struct PyModuleDef moduledef = {
-            PyModuleDef_HEAD_INIT,
-            "%(modname)s",  /* m_name */
-            NULL,           /* m_doc */
-            -1,             /* m_size */
-            &methods        /* m_methods */
-        };
-        """ % dict(methods='\n'.join(methods_table), modname=modname)
-        init = """PyObject *mod = PyModule_Create(&moduledef);"""
-        return self.import_module(name=modname, init=init, body=body)
-
-    def record_imported_module(self, name):
-        """
-        Record a module imported in a test so that it can be cleaned up in
-        teardown before the check for leaks is done.
-
-        name gives the name of the module in the space's sys.modules.
-        """
-        self.imported_module_names.append(name)
-
-    def setup_method(self, func):
         # A list of modules which the test caused to be imported (in
         # self.space).  These will be cleaned up automatically in teardown.
         self.imported_module_names = []
 
-        self.w_import_module = self.space.wrap(self.import_module)
-        self.w_reimport_module = self.space.wrap(self.reimport_module)
-        self.w_import_extension = self.space.wrap(self.import_extension)
-        self.w_compile_module = self.space.wrap(self.compile_module)
+        self.w_compile_module = self.space.wrap(interp2app(compile_module))
+        self.w_import_module = self.space.wrap(interp2app(import_module))
+        self.w_reimport_module = self.space.wrap(interp2app(reimport_module))
+        self.w_import_extension = self.space.wrap(interp2app(import_extension))
         self.w_record_imported_module = self.space.wrap(
-            self.record_imported_module)
+            interp2app(record_imported_module))
         self.w_here = self.space.wrap(
             str(py.path.local(autopath.pypydir)) + '/module/cpyext/test/')
 

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

View file
  • Ignore whitespace
             ("get_types", "METH_NOARGS",
              """
                  PyDateTime_IMPORT;
+                 if (!PyDateTimeAPI) {
+                     PyErr_SetString(PyExc_RuntimeError, "No PyDateTimeAPI");
+                     return NULL;
+                 }
                  return PyTuple_Pack(4,
                                      PyDateTimeAPI->DateType,
                                      PyDateTimeAPI->DateTimeType,

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

View file
  • Ignore whitespace
         assert space.type(api.PyNumber_Float(space.wrap(3))) is space.w_float
         assert space.type(api.PyNumber_Float(space.wrap("3"))) is space.w_float
 
-        class Coerce(object):
-            def __float__(self):
-                return 42.5
-        assert space.eq_w(api.PyNumber_Float(space.wrap(Coerce())),
-                          space.wrap(42.5))
+        w_obj = space.appexec([], """():
+            class Coerce(object):
+                def __float__(self):
+                    return 42.5
+            return Coerce()""")
+        assert space.eq_w(api.PyNumber_Float(w_obj), space.wrap(42.5))
 
     def test_unpack(self, space, api):
         with rffi.scoped_str2charp("\x9a\x99\x99?") as ptr:

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

View file
  • Ignore whitespace
                 == 10**30 % (2**64))
 
     def test_coerce(self, space, api):
-        class Coerce(object):
-            def __int__(self):
-                return 42
-        assert api.PyInt_AsLong(space.wrap(Coerce())) == 42
+        w_obj = space.appexec([], """():
+            class Coerce(object):
+                def __int__(self):
+                    return 42
+            return Coerce()""")
+        assert api.PyInt_AsLong(w_obj) == 42
 
 class AppTestIntObject(AppTestCpythonExtensionBase):
     def test_fromstring(self):

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

View file
  • Ignore whitespace
 
 class TestIterator(BaseApiTest):
     def test_check_iter(self, space, api):
-        assert api.PyIter_Check(space.wrap(iter("a")))
-        assert api.PyIter_Check(space.wrap(iter([])))
-        assert not api.PyIter_Check(space.wrap(type))
+        assert api.PyIter_Check(space.iter(space.wrap("a")))
+        assert api.PyIter_Check(space.iter(space.newlist([])))
+        assert not api.PyIter_Check(space.w_type)
         assert not api.PyIter_Check(space.wrap(2))
 
     def test_getIter(self, space, api):

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

View file
  • Ignore whitespace
         assert api.PyObject_Not(space.wrap(3.14)) == 0
 
     def test_exception(self, space, api):
-        class C:
-            def __bool__(self):
-                raise ValueError
+        w_obj = space.appexec([], """():
+            class C:
+                def __bool__(self):
+                    raise ValueError
+            return C()""")
 
-        assert api.PyObject_IsTrue(space.wrap(C())) == -1
-        assert api.PyObject_Not(space.wrap(C())) == -1
+        assert api.PyObject_IsTrue(w_obj) == -1
+        assert api.PyObject_Not(w_obj) == -1
         api.PyErr_Clear()
 
     def test_HasAttr(self, space, api):
         rffi.free_charp(buf)
 
     def test_SetAttr(self, space, api):
-        class X:
-            pass
-        x = X()
-        api.PyObject_SetAttr(space.wrap(x), space.wrap('test'), space.wrap(5))
+        w_obj = space.appexec([], """():
+            class C:
+                pass
+            return C()""")
+
+        api.PyObject_SetAttr(w_obj, space.wrap('test'), space.wrap(5))
         assert not api.PyErr_Occurred()
-        assert x.test == 5
-        assert api.PyObject_HasAttr(space.wrap(x), space.wrap('test'))
-        api.PyObject_SetAttr(space.wrap(x), space.wrap('test'), space.wrap(10))
-        assert x.test == 10
+        assert space.unwrap(space.getattr(w_obj, space.wrap('test'))) == 5
+        assert api.PyObject_HasAttr(w_obj, space.wrap('test'))
+        api.PyObject_SetAttr(w_obj, space.wrap('test'), space.wrap(10))
+        assert space.unwrap(space.getattr(w_obj, space.wrap('test'))) == 10
 
         buf = rffi.str2charp('test')
-        api.PyObject_SetAttrString(space.wrap(x), buf, space.wrap(20))
+        api.PyObject_SetAttrString(w_obj, buf, space.wrap(20))
         rffi.free_charp(buf)
-        assert x.test == 20
+        assert space.unwrap(space.getattr(w_obj, space.wrap('test'))) == 20
 
     def test_getattr(self, space, api):
         charp1 = rffi.str2charp("__len__")

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

View file
  • Ignore whitespace
         assert api.PyErr_Occurred() is space.w_ValueError
         api.PyErr_Clear()
 
-        gen = (x ** 2 for x in range(40))
+        w_gen = space.appexec([], """():
+           return (x ** 2 for x in range(40))""")
         w_tofind = space.wrap(16)
-        result = api.PySequence_Index(space.wrap(gen), w_tofind)
+        result = api.PySequence_Index(w_gen, w_tofind)
         assert result == 4

File pypy/module/imp/test/test_app.py

View file
  • Ignore whitespace
 from __future__ import with_statement
 from pypy.tool.udir import udir
 
+
 class AppTestImpModule:
-    spaceconfig = dict(usemodules=('imp',))
+    spaceconfig = {
+        "usemodules": ['imp', 'itertools', 'binascii', 'rctime'],
+    }
 
     def setup_class(cls):
         cls.w_imp = cls.space.getbuiltinmodule('imp')

File pypy/module/imp/test/test_import.py

View file
  • Ignore whitespace
             sys.modules.update(saved_modules)
     """)
 
+
 class AppTestImport:
-    def setup_class(cls): # interpreter-level
+    spaceconfig = {
+        "usemodules": ['rctime'],
+    }
+
+    def setup_class(cls):
         cls.w_runappdirect = cls.space.wrap(conftest.option.runappdirect)
         cls.w_saved_modules = _setup(cls.space)
         #XXX Compile class
 
-        
-    def teardown_class(cls): # interpreter-level
+    def teardown_class(cls):
         _teardown(cls.space, cls.w_saved_modules)
 
     def w_exec_(self, cmd, ns):
     extrapath.join("urllib.py").write("print(42)\n")
     old = os.environ.get('PYTHONPATH', None)
     oldlang = os.environ.pop('LANG', None)
-    try: 
+    try:
         os.environ['PYTHONPATH'] = str(extrapath)
-        output = py.process.cmdexec('''"%s" "%s" -c "import urllib"''' % 
-                                 (sys.executable, pypypath) )
-        assert output.strip() == '42' 
-    finally: 
-        if old: 
-            os.environ['PYTHONPATH'] = old 
+        output = py.process.cmdexec('''"%s" "%s" -c "import urllib"''' %
+                                 (sys.executable, pypypath))
+        assert output.strip() == '42'
+    finally:
+        if old:
+            os.environ['PYTHONPATH'] = old
         if oldlang:
             os.environ['LANG'] = oldlang
 
+
 class AppTestImportHooks(object):
-    spaceconfig = dict(usemodules=('struct', 'itertools'))
+    spaceconfig = {
+        "usemodules": ['struct', 'itertools', 'rctime'],
+    }
 
     def setup_class(cls):
         mydir = os.path.dirname(__file__)

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

View file
  • Ignore whitespace
 
 
 class AppTestItertools27:
-    spaceconfig = dict(usemodules=['itertools', 'struct'])
+    spaceconfig = {
+        "usemodules": ['itertools', 'struct', 'binascii'],
+    }
 
     def setup_class(cls):
         if cls.space.is_true(cls.space.appexec([], """():

File pypy/module/math/test/test_math.py

View file
  • Ignore whitespace
 from __future__ import with_statement
-import sys
+
+from pypy.interpreter.function import Function
+from pypy.interpreter.gateway import BuiltinCode
 from pypy.module.math.test import test_direct
 
 
 class AppTestMath:
-    spaceconfig = dict(usemodules=['math', 'struct'])
+    spaceconfig = {
+        "usemodules": ['math', 'struct', 'itertools', 'rctime', 'binascii'],
+    }
 
     def setup_class(cls):
-        cls.w_cases = cls.space.wrap(test_direct.MathTests.TESTCASES)
-        cls.w_consistent_host = cls.space.wrap(test_direct.consistent_host)
+        space = cls.space
+        cases = []
+        for a, b, expected in test_direct.MathTests.TESTCASES:
+            if type(expected) is type and issubclass(expected, Exception):
+                expected = getattr(space, "w_%s" % expected.__name__)
+            elif callable(expected):
+                expected = cls.make_callable_wrapper(expected)
+            else:
+                expected = space.wrap(expected)
+            cases.append(space.newtuple([space.wrap(a), space.wrap(b), expected]))
+        cls.w_cases = space.newlist(cases)
+        cls.w_consistent_host = space.wrap(test_direct.consistent_host)
+
+    @classmethod
+    def make_callable_wrapper(cls, func):
+        def f(space, w_x):
+            return space.wrap(func(space.unwrap(w_x)))
+        return Function(cls.space, BuiltinCode(f))
 
     def w_ftest(self, actual, expected):
         assert abs(actual - expected) < 10E-5

File pypy/module/micronumpy/test/test_complex.py

View file
  • Ignore whitespace
 from __future__ import with_statement
+
 import sys
+
+from pypy.conftest import option
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.gateway import interp2app
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
 from pypy.rlib.rfloat import isnan, isinf, copysign
 from pypy.rlib.rcomplex import c_pow
-from pypy.interpreter.error import OperationError
 
-from pypy.conftest import option
 
-def rAlmostEqual(a, b, rel_err = 2e-15, abs_err = 5e-323, msg='', isnumpy=False):
+def rAlmostEqual(a, b, rel_err=2e-15, abs_err=5e-323, msg='', isnumpy=False):
     """Fail if the two floating-point numbers are not almost equal.
 
     Determine whether floating-point values a and b are equal to within
         fname64 = os.path.join(os.path.dirname(__file__), 'complex64_testcases.txt')
         cls.w_testcases128 = cls.space.wrap(list(parse_testfile(fname128)))
         cls.w_testcases64 = cls.space.wrap(list(parse_testfile(fname64)))
-        def cls_c_pow(self, *args):
+
+        def cls_c_pow(space, args_w):
             try:
-                retVal = c_pow(*args)
-                return retVal
+                retVal = c_pow(*map(space.unwrap, args_w))
+                return space.wrap(retVal)
             except ValueError, e:
                 if option.runappdirect:
                     raise
                 raise OperationError(cls.space.w_ValueError,
                         cls.space.wrap(e.message))
-        cls.w_c_pow = cls.space.wrap(cls_c_pow)
+        cls.w_c_pow = cls.space.wrap(interp2app(cls_c_pow))
         cls.w_runAppDirect = cls.space.wrap(option.runappdirect)
         cls.w_isWindows = cls.space.wrap(os.name == 'nt')
-        def cls_rAlmostEqual(self, *args, **kwargs):
+
+        def cls_rAlmostEqual(space, __args__):
+            args, kwargs = __args__.unpack()
+            args = map(space.unwrap, args)
+            kwargs = dict([
+                (k, space.unwrap(v))
+                for k, v in kwargs.iteritems()
+            ])
             if '__pypy__' not in sys.builtin_module_names:
                 kwargs['isnumpy'] = True
-            return rAlmostEqual(*args, **kwargs)
-        cls.w_rAlmostEqual = cls.space.wrap(cls_rAlmostEqual)
+            return space.wrap(rAlmostEqual(*args, **kwargs))
+        cls.w_rAlmostEqual = cls.space.wrap(interp2app(cls_rAlmostEqual))
 
     def test_fabs(self):
         from _numpypy import fabs, complex128

File pypy/module/micronumpy/test/test_ufuncs.py

View file
  • Ignore whitespace
-
+from pypy.conftest import option
+from pypy.interpreter.gateway import interp2app
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
 from pypy.rlib.rcomplex import c_pow
 
-from pypy.conftest import option
-
 
 class AppTestUfuncs(BaseNumpyAppTest):
     def setup_class(cls):
         import os
         BaseNumpyAppTest.setup_class.im_func(cls)
-        def cls_c_pow(self, *args):
-            return c_pow(*args)
-        cls.w_c_pow = cls.space.wrap(cls_c_pow)
+
+        def cls_c_pow(space, args_w):
+            return space.wrap(c_pow(*map(space.unwrap, args_w)))
+        cls.w_c_pow = cls.space.wrap(interp2app(cls_c_pow))
         cls.w_runAppDirect = cls.space.wrap(option.runappdirect)
         cls.w_isWindows = cls.space.wrap(os.name == 'nt')
 

File pypy/module/posix/test/test_posix2.py

View file
  • Ignore whitespace
 
 GET_POSIX = "(): import %s as m ; return m" % os.name
 
+
 class AppTestPosix:
+    spaceconfig = {
+        "usemodules": ["binascii", "struct", "rctime"],
+    }
 
     def setup_class(cls):
         cls.space = space

File pypy/module/rctime/test/test_rctime.py

View file
  • Ignore whitespace
 class AppTestRCTime:
-    spaceconfig = dict(usemodules=['rctime', 'struct'])
+    spaceconfig = {
+        "usemodules": ['rctime', 'struct', 'binascii'],
+    }
 
     def test_attributes(self):
         import time as rctime

File pypy/module/select/test/test_epoll.py

View file
  • Ignore whitespace
 # add a larger timeout for slow ARM machines
 import platform
 
+
 class AppTestEpoll(object):
-    spaceconfig = dict(usemodules=["select", "_socket", "posix"])
+    spaceconfig = {
+        "usemodules": ["select", "_socket", "posix", "rctime"],
+    }
 
     def setup_class(cls):
         # NB. we should ideally py.test.skip() if running on an old linux

File pypy/module/select/test/test_select.py

View file
  • Ignore whitespace
-import py, sys
+import sys
+
+import py
+
+from pypy.interpreter.error import OperationError
+
 
 class _AppTestSelect:
     def test_sleep(self):
             readend.close()
             writeend.close()
 
+
 class AppTestSelectWithPipes(_AppTestSelect):
     "Use a pipe to get pairs of file descriptors"
-    spaceconfig = dict(usemodules=["select"])
+    spaceconfig = {
+        "usemodules": ["select", "rctime"]
+    }
 
     def setup_class(cls):
         if sys.platform == 'win32':
         s1, s2 = os.pipe()
         return FileAsSocket(s1), FileAsSocket(s2)
 
+
 class AppTestSelectWithSockets(_AppTestSelect):
     """Same tests with connected sockets.
     socket.socketpair() does not exists on win32,
     so we start our own server."""
-    spaceconfig = dict(usemodules=["select", "_socket"])
+    spaceconfig = {
+        "usemodules": ["select", "_socket", "rctime", "thread"],
+    }
 
     def setup_class(cls):
-        cls.w_getpair = cls.space.wrap(cls.getsocketpair)
-
-        import socket
-        cls.sock = socket.socket()
+        space = cls.space
+        w_import = space.getattr(space.builtin, space.wrap("__import__"))
+        w_socketmod = space.call_function(w_import, space.wrap("socket"))
+        cls.w_sock = cls.space.call_method(w_socketmod, "socket")
 
         try_ports = [1023] + range(20000, 30000, 437)
         for port in try_ports:
             print 'binding to port %d:' % (port,),
-            cls.sockaddress = ('127.0.0.1', port)
+            cls.w_sockaddress = space.wrap(('127.0.0.1', port))
             try:
-                cls.sock.bind(cls.sockaddress)
+                space.call_method(cls.w_sock, "bind", cls.w_sockaddress)
                 print 'works'
                 break
-            except socket.error, e:   # should get a "Permission denied"
+            except OperationError, e:   # should get a "Permission denied"
+                if not e.match(space, space.getattr(w_socketmod, space.wrap("error"))):
+                    raise
                 print e
             else:
                 raise e
 
-    @classmethod
-    def getsocketpair(cls):
-        """Helper method which returns a pair of connected sockets.
-        Note that they become faked objects at AppLevel"""
-        import thread, socket
+    def w_getpair(self):
+        """Helper method which returns a pair of connected sockets."""
+        import socket
+        import thread
 
-        cls.sock.listen(1)
+        self.sock.listen(1)
         s2 = socket.socket()
-        thread.start_new_thread(s2.connect, (cls.sockaddress,))
-        s1, addr2 = cls.sock.accept()
+        thread.start_new_thread(s2.connect, (self.sockaddress,))
+        s1, addr2 = self.sock.accept()
 
         return s1, s2

File pypy/module/signal/test/test_signal.py

View file
  • Ignore whitespace
     def setup_class(cls):
         if not hasattr(os, 'kill') or not hasattr(os, 'getpid'):
             py.test.skip("requires os.kill() and os.getpid()")
-        if not hasattr(cpy_signal, 'SIGUSR1'):    
+        if not hasattr(cpy_signal, 'SIGUSR1'):
             py.test.skip("requires SIGUSR1 in signal")
 
     def test_checksignals(self):
 
 
 class AppTestSignal:
-    spaceconfig = dict(usemodules=['signal'])
+    spaceconfig = {
+        "usemodules": ['signal', 'rctime'],
+    }
 
     def setup_class(cls):
         cls.w_signal = cls.space.getbuiltinmodule('signal')
         if not hasattr(os, 'kill') or not hasattr(os, 'getpid'):
             skip("requires os.kill() and os.getpid()")
         signal = self.signal   # the signal module to test
-        if not hasattr(signal, 'SIGUSR1'):    
+        if not hasattr(signal, 'SIGUSR1'):
             py.test.skip("requires SIGUSR1 in signal")
         signum = signal.SIGUSR1
 

File pypy/module/sys/test/test_sysmodule.py

View file
  • Ignore whitespace
         # be changed.
         assert sys.float_repr_style == "short"
 
+
 class AppTestCurrentFrames:
-
     def test_current_frames(self):
         try:
             import _thread
         assert list(frames) == [0]
         assert frames[0].f_code.co_name in ('f', '?')
 
+
 class AppTestCurrentFramesWithThread(AppTestCurrentFrames):
-    spaceconfig = dict(usemodules=('thread',))
+    spaceconfig = {
+        "usemodules": ["rctime", "thread"],
+    }
 
     def test_current_frames(self):
         import sys

File pypy/module/test_lib_pypy/test_pwd.py

View file
  • Ignore whitespace
 import py, sys
 
 class AppTestPwd:
-    spaceconfig = dict(usemodules=('_ffi', '_rawffi'))
+    spaceconfig = dict(usemodules=('_ffi', '_rawffi', 'itertools', 'binascii'))
 
     def setup_class(cls):
         if sys.platform == 'win32':

File pypy/module/thread/test/support.py

View file
  • Ignore whitespace
-import py
-import time, gc, thread, os
-from pypy.interpreter.gateway import ObjSpace, W_Root, interp2app_temp
+import gc
+import time
+import thread
+import os
+
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.module.thread import gil
 
 
 NORMAL_TIMEOUT = 300.0   # 5 minutes
 
+
 def waitfor(space, w_condition, delay=1):
     adaptivedelay = 0.04
     limit = time.time() + delay * NORMAL_TIMEOUT
         adaptivedelay *= 1.05
     print '*** timed out ***'
 
+
 def timeout_killer(pid, delay):
     def kill():
         for x in range(delay * 10):
         print "process %s killed!" % (pid,)
     thread.start_new_thread(kill, ())
 
+