[pypy-commit] pypy py3k-refactor-str-types: merge default

pjenvey noreply at buildbot.pypy.org
Fri Jan 24 22:59:36 CET 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k-refactor-str-types
Changeset: r68919:0ffad77c46f4
Date: 2014-01-24 13:49 -0800
http://bitbucket.org/pypy/pypy/changeset/0ffad77c46f4/

Log:	merge default

diff too long, truncating to 2000 out of 9701 lines

diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -1,4 +1,4 @@
-import _ffi
+from _rawffi import alt as _ffi
 import _rawffi
 
 from _ctypes.basics import _CData, cdata_from_address, _CDataMeta, sizeof
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -1,6 +1,6 @@
 
 import _rawffi
-import _ffi
+from _rawffi import alt as _ffi
 import sys
 
 try: from __pypy__ import builtinify
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -5,7 +5,7 @@
 from _ctypes.basics import is_struct_shape
 from _ctypes.builtin import get_errno, set_errno, get_last_error, set_last_error
 import _rawffi
-import _ffi
+from _rawffi import alt as _ffi
 import sys
 import traceback
 
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -1,6 +1,6 @@
 
 import _rawffi
-import _ffi
+from _rawffi import alt as _ffi
 from _ctypes.basics import _CData, _CDataMeta, cdata_from_address, ArgumentError
 from _ctypes.basics import keepalive_key, store_reference, ensure_objects
 from _ctypes.basics import sizeof, byref, as_ffi_pointer
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -1,4 +1,4 @@
-import _ffi
+from _rawffi import alt as _ffi
 import _rawffi
 import weakref
 import sys
diff --git a/lib_pypy/_ffi.py b/lib_pypy/_ffi.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_ffi.py
@@ -0,0 +1,2 @@
+# Backward compatibility hack
+from _rawffi.alt import *
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -34,7 +34,7 @@
      "struct", "_hashlib", "_md5", "_minimal_curses",
      "thread", "itertools", "pyexpat", "_ssl", "cpyext", "array",
      "binascii", "_multiprocessing", '_warnings',
-     "_collections", "_multibytecodec", "_ffi",
+     "_collections", "_multibytecodec",
      "_continuation", "_csv", "_cffi_backend",
      "_posixsubprocess", "_pypyjson", # "cppyy", "micronumpy",
      ]
@@ -43,7 +43,7 @@
 translation_modules = default_modules.copy()
 translation_modules.update(dict.fromkeys(
     ["fcntl", "rctime", "select", "signal", "_rawffi", "zlib",
-     "struct", "array", "_ffi",
+     "struct", "array",
      "binascii",
      # the following are needed for pyrepl (and hence for the
      # interactive prompt/pdb)
@@ -99,7 +99,6 @@
     # no _rawffi if importing rpython.rlib.clibffi raises ImportError
     # or CompilationError or py.test.skip.Exception
     "_rawffi"   : ["rpython.rlib.clibffi"],
-    "_ffi"      : ["rpython.rlib.clibffi"],
 
     "zlib"      : ["rpython.rlib.rzlib"],
     "bz2"       : ["pypy.module.bz2.interp_bz2"],
diff --git a/pypy/doc/_ref.txt b/pypy/doc/_ref.txt
--- a/pypy/doc/_ref.txt
+++ b/pypy/doc/_ref.txt
@@ -109,6 +109,4 @@
 .. _`rpython/translator/c/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/
 .. _`rpython/translator/c/src/stacklet/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/
 .. _`rpython/translator/c/src/stacklet/stacklet.h`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/stacklet.h
-.. _`rpython/translator/cli/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/cli/
-.. _`rpython/translator/jvm/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/jvm/
 .. _`rpython/translator/tool/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/tool/
diff --git a/pypy/doc/garbage_collection.rst b/pypy/doc/garbage_collection.rst
--- a/pypy/doc/garbage_collection.rst
+++ b/pypy/doc/garbage_collection.rst
@@ -210,4 +210,12 @@
   are preserved.  If the object dies then the pre-reserved location
   becomes free garbage, to be collected at the next major collection.
 
+The exact name of this GC is either `minimark` or `incminimark`.  The
+latter is a version that does major collections incrementally (i.e.  one
+major collection is split along some number of minor collections, rather
+than being done all at once after a specific minor collection).  The
+default is `incminimark`, as it seems to have a very minimal impact on
+performance and memory usage at the benefit of avoiding the long pauses
+of `minimark`.
+
 .. include:: _ref.txt
diff --git a/pypy/doc/gc_info.rst b/pypy/doc/gc_info.rst
--- a/pypy/doc/gc_info.rst
+++ b/pypy/doc/gc_info.rst
@@ -6,7 +6,7 @@
 Minimark
 --------
 
-PyPy's default ``minimark`` garbage collector is configurable through
+PyPy's default ``incminimark`` garbage collector is configurable through
 several environment variables:
 
 ``PYPY_GC_NURSERY``
@@ -14,6 +14,17 @@
     Defaults to 1/2 of your cache or ``4M``.
     Small values (like 1 or 1KB) are useful for debugging.
 
+``PYPY_GC_NURSERY_CLEANUP``
+    The interval at which nursery is cleaned up. Must
+    be smaller than the nursery size and bigger than the
+    biggest object we can allotate in the nursery.
+
+``PYPY_GC_INCREMENT_STEP``
+    The size of memory marked during the marking step.  Default is size of
+    nursery times 2. If you mark it too high your GC is not incremental at
+    all.  The minimum is set to size that survives minor collection times
+    1.5 so we reclaim anything all the time.
+
 ``PYPY_GC_MAJOR_COLLECT``
     Major collection memory factor.
     Default is ``1.82``, which means trigger a major collection when the
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
@@ -48,3 +48,12 @@
 .. branch: remove-del-from-generatoriterator
 Speed up generators that don't yield inside try or wait blocks by skipping
 unnecessary cleanup.
+
+.. branch: annotator
+Remove FlowObjSpace.
+Improve cohesion between rpython.flowspace and rpython.annotator.
+
+.. branch: detect-immutable-fields
+mapdicts keep track of whether or not an attribute is every assigned to
+multiple times. If it's only assigned once then an elidable lookup is used when
+possible.
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1,5 +1,5 @@
 from __future__ import division
-import py
+import py, sys
 from pypy.interpreter.astcompiler import codegen, astbuilder, symtable, optimize
 from pypy.interpreter.pyparser import pyparse
 from pypy.interpreter.pyparser.test import expressions
@@ -968,6 +968,9 @@
 
 class AppTestCompiler:
 
+    def setup_class(cls):
+        cls.w_maxunicode = cls.space.wrap(sys.maxunicode)
+
     def test_docstring_not_loaded(self):
         import io, dis, sys
         ns = {}
@@ -1002,7 +1005,17 @@
         l = [a for a in Foo()]
         assert hint_called[0]
         assert l == list(range(5))
-        
+
+    def test_unicode_in_source(self):
+        import sys
+        d = {}
+        exec('# -*- coding: utf-8 -*-\n\nu = "\xf0\x9f\x92\x8b"', d)
+        if sys.maxunicode > 65535 and self.maxunicode > 65535:
+            expected_length = 1
+        else:
+            expected_length = 2
+        assert len(d['u']) == expected_length
+
 
 class TestOptimizations:
     def count_instructions(self, source):
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -918,7 +918,7 @@
         """
         return self.unpackiterable(w_iterable, expected_length)
 
-    def listview_str(self, w_list):
+    def listview_bytes(self, w_list):
         """ Return a list of unwrapped strings out of a list of strings. If the
         argument is not a list or does not contain only strings, return None.
         May return None anyway.
@@ -952,7 +952,7 @@
         """
         return (None, None)
 
-    def newlist_str(self, list_s):
+    def newlist_bytes(self, list_s):
         return self.newlist([self.wrapbytes(s) for s in list_s])
 
     def newlist_unicode(self, list_u):
diff --git a/pypy/interpreter/pyparser/parsestring.py b/pypy/interpreter/pyparser/parsestring.py
--- a/pypy/interpreter/pyparser/parsestring.py
+++ b/pypy/interpreter/pyparser/parsestring.py
@@ -15,7 +15,6 @@
     Yes, it's very inefficient.
     Yes, CPython has very similar code.
     """
-
     # we use ps as "pointer to s"
     # q is the virtual last char index of the string
     ps = 0
@@ -50,47 +49,10 @@
 
     if unicode_literal and not rawmode: # XXX Py_UnicodeFlag is ignored for now
         if encoding is None:
-            buf = s
-            bufp = ps
-            bufq = q
-            u = None
+            assert 0 <= ps <= q
+            substr = s[ps:q]
         else:
-            # String is utf8-encoded, but 'unicode_escape' expects
-            # latin-1; So multibyte sequences must be escaped.
-            lis = [] # using a list to assemble the value
-            end = q
-            # Worst case:
-            # "ä" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5
-            # "\ä" (3 bytes) may become "\u005c\U000000E4" (16 bytes),
-            # or ~1:6
-            while ps < end:
-                if s[ps] == '\\':
-                    lis.append(s[ps])
-                    ps += 1
-                    if ord(s[ps]) & 0x80:
-                        # A multibyte sequence will follow, it will be
-                        # escaped like \u1234. To avoid confusion with
-                        # the backslash we just wrote, we emit "\u005c"
-                        # instead.
-                        lis.append("u005c")
-                if ord(s[ps]) & 0x80: # XXX inefficient
-                    w, ps = decode_utf8(space, s, ps, end, "utf-32-be")
-                    rn = len(w)
-                    assert rn % 4 == 0
-                    for i in range(0, rn, 4):
-                        lis.append('\\U')
-                        lis.append(hexbyte(ord(w[i])))
-                        lis.append(hexbyte(ord(w[i+1])))
-                        lis.append(hexbyte(ord(w[i+2])))
-                        lis.append(hexbyte(ord(w[i+3])))
-                else:
-                    lis.append(s[ps])
-                    ps += 1
-            buf = ''.join(lis)
-            bufp = 0
-            bufq = len(buf)
-        assert 0 <= bufp <= bufq
-        substr = buf[bufp:bufq]
+            substr = decode_unicode_utf8(space, s, ps, q)
         v = unicodehelper.decode_unicode_escape(space, substr)
         return space.wrap(v)
 
@@ -120,6 +82,39 @@
         result = "0" + result
     return result
 
+def decode_unicode_utf8(space, s, ps, q):
+    # ****The Python 2.7 version, producing UTF-32 escapes****
+    # String is utf8-encoded, but 'unicode_escape' expects
+    # latin-1; So multibyte sequences must be escaped.
+    lis = [] # using a list to assemble the value
+    end = q
+    # Worst case:
+    # "<92><195><164>" may become "\u005c\U000000E4" (16 bytes)
+    while ps < end:
+        if s[ps] == '\\':
+            lis.append(s[ps])
+            ps += 1
+            if ord(s[ps]) & 0x80:
+                # A multibyte sequence will follow, it will be
+                # escaped like \u1234. To avoid confusion with
+                # the backslash we just wrote, we emit "\u005c"
+                # instead.
+                lis.append("u005c")
+        if ord(s[ps]) & 0x80: # XXX inefficient
+            w, ps = decode_utf8(space, s, ps, end, "utf-32-be")
+            rn = len(w)
+            assert rn % 4 == 0
+            for i in range(0, rn, 4):
+                lis.append('\\U')
+                lis.append(hexbyte(ord(w[i])))
+                lis.append(hexbyte(ord(w[i+1])))
+                lis.append(hexbyte(ord(w[i+2])))
+                lis.append(hexbyte(ord(w[i+3])))
+        else:
+            lis.append(s[ps])
+            ps += 1
+    return ''.join(lis)
+
 def PyString_DecodeEscape(space, s, recode_encoding):
     """
     Unescape a backslash-escaped string. If recode_encoding is non-zero,
diff --git a/pypy/interpreter/pyparser/test/test_parsestring.py b/pypy/interpreter/pyparser/test/test_parsestring.py
--- a/pypy/interpreter/pyparser/test/test_parsestring.py
+++ b/pypy/interpreter/pyparser/test/test_parsestring.py
@@ -1,10 +1,10 @@
 from pypy.interpreter.pyparser import parsestring
-import py
+import py, sys
 
 class TestParsetring:
-    def parse_and_compare(self, literal, value):
+    def parse_and_compare(self, literal, value, encoding=None):
         space = self.space
-        w_ret = parsestring.parsestr(space, None, literal)
+        w_ret = parsestring.parsestr(space, encoding, literal)
         if isinstance(value, str):
             assert space.type(w_ret) == space.w_bytes
             assert space.bytes_w(w_ret) == value
@@ -105,3 +105,18 @@
         input = ["'", 'x', ' ', chr(0xc3), chr(0xa9), ' ', chr(92), 'n', "'"]
         w_ret = parsestring.parsestr(space, 'utf8', ''.join(input))
         assert space.str_w(w_ret) == ''.join(expected)
+
+    def test_wide_unicode_in_source(self):
+        if sys.maxunicode == 65535:
+            py.test.skip("requires a wide-unicode host")
+        self.parse_and_compare('u"\xf0\x9f\x92\x8b"',
+                               unichr(0x1f48b),
+                               encoding='utf-8')
+
+    def test_decode_unicode_utf8(self):
+        buf = parsestring.decode_unicode_utf8(self.space,
+                                              'u"\xf0\x9f\x92\x8b"', 2, 6)
+        if sys.maxunicode == 65535:
+            assert buf == r"\U0000d83d\U0000dc8b"
+        else:
+            assert buf == r"\U0001f48b"
diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -3,7 +3,7 @@
 from rpython.rlib.objectmodel import we_are_translated
 from pypy.objspace.std.listobject import W_ListObject
 from pypy.objspace.std.typeobject import MethodCache
-from pypy.objspace.std.mapdict import IndexCache
+from pypy.objspace.std.mapdict import MapAttrCache
 from rpython.rlib import rposix, rgc
 
 
@@ -35,7 +35,7 @@
     cache.misses = {}
     cache.hits = {}
     if space.config.objspace.std.withmapdict:
-        cache = space.fromcache(IndexCache)
+        cache = space.fromcache(MapAttrCache)
         cache.misses = {}
         cache.hits = {}
 
@@ -45,7 +45,7 @@
     in the mapdict cache with the given attribute name."""
     assert space.config.objspace.std.withmethodcachecounter
     assert space.config.objspace.std.withmapdict
-    cache = space.fromcache(IndexCache)
+    cache = space.fromcache(MapAttrCache)
     return space.newtuple([space.newint(cache.hits.get(name, 0)),
                            space.newint(cache.misses.get(name, 0))])
 
diff --git a/pypy/module/__pypy__/test/test_special.py b/pypy/module/__pypy__/test/test_special.py
--- a/pypy/module/__pypy__/test/test_special.py
+++ b/pypy/module/__pypy__/test/test_special.py
@@ -81,7 +81,9 @@
         l = [1, 2, 3]
         assert list_strategy(l) == "int"
         l = ["a", "b", "c"]
-        assert list_strategy(l) == "str"
+        assert list_strategy(l) == "bytes"
+        l = [u"a", u"b", u"c"]
+        assert list_strategy(l) == "unicode"
         l = [1.1, 2.2, 3.3]
         assert list_strategy(l) == "float"
         l = range(3)
diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py
--- a/pypy/module/_cffi_backend/ctypestruct.py
+++ b/pypy/module/_cffi_backend/ctypestruct.py
@@ -33,7 +33,7 @@
         if self.fields_dict is None:
             space = self.space
             raise operationerrfmt(w_errorcls or space.w_TypeError,
-                                  "'%s' is not completed yet", self.name)
+                              "'%s' is opaque or not completed yet", self.name)
 
     def _alignof(self):
         self.check_complete(w_errorcls=self.space.w_ValueError)
diff --git a/pypy/module/_ffi/app_struct.py b/pypy/module/_ffi/app_struct.py
deleted file mode 100644
--- a/pypy/module/_ffi/app_struct.py
+++ /dev/null
@@ -1,21 +0,0 @@
-import _ffi
-
-class MetaStructure(type):
-
-    def __new__(cls, name, bases, dic):
-        cls._compute_shape(name, dic)
-        return type.__new__(cls, name, bases, dic)
-
-    @classmethod
-    def _compute_shape(cls, name, dic):
-        fields = dic.get('_fields_')
-        if fields is None:
-            return
-        struct_descr = _ffi._StructDescr(name, fields)
-        for field in fields:
-            dic[field.name] = field
-        dic['_struct_'] = struct_descr
-
-
-class Structure(metaclass=MetaStructure):
-    pass
diff --git a/pypy/module/_ffi/interp_funcptr.py b/pypy/module/_ffi/interp_funcptr.py
deleted file mode 100644
--- a/pypy/module/_ffi/interp_funcptr.py
+++ /dev/null
@@ -1,380 +0,0 @@
-from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError, wrap_oserror, \
-    operationerrfmt
-from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.typedef import TypeDef
-from pypy.module._ffi.interp_ffitype import W_FFIType
-#
-from rpython.rtyper.lltypesystem import lltype, rffi
-#
-from rpython.rlib import jit
-from rpython.rlib import libffi
-from rpython.rlib.clibffi import get_libc_name, StackCheckError, LibFFIError
-from rpython.rlib.rdynload import DLOpenError
-from rpython.rlib.rarithmetic import r_uint
-from rpython.rlib.objectmodel import we_are_translated
-from pypy.module._ffi.type_converter import FromAppLevelConverter, ToAppLevelConverter
-from pypy.module._rawffi.interp_rawffi import got_libffi_error, wrap_dlopenerror
-
-import os
-if os.name == 'nt':
-    def _getfunc(space, CDLL, w_name, w_argtypes, w_restype):
-        argtypes_w, argtypes, w_restype, restype = unpack_argtypes(
-            space, w_argtypes, w_restype)
-        if space.isinstance_w(w_name, space.w_unicode):
-            # XXX: support LoadLibraryW
-            name = space.str_w(w_name)
-            try:
-                func = CDLL.cdll.getpointer(name, argtypes, restype,
-                                            flags = CDLL.flags)
-            except KeyError:
-                raise operationerrfmt(
-                    space.w_AttributeError,
-                    "No symbol %s found in library %s", name, CDLL.name)
-            except LibFFIError:
-                raise got_libffi_error(space)
-
-            return W_FuncPtr(func, argtypes_w, w_restype)
-        elif space.isinstance_w(w_name, space.w_int):
-            ordinal = space.int_w(w_name)
-            try:
-                func = CDLL.cdll.getpointer_by_ordinal(
-                    ordinal, argtypes, restype,
-                    flags = CDLL.flags)
-            except KeyError:
-                raise operationerrfmt(
-                    space.w_AttributeError,
-                    "No ordinal %d found in library %s", ordinal, CDLL.name)
-            except LibFFIError:
-                raise got_libffi_error(space)
-
-            return W_FuncPtr(func, argtypes_w, w_restype)
-        else:
-            raise OperationError(space.w_TypeError, space.wrap(
-                    'function name must be a string or integer'))
-else:
-    @unwrap_spec(name=str)
-    def _getfunc(space, CDLL, w_name, w_argtypes, w_restype):
-        name = space.str_w(w_name)
-        argtypes_w, argtypes, w_restype, restype = unpack_argtypes(
-            space, w_argtypes, w_restype)
-        try:
-            func = CDLL.cdll.getpointer(name, argtypes, restype,
-                                        flags = CDLL.flags)
-        except KeyError:
-            raise operationerrfmt(
-                space.w_AttributeError,
-                "No symbol %s found in library %s", name, CDLL.name)
-        except LibFFIError:
-            raise got_libffi_error(space)
-
-        return W_FuncPtr(func, argtypes_w, w_restype)
-
-def unwrap_ffitype(space, w_argtype, allow_void=False):
-    res = w_argtype.get_ffitype()
-    if res is libffi.types.void and not allow_void:
-        msg = 'void is not a valid argument type'
-        raise OperationError(space.w_TypeError, space.wrap(msg))
-    return res
-
-
-# ========================================================================
-
-class W_FuncPtr(W_Root):
-
-    _immutable_fields_ = ['func', 'argtypes_w[*]', 'w_restype']
-
-    def __init__(self, func, argtypes_w, w_restype):
-        self.func = func
-        self.argtypes_w = argtypes_w
-        self.w_restype = w_restype
-        self.to_free = []
-
-    @jit.unroll_safe
-    def build_argchain(self, space, args_w):
-        expected = len(self.argtypes_w)
-        given = len(args_w)
-        if given != expected:
-            arg = 'arguments'
-            if len(self.argtypes_w) == 1:
-                arg = 'argument'
-            raise operationerrfmt(space.w_TypeError,
-                                  '%s() takes exactly %d %s (%d given)',
-                                  self.func.name, expected, arg, given)
-        #
-        argchain = libffi.ArgChain()
-        argpusher = PushArgumentConverter(space, argchain, self)
-        for i in range(expected):
-            w_argtype = self.argtypes_w[i]
-            w_arg = args_w[i]
-            argpusher.unwrap_and_do(w_argtype, w_arg)
-        return argchain
-
-    def call(self, space, args_w):
-        self = jit.promote(self)
-        argchain = self.build_argchain(space, args_w)
-        func_caller = CallFunctionConverter(space, self.func, argchain)
-        try:
-            return func_caller.do_and_wrap(self.w_restype)
-        except StackCheckError, e:
-            raise OperationError(space.w_ValueError, space.wrap(e.message))
-        #return self._do_call(space, argchain)
-
-    def free_temp_buffers(self, space):
-        for buf in self.to_free:
-            if not we_are_translated():
-                buf[0] = '\00' # invalidate the buffer, so that
-                               # test_keepalive_temp_buffer can fail
-            lltype.free(buf, flavor='raw')
-        self.to_free = []
-
-    def getaddr(self, space):
-        """
-        Return the physical address in memory of the function
-        """
-        return space.wrap(rffi.cast(rffi.LONG, self.func.funcsym))
-
-
-class PushArgumentConverter(FromAppLevelConverter):
-    """
-    A converter used by W_FuncPtr to unwrap the app-level objects into
-    low-level types and push them to the argchain.
-    """
-
-    def __init__(self, space, argchain, w_func):
-        FromAppLevelConverter.__init__(self, space)
-        self.argchain = argchain
-        self.w_func = w_func
-
-    def handle_signed(self, w_ffitype, w_obj, intval):
-        self.argchain.arg(intval)
-
-    def handle_unsigned(self, w_ffitype, w_obj, uintval):
-        self.argchain.arg(uintval)
-
-    def handle_pointer(self, w_ffitype, w_obj, intval):
-        self.argchain.arg(intval)
-
-    def handle_char(self, w_ffitype, w_obj, intval):
-        self.argchain.arg(intval)
-
-    def handle_unichar(self, w_ffitype, w_obj, intval):
-        self.argchain.arg(intval)
-
-    def handle_longlong(self, w_ffitype, w_obj, longlongval):
-        self.argchain.arg(longlongval)
-
-    def handle_char_p(self, w_ffitype, w_obj, strval):
-        buf = rffi.str2charp(strval)
-        self.w_func.to_free.append(rffi.cast(rffi.VOIDP, buf))
-        addr = rffi.cast(rffi.ULONG, buf)
-        self.argchain.arg(addr)
-
-    def handle_unichar_p(self, w_ffitype, w_obj, unicodeval):
-        buf = rffi.unicode2wcharp(unicodeval)
-        self.w_func.to_free.append(rffi.cast(rffi.VOIDP, buf))
-        addr = rffi.cast(rffi.ULONG, buf)
-        self.argchain.arg(addr)
-
-    def handle_float(self, w_ffitype, w_obj, floatval):
-        self.argchain.arg(floatval)
-
-    def handle_singlefloat(self, w_ffitype, w_obj, singlefloatval):
-        self.argchain.arg(singlefloatval)
-
-    def handle_struct(self, w_ffitype, w_structinstance):
-        # arg_raw directly takes value to put inside ll_args
-        ptrval = w_structinstance.rawmem
-        self.argchain.arg_raw(ptrval)
-
-    def handle_struct_rawffi(self, w_ffitype, w_structinstance):
-        # arg_raw directly takes value to put inside ll_args
-        ptrval = w_structinstance.ll_buffer
-        self.argchain.arg_raw(ptrval)
-
-
-class CallFunctionConverter(ToAppLevelConverter):
-    """
-    A converter used by W_FuncPtr to call the function, expect the result of
-    a correct low-level type and wrap it to the corresponding app-level type
-    """
-
-    def __init__(self, space, func, argchain):
-        ToAppLevelConverter.__init__(self, space)
-        self.func = func
-        self.argchain = argchain
-
-    def get_longlong(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.LONGLONG)
-
-    def get_ulonglong(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.ULONGLONG)
-
-    def get_signed(self, w_ffitype):
-        # if the declared return type of the function is smaller than LONG,
-        # the result buffer may contains garbage in its higher bits.  To get
-        # the correct value, and to be sure to handle the signed/unsigned case
-        # correctly, we need to cast the result to the correct type.  After
-        # that, we cast it back to LONG, because this is what we want to pass
-        # to space.wrap in order to get a nice applevel <int>.
-        #
-        restype = w_ffitype.get_ffitype()
-        call = self.func.call
-        if restype is libffi.types.slong:
-            return call(self.argchain, rffi.LONG)
-        elif restype is libffi.types.sint:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.INT))
-        elif restype is libffi.types.sshort:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.SHORT))
-        elif restype is libffi.types.schar:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.SIGNEDCHAR))
-        else:
-            self.error(w_ffitype)
-
-    def get_unsigned(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.ULONG)
-
-    def get_unsigned_which_fits_into_a_signed(self, w_ffitype):
-        # the same comment as get_signed apply
-        restype = w_ffitype.get_ffitype()
-        call = self.func.call
-        if restype is libffi.types.uint:
-            assert not libffi.IS_32_BIT
-            # on 32bit machines, we should never get here, because it's a case
-            # which has already been handled by get_unsigned above.
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.UINT))
-        elif restype is libffi.types.ushort:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.USHORT))
-        elif restype is libffi.types.uchar:
-            return rffi.cast(rffi.LONG, call(self.argchain, rffi.UCHAR))
-        else:
-            self.error(w_ffitype)
-
-
-    def get_pointer(self, w_ffitype):
-        ptrres = self.func.call(self.argchain, rffi.VOIDP)
-        return rffi.cast(rffi.ULONG, ptrres)
-
-    def get_char(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.UCHAR)
-
-    def get_unichar(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.WCHAR_T)
-
-    def get_float(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.DOUBLE)
-
-    def get_singlefloat(self, w_ffitype):
-        return self.func.call(self.argchain, rffi.FLOAT)
-
-    def get_struct(self, w_ffitype, w_structdescr):
-        addr = self.func.call(self.argchain, rffi.LONG, is_struct=True)
-        return w_structdescr.fromaddress(self.space, addr)
-
-    def get_struct_rawffi(self, w_ffitype, w_structdescr):
-        uintval = self.func.call(self.argchain, rffi.ULONG, is_struct=True)
-        return w_structdescr.fromaddress(self.space, uintval)
-
-    def get_void(self, w_ffitype):
-        return self.func.call(self.argchain, lltype.Void)
-
-
-def unpack_argtypes(space, w_argtypes, w_restype):
-    argtypes_w = [space.interp_w(W_FFIType, w_argtype)
-                  for w_argtype in space.listview(w_argtypes)]
-    argtypes = [unwrap_ffitype(space, w_argtype) for w_argtype in
-                argtypes_w]
-    w_restype = space.interp_w(W_FFIType, w_restype)
-    restype = unwrap_ffitype(space, w_restype, allow_void=True)
-    return argtypes_w, argtypes, w_restype, restype
-
- at unwrap_spec(addr=r_uint, name=str, flags=int)
-def descr_fromaddr(space, w_cls, addr, name, w_argtypes,
-                    w_restype, flags=libffi.FUNCFLAG_CDECL):
-    argtypes_w, argtypes, w_restype, restype = unpack_argtypes(space,
-                                                               w_argtypes,
-                                                               w_restype)
-    addr = rffi.cast(rffi.VOIDP, addr)
-    try:
-        func = libffi.Func(name, argtypes, restype, addr, flags)
-        return W_FuncPtr(func, argtypes_w, w_restype)
-    except LibFFIError:
-        raise got_libffi_error(space)
-
-
-W_FuncPtr.typedef = TypeDef(
-    '_ffi.FuncPtr',
-    __call__ = interp2app(W_FuncPtr.call),
-    getaddr = interp2app(W_FuncPtr.getaddr),
-    free_temp_buffers = interp2app(W_FuncPtr.free_temp_buffers),
-    fromaddr = interp2app(descr_fromaddr, as_classmethod=True)
-    )
-
-
-
-# ========================================================================
-
-class W_CDLL(W_Root):
-    def __init__(self, space, name, mode):
-        self.flags = libffi.FUNCFLAG_CDECL
-        self.space = space
-        if name is None:
-            self.name = "<None>"
-        else:
-            self.name = name
-        try:
-            self.cdll = libffi.CDLL(name, mode)
-        except DLOpenError, e:
-            raise wrap_dlopenerror(space, e, self.name)
-
-    def getfunc(self, space, w_name, w_argtypes, w_restype):
-        return _getfunc(space, self, w_name, w_argtypes, w_restype)
-
-    @unwrap_spec(name=str)
-    def getaddressindll(self, space, name):
-        try:
-            address_as_uint = rffi.cast(lltype.Unsigned,
-                                        self.cdll.getaddressindll(name))
-        except KeyError:
-            raise operationerrfmt(
-                space.w_ValueError,
-                "No symbol %s found in library %s", name, self.name)
-        return space.wrap(address_as_uint)
-
- at unwrap_spec(name='str_or_None', mode=int)
-def descr_new_cdll(space, w_type, name, mode=-1):
-    return space.wrap(W_CDLL(space, name, mode))
-
-
-W_CDLL.typedef = TypeDef(
-    '_ffi.CDLL',
-    __new__     = interp2app(descr_new_cdll),
-    getfunc     = interp2app(W_CDLL.getfunc),
-    getaddressindll = interp2app(W_CDLL.getaddressindll),
-    )
-
-class W_WinDLL(W_CDLL):
-    def __init__(self, space, name, mode):
-        W_CDLL.__init__(self, space, name, mode)
-        self.flags = libffi.FUNCFLAG_STDCALL
-
- at unwrap_spec(name='str_or_None', mode=int)
-def descr_new_windll(space, w_type, name, mode=-1):
-    return space.wrap(W_WinDLL(space, name, mode))
-
-
-W_WinDLL.typedef = TypeDef(
-    '_ffi.WinDLL',
-    __new__     = interp2app(descr_new_windll),
-    getfunc     = interp2app(W_WinDLL.getfunc),
-    getaddressindll = interp2app(W_WinDLL.getaddressindll),
-    )
-
-# ========================================================================
-
-def get_libc(space):
-    try:
-        return space.wrap(W_CDLL(space, get_libc_name(), -1))
-    except OSError, e:
-        raise wrap_oserror(space, e)
-
diff --git a/pypy/module/_ffi/test/test_funcptr.py b/pypy/module/_ffi/test/test_funcptr.py
deleted file mode 100644
--- a/pypy/module/_ffi/test/test_funcptr.py
+++ /dev/null
@@ -1,643 +0,0 @@
-from rpython.rtyper.lltypesystem import rffi
-from rpython.rlib.clibffi import get_libc_name
-from rpython.rlib.libffi import types
-from rpython.rlib.libffi import CDLL
-from rpython.rlib.test.test_clibffi import get_libm_name
-
-import sys, py
-
-class BaseAppTestFFI(object):
-    spaceconfig = dict(usemodules=('_ffi', '_rawffi'))
-
-    @classmethod
-    def prepare_c_example(cls):
-        from rpython.tool.udir import udir
-        from rpython.translator.tool.cbuild import ExternalCompilationInfo
-        from rpython.translator.platform import platform
-
-        c_file = udir.ensure("test__ffi", dir=1).join("foolib.c")
-        # automatically collect the C source from the docstrings of the tests
-        snippets = ["""
-        #ifdef _WIN32
-        #define DLLEXPORT __declspec(dllexport)
-        #else
-        #define DLLEXPORT
-        #endif
-        """]
-        for name in dir(cls):
-            if name.startswith('test_'):
-                meth = getattr(cls, name)
-                # the heuristic to determine it it's really C code could be
-                # improved: so far we just check that there is a '{' :-)
-                if meth.__doc__ is not None and '{' in meth.__doc__:
-                    snippets.append(meth.__doc__)
-        #
-        c_file.write(py.code.Source('\n'.join(snippets)))
-        eci = ExternalCompilationInfo(export_symbols=[])
-        return str(platform.compile([c_file], eci, 'x', standalone=False))
-
-    def setup_class(cls):
-        space = cls.space
-        cls.w_iswin32 = space.wrap(sys.platform == 'win32')
-        cls.w_libfoo_name = space.wrap(cls.prepare_c_example())
-        cls.w_libc_name = space.wrap(get_libc_name())
-        libm_name = get_libm_name(sys.platform)
-        cls.w_libm_name = space.wrap(libm_name)
-        libm = CDLL(libm_name)
-        pow = libm.getpointer('pow', [], types.void)
-        pow_addr = rffi.cast(rffi.LONG, pow.funcsym)
-        cls._libm = libm     # otherwise it gets unloaded - argh!
-        cls.w_pow_addr = space.wrap(pow_addr)
-
-class AppTestFFI(BaseAppTestFFI):
-
-    def setup_class(cls):
-        BaseAppTestFFI.setup_class.im_func(cls)
-        space = cls.space
-        # these are needed for test_single_float_args
-        from ctypes import c_float
-        f_12_34 = c_float(12.34).value
-        f_56_78 = c_float(56.78).value
-        f_result = c_float(f_12_34 + f_56_78).value
-        cls.w_f_12_34_plus_56_78 = space.wrap(f_result)
-
-    def test_libload(self):
-        import _ffi
-        _ffi.CDLL(self.libc_name)
-
-    def test_libload_fail(self):
-        import _ffi
-        raises(OSError, _ffi.CDLL, "xxxxx_this_name_does_not_exist_xxxxx")
-
-    def test_libload_None(self):
-        if self.iswin32:
-            skip("unix specific")
-        from _ffi import CDLL, types
-        # this should return *all* loaded libs, dlopen(NULL)
-        dll = CDLL(None)
-        # libm should be loaded
-        res = dll.getfunc('sqrt', [types.double], types.double)(1.0)
-        assert res == 1.0
-
-    def test_callfunc(self):
-        from _ffi import CDLL, types
-        libm = CDLL(self.libm_name)
-        pow = libm.getfunc('pow', [types.double, types.double], types.double)
-        assert pow(2, 3) == 8
-
-    @py.test.mark.skipif("py.test.config.option.runappdirect")
-    def test_getaddr(self):
-        from _ffi import CDLL, types
-        libm = CDLL(self.libm_name)
-        pow = libm.getfunc('pow', [types.double, types.double], types.double)
-        assert pow.getaddr() == self.pow_addr
-
-    @py.test.mark.skipif("py.test.config.option.runappdirect")
-    def test_getaddressindll(self):
-        import sys
-        from _ffi import CDLL
-        libm = CDLL(self.libm_name)
-        pow_addr = libm.getaddressindll('pow')
-        fff = sys.maxsize*2-1
-        assert pow_addr == self.pow_addr & fff
-
-    def test_func_fromaddr(self):
-        from _ffi import CDLL, types, FuncPtr
-        libm = CDLL(self.libm_name)
-        pow_addr = libm.getaddressindll('pow')
-        pow = FuncPtr.fromaddr(pow_addr, 'pow', [types.double, types.double],
-                               types.double)
-        assert pow(2, 3) == 8
-
-    def test_int_args(self):
-        """
-            DLLEXPORT int sum_xy(int x, int y)
-            {
-                return x+y;
-            }
-        """
-        import sys
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy', [types.sint, types.sint], types.sint)
-        assert sum_xy(30, 12) == 42
-        assert sum_xy(sys.maxsize*2, 0) == -2
-
-    def test_void_result(self):
-        """
-            int dummy = 0;
-            DLLEXPORT void set_dummy(int val) { dummy = val; }
-            DLLEXPORT int get_dummy() { return dummy; }
-        """
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        set_dummy = libfoo.getfunc('set_dummy', [types.sint], types.void)
-        get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
-        assert get_dummy() == 0
-        assert set_dummy(42) is None
-        assert get_dummy() == 42
-        set_dummy(0)
-
-    def test_pointer_args(self):
-        """
-            extern int dummy; // defined in test_void_result
-            DLLEXPORT int* get_dummy_ptr() { return &dummy; }
-            DLLEXPORT void set_val_to_ptr(int* ptr, int val) { *ptr = val; }
-        """
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
-        get_dummy_ptr = libfoo.getfunc('get_dummy_ptr', [], types.void_p)
-        set_val_to_ptr = libfoo.getfunc('set_val_to_ptr',
-                                        [types.void_p, types.sint],
-                                        types.void)
-        assert get_dummy() == 0
-        ptr = get_dummy_ptr()
-        set_val_to_ptr(ptr, 123)
-        assert get_dummy() == 123
-        set_val_to_ptr(ptr, 0)
-
-    def test_convert_pointer_args(self):
-        """
-            extern int dummy; // defined in test_void_result
-            DLLEXPORT int* get_dummy_ptr(); // defined in test_pointer_args
-            DLLEXPORT void set_val_to_ptr(int* ptr, int val); // ditto
-        """
-        from _ffi import CDLL, types
-
-        class MyPointerWrapper(object):
-            def __init__(self, value):
-                self.value = value
-            def _as_ffi_pointer_(self, ffitype):
-                assert ffitype is types.void_p
-                return self.value
-
-        libfoo = CDLL(self.libfoo_name)
-        get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
-        get_dummy_ptr = libfoo.getfunc('get_dummy_ptr', [], types.void_p)
-        set_val_to_ptr = libfoo.getfunc('set_val_to_ptr',
-                                        [types.void_p, types.sint],
-                                        types.void)
-        assert get_dummy() == 0
-        ptr = get_dummy_ptr()
-        assert type(ptr) is int
-        ptr2 = MyPointerWrapper(ptr)
-        set_val_to_ptr(ptr2, 123)
-        assert get_dummy() == 123
-        set_val_to_ptr(ptr2, 0)
-
-    def test_convert_strings_to_char_p(self):
-        """
-            DLLEXPORT
-            long mystrlen(char* s)
-            {
-                long len = 0;
-                while(*s++)
-                    len++;
-                return len;
-            }
-        """
-        from _ffi import CDLL, types
-        import _rawffi
-        libfoo = CDLL(self.libfoo_name)
-        mystrlen = libfoo.getfunc('mystrlen', [types.char_p], types.slong)
-        #
-        # first, try automatic conversion from a string
-        assert mystrlen(b'foobar') == 6
-        # then, try to pass an explicit pointer
-        CharArray = _rawffi.Array('c')
-        mystr = CharArray(7, b'foobar')
-        assert mystrlen(mystr.buffer) == 6
-        mystr.free()
-        mystrlen.free_temp_buffers()
-
-    def test_convert_unicode_to_unichar_p(self):
-        """
-            #include <wchar.h>
-            DLLEXPORT
-            long mystrlen_u(wchar_t* s)
-            {
-                long len = 0;
-                while(*s++)
-                    len++;
-                return len;
-            }
-        """
-        from _ffi import CDLL, types
-        import _rawffi
-        libfoo = CDLL(self.libfoo_name)
-        mystrlen = libfoo.getfunc('mystrlen_u', [types.unichar_p], types.slong)
-        #
-        # first, try automatic conversion from strings and unicode
-        assert mystrlen('foobar') == 6
-        assert mystrlen('foobar') == 6
-        assert mystrlen('ab\u2070') == 3
-        # then, try to pass an explicit pointer
-        UniCharArray = _rawffi.Array('u')
-        mystr = UniCharArray(7, 'foobar')
-        assert mystrlen(mystr.buffer) == 6
-        mystr.free()
-        mystrlen.free_temp_buffers()
-
-    def test_keepalive_temp_buffer(self):
-        """
-            DLLEXPORT
-            char* do_nothing(char* s)
-            {
-                return s;
-            }
-        """
-        from _ffi import CDLL, types
-        import _rawffi
-        libfoo = CDLL(self.libfoo_name)
-        do_nothing = libfoo.getfunc('do_nothing', [types.char_p], types.char_p)
-        CharArray = _rawffi.Array('c')
-        #
-        ptr = do_nothing(b'foobar')
-        array = CharArray.fromaddress(ptr, 7)
-        assert bytes(array) == b'foobar\00'
-        do_nothing.free_temp_buffers()
-
-    def test_typed_pointer_args(self):
-        """
-            extern int dummy; // defined in test_void_result
-            DLLEXPORT int* get_dummy_ptr(); // defined in test_pointer_args
-            DLLEXPORT void set_val_to_ptr(int* ptr, int val); // ditto
-        """
-        from _ffi import CDLL, types
-
-        libfoo = CDLL(self.libfoo_name)
-        intptr = types.Pointer(types.sint)
-        get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
-        get_dummy_ptr = libfoo.getfunc('get_dummy_ptr', [], intptr)
-        set_val_to_ptr = libfoo.getfunc('set_val_to_ptr', [intptr, types.sint], types.void)
-        assert get_dummy() == 0
-        ptr = get_dummy_ptr()
-        set_val_to_ptr(ptr, 123)
-        assert get_dummy() == 123
-        set_val_to_ptr(ptr, 0)
-
-    def test_huge_pointer_args(self):
-        """
-            #include <stdlib.h>
-            DLLEXPORT long is_null_ptr(void* ptr) { return ptr == NULL; }
-        """
-        import sys
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        is_null_ptr = libfoo.getfunc('is_null_ptr', [types.void_p], types.ulong)
-        assert not is_null_ptr(sys.maxsize+1)
-
-    def test_unsigned_long_args(self):
-        """
-            DLLEXPORT unsigned long sum_xy_ul(unsigned long x, unsigned long y)
-            {
-                return x+y;
-            }
-        """
-        import sys
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_ul', [types.ulong, types.ulong],
-                                types.ulong)
-        assert sum_xy(sys.maxsize, 12) == sys.maxsize+12
-        assert sum_xy(sys.maxsize+1, 12) == sys.maxsize+13
-        #
-        res = sum_xy(sys.maxsize*2+3, 0)
-        assert res == 1
-
-    def test_unsigned_short_args(self):
-        """
-            DLLEXPORT unsigned short sum_xy_us(unsigned short x, unsigned short y)
-            {
-                return x+y;
-            }
-        """
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_us', [types.ushort, types.ushort],
-                                types.ushort)
-        assert sum_xy(32000, 8000) == 40000
-        assert sum_xy(60000, 30000) == 90000 % 65536
-
-    def test_unsigned_byte_args(self):
-        """
-            DLLEXPORT unsigned char sum_xy_ub(unsigned char x, unsigned char y)
-            {
-                return x+y;
-            }
-        """
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_us', [types.ubyte, types.ubyte],
-                                types.ubyte)
-        assert sum_xy(100, 40) == 140
-        assert sum_xy(200, 60) == 260 % 256
-
-    def test_unsigned_int_args(self):
-        r"""
-            DLLEXPORT unsigned int sum_xy_ui(unsigned int x, unsigned int y)
-            {
-                return x+y;
-            }
-        """
-        import sys
-        from _ffi import CDLL, types
-        maxint32 = 2147483647
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_ui', [types.uint, types.uint],
-                                types.uint)
-        assert sum_xy(maxint32, 1) == maxint32+1
-        assert sum_xy(maxint32, maxint32+2) == 0
-
-    def test_signed_byte_args(self):
-        """
-            DLLEXPORT signed char sum_xy_sb(signed char x, signed char y)
-            {
-                return x+y;
-            }
-        """
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_sb', [types.sbyte, types.sbyte],
-                                types.sbyte)
-        assert sum_xy(10, 20) == 30
-        assert sum_xy(100, 28) == -128
-
-    def test_char_args(self):
-        """
-            DLLEXPORT char my_toupper(char x)
-            {
-                return x - ('a'-'A');
-            }
-        """
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        my_toupper = libfoo.getfunc('my_toupper', [types.char],
-                                    types.char)
-        assert my_toupper('c') == 'C'
-
-    def test_unichar_args(self):
-        """
-            #include <stddef.h>
-            DLLEXPORT wchar_t sum_xy_wc(wchar_t x, wchar_t y)
-            {
-                return x + y;
-            }
-        """
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_wc', [types.unichar, types.unichar],
-                                types.unichar)
-        res = sum_xy(chr(1000), chr(2000))
-        assert type(res) is str
-        assert ord(res) == 3000
-
-    def test_single_float_args(self):
-        """
-            DLLEXPORT float sum_xy_float(float x, float y)
-            {
-                return x+y;
-            }
-        """
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_float', [types.float, types.float],
-                                types.float)
-        res = sum_xy(12.34, 56.78)
-        assert res == self.f_12_34_plus_56_78
-
-
-    def test_slonglong_args(self):
-        """
-            DLLEXPORT long long sum_xy_longlong(long long x, long long y)
-            {
-                return x+y;
-            }
-        """
-        from _ffi import CDLL, types
-        maxint32 = 2147483647 # we cannot really go above maxint on 64 bits
-                              # (and we would not test anything, as there long
-                              # is the same as long long)
-
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_longlong', [types.slonglong, types.slonglong],
-                                types.slonglong)
-        x = maxint32+1
-        y = maxint32+2
-        res = sum_xy(x, y)
-        expected = maxint32*2 + 3
-        assert res == expected
-
-    def test_ulonglong_args(self):
-        """
-            DLLEXPORT unsigned long long sum_xy_ulonglong(unsigned long long x,
-                                                unsigned long long y)
-            {
-                return x+y;
-            }
-        """
-        from _ffi import CDLL, types
-        maxint64 = 9223372036854775807 # maxint64+1 does not fit into a
-                                       # longlong, but it does into a
-                                       # ulonglong
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy_ulonglong', [types.ulonglong, types.ulonglong],
-                                types.ulonglong)
-        x = maxint64+1
-        y = 2
-        res = sum_xy(x, y)
-        expected = maxint64 + 3
-        assert res == expected
-        #
-        res = sum_xy(maxint64*2+3, 0)
-        assert res == 1
-
-    def test_byval_argument(self):
-        """
-            struct Point {
-                long x;
-                long y;
-            };
-
-            DLLEXPORT long sum_point(struct Point p) {
-                return p.x + p.y;
-            }
-        """
-        from _ffi import CDLL, types, _StructDescr, Field
-        Point = _StructDescr('Point', [
-                Field('x', types.slong),
-                Field('y', types.slong),
-                ])
-        libfoo = CDLL(self.libfoo_name)
-        sum_point = libfoo.getfunc('sum_point', [Point.ffitype], types.slong)
-        #
-        p = Point.allocate()
-        p.setfield('x', 30)
-        p.setfield('y', 12)
-        res = sum_point(p)
-        assert res == 42
-
-    def test_byval_result(self):
-        """
-            DLLEXPORT struct Point make_point(long x, long y) {
-                struct Point p;
-                p.x = x;
-                p.y = y;
-                return p;
-            }
-        """
-        from _ffi import CDLL, types, _StructDescr, Field
-        Point = _StructDescr('Point', [
-                Field('x', types.slong),
-                Field('y', types.slong),
-                ])
-        libfoo = CDLL(self.libfoo_name)
-        make_point = libfoo.getfunc('make_point', [types.slong, types.slong],
-                                    Point.ffitype)
-        #
-        p = make_point(12, 34)
-        assert p.getfield('x') == 12
-        assert p.getfield('y') == 34
-
-    # XXX: support for _rawffi structures should be killed as soon as we
-    # implement ctypes.Structure on top of _ffi. In the meantime, we support
-    # both
-    def test_byval_argument__rawffi(self):
-        """
-            // defined above
-            struct Point;
-            DLLEXPORT long sum_point(struct Point p);
-        """
-        import _rawffi
-        from _ffi import CDLL, types
-        POINT = _rawffi.Structure([('x', 'l'), ('y', 'l')])
-        ffi_point = POINT.get_ffi_type()
-        libfoo = CDLL(self.libfoo_name)
-        sum_point = libfoo.getfunc('sum_point', [ffi_point], types.slong)
-        #
-        p = POINT()
-        p.x = 30
-        p.y = 12
-        res = sum_point(p)
-        assert res == 42
-        p.free()
-
-    def test_byval_result__rawffi(self):
-        """
-            // defined above
-            DLLEXPORT struct Point make_point(long x, long y);
-        """
-        import _rawffi
-        from _ffi import CDLL, types
-        POINT = _rawffi.Structure([('x', 'l'), ('y', 'l')])
-        ffi_point = POINT.get_ffi_type()
-        libfoo = CDLL(self.libfoo_name)
-        make_point = libfoo.getfunc('make_point', [types.slong, types.slong], ffi_point)
-        #
-        p = make_point(12, 34)
-        assert p.x == 12
-        assert p.y == 34
-        p.free()
-
-
-    def test_TypeError_numargs(self):
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        sum_xy = libfoo.getfunc('sum_xy', [types.sint, types.sint], types.sint)
-        raises(TypeError, "sum_xy(1, 2, 3)")
-        raises(TypeError, "sum_xy(1)")
-
-    def test_TypeError_voidarg(self):
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        raises(TypeError, "libfoo.getfunc('sum_xy', [types.void], types.sint)")
-
-    def test_OSError_loading(self):
-        from _ffi import CDLL, types
-        raises(OSError, "CDLL('I do not exist')")
-
-    def test_AttributeError_missing_function(self):
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        raises(AttributeError, "libfoo.getfunc('I_do_not_exist', [], types.void)")
-        if self.iswin32:
-            skip("unix specific")
-        libnone = CDLL(None)
-        raises(AttributeError, "libnone.getfunc('I_do_not_exist', [], types.void)")
-
-    def test_calling_convention1(self):
-        if not self.iswin32:
-            skip("windows specific")
-        from _ffi import WinDLL, types
-        libm = WinDLL(self.libm_name)
-        pow = libm.getfunc('pow', [types.double, types.double], types.double)
-        try:
-            pow(2, 3)
-        except ValueError as e:
-            assert str(e).startswith('Procedure called with')
-        else:
-            assert 0, 'test must assert, wrong calling convention'
-
-    def test_calling_convention2(self):
-        if not self.iswin32:
-            skip("windows specific")
-        from _ffi import WinDLL, types
-        kernel = WinDLL('Kernel32.dll')
-        sleep = kernel.getfunc('Sleep', [types.uint], types.void)
-        sleep(10)
-
-    def test_calling_convention3(self):
-        if not self.iswin32:
-            skip("windows specific")
-        from _ffi import CDLL, types
-        wrong_kernel = CDLL('Kernel32.dll')
-        wrong_sleep = wrong_kernel.getfunc('Sleep', [types.uint], types.void)
-        try:
-            wrong_sleep(10)
-        except ValueError as e:
-            assert str(e).startswith('Procedure called with')
-        else:
-            assert 0, 'test must assert, wrong calling convention'
-
-    def test_func_fromaddr2(self):
-        if not self.iswin32:
-            skip("windows specific")
-        from _ffi import CDLL, types, FuncPtr
-        from _rawffi import FUNCFLAG_STDCALL
-        libm = CDLL(self.libm_name)
-        pow_addr = libm.getaddressindll('pow')
-        wrong_pow = FuncPtr.fromaddr(pow_addr, 'pow',
-                [types.double, types.double], types.double, FUNCFLAG_STDCALL)
-        try:
-            wrong_pow(2, 3) == 8
-        except ValueError as e:
-            assert str(e).startswith('Procedure called with')
-        else:
-            assert 0, 'test must assert, wrong calling convention'
-
-    def test_func_fromaddr3(self):
-        if not self.iswin32:
-            skip("windows specific")
-        from _ffi import WinDLL, types, FuncPtr
-        from _rawffi import FUNCFLAG_STDCALL
-        kernel = WinDLL('Kernel32.dll')
-        sleep_addr = kernel.getaddressindll('Sleep')
-        sleep = FuncPtr.fromaddr(sleep_addr, 'sleep', [types.uint],
-                            types.void, FUNCFLAG_STDCALL)
-        sleep(10)
-
-    def test_by_ordinal(self):
-        """
-            int DLLEXPORT AAA_first_ordinal_function()
-            {
-                return 42;
-            }
-        """
-        if not self.iswin32:
-            skip("windows specific")
-        from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        f_name = libfoo.getfunc('AAA_first_ordinal_function', [], types.sint)
-        f_ordinal = libfoo.getfunc(1, [], types.sint)
-        assert f_name.getaddr() == f_ordinal.getaddr()
diff --git a/pypy/module/_ffi/test/test_struct.py b/pypy/module/_ffi/test/test_struct.py
deleted file mode 100644
--- a/pypy/module/_ffi/test/test_struct.py
+++ /dev/null
@@ -1,331 +0,0 @@
-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
-
-
-class TestStruct(object):
-
-    class FakeSpace(object):
-        def interp_w(self, cls, obj):
-            return obj
-
-    def compute(self, ffitypes_w):
-        fields_w = [W_Field('<dummy>', w_ffitype) for
-                    w_ffitype in ffitypes_w]
-        return compute_size_and_alignement(self.FakeSpace(), fields_w)
-
-    def sizeof(self, ffitypes_w):
-        size, aligned, fields_w = self.compute(ffitypes_w)
-        return size
-
-    def test_compute_size(self):
-        T = app_types
-        byte_size = app_types.sbyte.sizeof()
-        long_size = app_types.slong.sizeof()
-        llong_size = app_types.slonglong.sizeof()
-        llong_align = app_types.slonglong.get_alignment()
-        #
-        assert llong_align >= 4
-        assert self.sizeof([T.sbyte, T.slong]) == 2*long_size
-        assert self.sizeof([T.sbyte, T.slonglong]) == llong_align + llong_size
-        assert self.sizeof([T.sbyte, T.sbyte, T.slonglong]) == llong_align + llong_size
-        assert self.sizeof([T.sbyte, T.sbyte, T.sbyte, T.slonglong]) == llong_align + llong_size
-        assert self.sizeof([T.sbyte, T.sbyte, T.sbyte, T.sbyte, T.slonglong]) == llong_align + llong_size
-        assert self.sizeof([T.slonglong, T.sbyte]) == llong_size + llong_align
-        assert self.sizeof([T.slonglong, T.sbyte, T.sbyte]) == llong_size + llong_align
-        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):
-
-    @classmethod
-    def read_raw_mem(cls, addr, typename, length):
-        import ctypes
-        addr = ctypes.cast(addr, ctypes.c_void_p)
-        c_type = getattr(ctypes, typename)
-        array_type = ctypes.POINTER(c_type * length)
-        ptr_array = ctypes.cast(addr, array_type)
-        array = ptr_array[0]
-        lst = [array[i] for i in range(length)]
-        return lst
-
-    def setup_class(cls):
-        BaseAppTestFFI.setup_class.im_func(cls)
-
-        if cls.runappdirect:
-            cls.w_read_raw_mem = cls.read_raw_mem
-        else:
-            @unwrap_spec(addr=int, typename=str, length=int)
-            def read_raw_mem_w(space, addr, typename, length):
-                return space.wrap(cls.read_raw_mem(addr, typename, length))
-            cls.w_read_raw_mem = cls.space.wrap(interp2app(read_raw_mem_w))
-        #
-        from rpython.rlib import clibffi
-        from rpython.rlib.rarithmetic import r_uint
-        from rpython.rtyper.lltypesystem import lltype, rffi
-        dummy_type = lltype.malloc(clibffi.FFI_TYPE_P.TO, flavor='raw')
-        dummy_type.c_size = r_uint(123)
-        dummy_type.c_alignment = rffi.cast(rffi.USHORT, 0)
-        dummy_type.c_type = rffi.cast(rffi.USHORT, 0)
-        cls.w_dummy_type = W_FFIType('dummy', dummy_type)
-        cls.w_runappdirect = cls.space.wrap(cls.runappdirect)
-        
-    def test__StructDescr(self):
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('x', types.slong),
-            Field('y', types.slong),
-            ]
-        descr = _StructDescr('foo', fields)
-        assert descr.ffitype.sizeof() == longsize*2
-        assert descr.ffitype.name == 'struct foo'
-
-    def test_alignment(self):
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('x', types.sbyte),
-            Field('y', types.slong),
-            ]
-        descr = _StructDescr('foo', fields)
-        assert descr.ffitype.sizeof() == longsize*2
-        assert fields[0].offset == 0
-        assert fields[1].offset == longsize # aligned to WORD
-
-    def test_missing_field(self):
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('x', types.slong),
-            Field('y', types.slong),
-            ]
-        descr = _StructDescr('foo', fields)
-        struct = descr.allocate()
-        raises(AttributeError, "struct.getfield('missing')")
-        raises(AttributeError, "struct.setfield('missing', 42)")
-
-    def test_unknown_type(self):
-        if self.runappdirect:
-            skip('cannot use self.dummy_type with -A')
-        from _ffi import _StructDescr, Field
-        fields = [
-            Field('x', self.dummy_type),
-            ]
-        descr = _StructDescr('foo', fields)
-        struct = descr.allocate()
-        raises(TypeError, "struct.getfield('x')")
-        raises(TypeError, "struct.setfield('x', 42)")
-
-    def test_getfield_setfield(self):
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('x', types.slong),
-            Field('y', types.slong),
-            ]
-        descr = _StructDescr('foo', fields)
-        struct = descr.allocate()
-        struct.setfield('x', 42)
-        struct.setfield('y', 43)
-        assert struct.getfield('x') == 42
-        assert struct.getfield('y') == 43
-        mem = self.read_raw_mem(struct.getaddr(), 'c_long', 2)
-        assert mem == [42, 43]
-
-    def test_getfield_setfield_signed_types(self):
-        import sys
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('sbyte', types.sbyte),
-            Field('sshort', types.sshort),
-            Field('sint', types.sint),
-            Field('slong', types.slong),
-            ]
-        descr = _StructDescr('foo', fields)
-        struct = descr.allocate()
-        struct.setfield('sbyte', 128)
-        assert struct.getfield('sbyte') == -128
-        struct.setfield('sshort', 32768)
-        assert struct.getfield('sshort') == -32768
-        struct.setfield('sint', 43)
-        assert struct.getfield('sint') == 43
-        struct.setfield('slong', sys.maxsize+1)
-        assert struct.getfield('slong') == -sys.maxsize-1
-        struct.setfield('slong', sys.maxsize*3)
-        assert struct.getfield('slong') == sys.maxsize-2
-
-    def test_getfield_setfield_unsigned_types(self):
-        import sys
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('ubyte', types.ubyte),
-            Field('ushort', types.ushort),
-            Field('uint', types.uint),
-            Field('ulong', types.ulong),
-            Field('char', types.char),
-            Field('unichar', types.unichar),
-            Field('ptr', types.void_p),
-            ]
-        descr = _StructDescr('foo', fields)
-        struct = descr.allocate()
-        struct.setfield('ubyte', -1)
-        assert struct.getfield('ubyte') == 255
-        struct.setfield('ushort', -1)
-        assert struct.getfield('ushort') == 65535
-        struct.setfield('uint', 43)
-        assert struct.getfield('uint') == 43
-        struct.setfield('ulong', -1)
-        assert struct.getfield('ulong') == sys.maxsize*2 + 1
-        struct.setfield('ulong', sys.maxsize*2 + 2)
-        assert struct.getfield('ulong') == 0
-        struct.setfield('char', 'a')
-        assert struct.getfield('char') == 'a'
-        struct.setfield('unichar', '\u1234')
-        assert struct.getfield('unichar') == '\u1234'
-        struct.setfield('ptr', -1)
-        assert struct.getfield('ptr') == sys.maxsize*2 + 1
-    
-    def test_getfield_setfield_longlong(self):
-        import sys
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('slonglong', types.slonglong),
-            Field('ulonglong', types.ulonglong),
-            ]
-        descr = _StructDescr('foo', fields)
-        struct = descr.allocate()
-        struct.setfield('slonglong', 9223372036854775808)
-        assert struct.getfield('slonglong') == -9223372036854775808
-        struct.setfield('ulonglong', -1)
-        assert struct.getfield('ulonglong') == 18446744073709551615        
-        mem = self.read_raw_mem(struct.getaddr(), 'c_longlong', 2)
-        assert mem == [-9223372036854775808, -1]
-
-    def test_getfield_setfield_float(self):
-        import sys
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('x', types.double),
-            ]
-        descr = _StructDescr('foo', fields)
-        struct = descr.allocate()
-        struct.setfield('x', 123.4)
-        assert struct.getfield('x') == 123.4
-        mem = self.read_raw_mem(struct.getaddr(), 'c_double', 1)
-        assert mem == [123.4]
-
-    def test_getfield_setfield_singlefloat(self):
-        import sys
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('x', types.float),
-            ]
-        descr = _StructDescr('foo', fields)
-        struct = descr.allocate()
-        struct.setfield('x', 123.4) # this is a value which DOES loose
-                                    # precision in a single float
-        assert 0 < abs(struct.getfield('x') - 123.4) < 0.0001
-        #
-        struct.setfield('x', 123.5) # this is a value which does not loose
-                                    # precision in a single float
-        assert struct.getfield('x') == 123.5
-        mem = self.read_raw_mem(struct.getaddr(), 'c_float', 1)
-        assert mem == [123.5]
-
-    def test_define_fields(self):
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('x', types.slong),
-            Field('y', types.slong),
-            ]
-        descr = _StructDescr('foo')
-        assert descr.ffitype.name == 'struct foo'
-        assert repr(descr.ffitype) == '<ffi type struct foo (incomplete)>'
-        raises(ValueError, "descr.ffitype.sizeof()")
-        raises(ValueError, "descr.allocate()")
-        #
-        descr.define_fields(fields)
-        assert repr(descr.ffitype) == '<ffi type struct foo>'
-        assert descr.ffitype.sizeof() == longsize*2
-        raises(ValueError, "descr.define_fields(fields)")
-
-    def test_pointer_to_incomplete_struct(self):
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        fields = [
-            Field('x', types.slong),
-            Field('y', types.slong),
-            ]
-        descr = _StructDescr('foo')
-        foo_ffitype = descr.ffitype
-        foo_p = types.Pointer(descr.ffitype)
-        assert foo_p.deref_pointer() is foo_ffitype
-        descr.define_fields(fields)
-        assert descr.ffitype is foo_ffitype
-        assert foo_p.deref_pointer() is foo_ffitype
-        assert types.Pointer(descr.ffitype) is foo_p
-
-    def test_nested_structure(self):
-        from _ffi import _StructDescr, Field, types
-        longsize = types.slong.sizeof()
-        foo_fields = [
-            Field('x', types.slong),
-            Field('y', types.slong),
-            ]
-        foo_descr = _StructDescr('foo', foo_fields)
-        #
-        bar_fields = [
-            Field('x', types.slong),
-            Field('foo', foo_descr.ffitype),
-            ]
-        bar_descr = _StructDescr('bar', bar_fields)
-        assert bar_descr.ffitype.sizeof() == longsize*3
-        #
-        struct = bar_descr.allocate()
-        struct.setfield('x', 40)
-        # reading a nested structure yields a reference to it
-        struct_foo = struct.getfield('foo')
-        struct_foo.setfield('x', 41)
-        struct_foo.setfield('y', 42)
-        mem = self.read_raw_mem(struct.getaddr(), 'c_long', 3)
-        assert mem == [40, 41, 42]
-        #
-        struct_foo2 = foo_descr.allocate()
-        struct_foo2.setfield('x', 141)
-        struct_foo2.setfield('y', 142)
-        # writing a nested structure copies its memory into the target
-        struct.setfield('foo', struct_foo2)
-        struct_foo2.setfield('x', 241)
-        struct_foo2.setfield('y', 242)
-        mem = self.read_raw_mem(struct.getaddr(), 'c_long', 3)
-        assert mem == [40, 141, 142]
-        mem = self.read_raw_mem(struct_foo2.getaddr(), 'c_long', 2)
-        assert mem == [241, 242]
-
-
-
-    def test_compute_shape(self):
-        from _ffi import Structure, Field, types
-        class Point(Structure):
-            _fields_ = [
-                Field('x', types.slong),
-                Field('y', types.slong),
-                ]
-
-        longsize = types.slong.sizeof()
-        assert isinstance(Point.x, Field)
-        assert isinstance(Point.y, Field)
-        assert Point.x.offset == 0
-        assert Point.y.offset == longsize
-        assert Point._struct_.ffitype.sizeof() == longsize*2
-        assert Point._struct_.ffitype.name == 'struct Point'
-
diff --git a/pypy/module/_ffi/test/test_type_converter.py b/pypy/module/_ffi/test/test_type_converter.py
deleted file mode 100644
--- a/pypy/module/_ffi/test/test_type_converter.py
+++ /dev/null
@@ -1,170 +0,0 @@
-import sys
-from rpython.rlib.rarithmetic import r_uint, r_singlefloat, r_longlong, r_ulonglong
-from rpython.rlib.libffi import IS_32_BIT
-from pypy.module._ffi.interp_ffitype import app_types, descr_new_pointer
-from pypy.module._ffi.type_converter import FromAppLevelConverter, ToAppLevelConverter
-
-class DummyFromAppLevelConverter(FromAppLevelConverter):
-
-    def handle_all(self, w_ffitype, w_obj, val):
-        self.lastval = val
-
-    handle_signed = handle_all
-    handle_unsigned = handle_all
-    handle_pointer = handle_all
-    handle_char = handle_all        
-    handle_unichar = handle_all
-    handle_longlong = handle_all
-    handle_char_p = handle_all
-    handle_unichar_p = handle_all
-    handle_float = handle_all
-    handle_singlefloat = handle_all
-    
-    def handle_struct(self, w_ffitype, w_structinstance):
-        self.lastval = w_structinstance
-
-    def convert(self, w_ffitype, w_obj):
-        self.unwrap_and_do(w_ffitype, w_obj)
-        return self.lastval
-
-
-class TestFromAppLevel(object):
-    spaceconfig = dict(usemodules=('_ffi',))
-
-    def setup_class(cls):
-        converter = DummyFromAppLevelConverter(cls.space)
-        cls.from_app_level = staticmethod(converter.convert)
-
-    def check(self, w_ffitype, w_obj, expected):
-        v = self.from_app_level(w_ffitype, w_obj)
-        assert v == expected
-        assert type(v) is type(expected)
-
-    def test_int(self):
-        self.check(app_types.sint, self.space.wrap(42), 42)
-        self.check(app_types.sint, self.space.wrap(sys.maxint+1), -sys.maxint-1)
-        self.check(app_types.sint, self.space.wrap(sys.maxint*2), -2)
-
-    def test_unsigned(self):
-        space = self.space
-        self.check(app_types.uint, space.wrap(42), r_uint(42))
-        self.check(app_types.uint, space.wrap(-1), r_uint(sys.maxint*2 +1))
-        self.check(app_types.uint, space.wrap(sys.maxint*3),
-                   r_uint(sys.maxint - 2))
-        self.check(app_types.ulong, space.wrap(sys.maxint+12),
-                   r_uint(sys.maxint+12))
-        self.check(app_types.ulong, space.wrap(sys.maxint*2+3), r_uint(1))
-
-    def test_char(self):
-        space = self.space
-        self.check(app_types.char, space.wrap('a'), ord('a'))
-        self.check(app_types.unichar, space.wrap(u'\u1234'), 0x1234)
-
-    def test_signed_longlong(self):
-        space = self.space
-        maxint32 = 2147483647 # we cannot really go above maxint on 64 bits
-                              # (and we would not test anything, as there long
-                              # is the same as long long)
-        expected = maxint32+1
-        if IS_32_BIT:
-            expected = r_longlong(expected)
-        self.check(app_types.slonglong, space.wrap(maxint32+1), expected)
-
-    def test_unsigned_longlong(self):
-        space = self.space
-        maxint64 = 9223372036854775807 # maxint64+1 does not fit into a
-                                       # longlong, but it does into a
-                                       # ulonglong
-        if IS_32_BIT:
-            # internally, the type converter always casts to signed longlongs
-            expected = r_longlong(-maxint64-1)
-        else:
-            # on 64 bit, ulonglong == uint (i.e., unsigned long in C terms)
-            expected = r_uint(maxint64+1)
-        self.check(app_types.ulonglong, space.wrap(maxint64+1), expected)
-
-    def test_float_and_double(self):
-        space = self.space
-        self.check(app_types.float, space.wrap(12.34), r_singlefloat(12.34))
-        self.check(app_types.double, space.wrap(12.34), 12.34)
-
-    def test_pointer(self):
-        # pointers are "unsigned" at applevel, but signed at interp-level (for
-        # no good reason, at interp-level Signed or Unsigned makes no
-        # difference for passing bits around)
-        space = self.space
-        self.check(app_types.void_p, space.wrap(42), 42)
-        self.check(app_types.void_p, space.wrap(sys.maxint+1), -sys.maxint-1)
-        #
-        # typed pointers
-        w_ptr_sint = descr_new_pointer(space, None, app_types.sint)
-        self.check(w_ptr_sint, space.wrap(sys.maxint+1), -sys.maxint-1)
-
-
-    def test__as_ffi_pointer_(self):
-        space = self.space
-        w_MyPointerWrapper = space.appexec([], """():
-            import _ffi
-            class MyPointerWrapper(object):
-                def __init__(self, value):
-                    self.value = value
-                def _as_ffi_pointer_(self, ffitype):
-                    assert ffitype is _ffi.types.void_p
-                    return self.value
-
-            return MyPointerWrapper
-        """)
-        w_obj = space.call_function(w_MyPointerWrapper, space.wrap(42))
-        self.check(app_types.void_p, w_obj, 42)
-
-    def test_strings(self):
-        # first, try automatic conversion from applevel
-        self.check(app_types.char_p, self.space.wrapbytes('foo'), 'foo')
-        self.check(app_types.unichar_p, self.space.wrap(u'foo\u1234'), u'foo\u1234')    
-        self.check(app_types.unichar_p, self.space.wrap('foo'), u'foo')    
-        # then, try to pass explicit pointers
-        self.check(app_types.char_p, self.space.wrap(42), 42)
-        self.check(app_types.unichar_p, self.space.wrap(42), 42)        
-
-
-
-class DummyToAppLevelConverter(ToAppLevelConverter):
-
-    def get_all(self, w_ffitype):
-        return self.val
-
-    get_signed = get_all
-    get_unsigned = get_all
-    get_pointer = get_all
-    get_char = get_all        
-    get_unichar = get_all
-    get_longlong = get_all
-    get_char_p = get_all
-    get_unichar_p = get_all
-    get_float = get_all
-    get_singlefloat = get_all
-    get_unsigned_which_fits_into_a_signed = get_all
-    
-    def convert(self, w_ffitype, val):
-        self.val = val
-        return self.do_and_wrap(w_ffitype)
-
-
-class TestToAppLevel(object):
-    spaceconfig = dict(usemodules=('_ffi',))
-
-    def setup_class(cls):
-        converter = DummyToAppLevelConverter(cls.space)
-        cls.from_app_level = staticmethod(converter.convert)
-
-    def check(self, w_ffitype, val, w_expected):
-        w_v = self.from_app_level(w_ffitype, val)
-        assert self.space.eq_w(w_v, w_expected)
-
-    def test_int(self):
-        self.check(app_types.sint, 42, self.space.wrap(42))
-        self.check(app_types.sint, -sys.maxint-1, self.space.wrap(-sys.maxint-1))
-
-    def test_uint(self):
-        self.check(app_types.uint, 42, self.space.wrap(42))
-        self.check(app_types.uint, r_uint(sys.maxint+1), self.space.wrap(sys.maxint+1))
diff --git a/pypy/module/_multiprocessing/test/test_memory.py b/pypy/module/_multiprocessing/test/test_memory.py
--- a/pypy/module/_multiprocessing/test/test_memory.py
+++ b/pypy/module/_multiprocessing/test/test_memory.py
@@ -1,6 +1,6 @@
 class AppTestMemory:
     spaceconfig = dict(usemodules=('_multiprocessing', 'mmap',
-                                   '_rawffi', '_ffi'))
+                                   '_rawffi'))
 
     def test_address_of(self):
         import _multiprocessing
diff --git a/pypy/module/_rawffi/__init__.py b/pypy/module/_rawffi/__init__.py
--- a/pypy/module/_rawffi/__init__.py
+++ b/pypy/module/_rawffi/__init__.py
@@ -2,6 +2,7 @@
 """


More information about the pypy-commit mailing list