Author: Wim Lavrijsen <wlavrij...@lbl.gov>
Branch: cling-support
Changeset: r86435:0b1eabb9b806
Date: 2016-08-22 21:46 -0700
http://bitbucket.org/pypy/pypy/changeset/0b1eabb9b806/

Log:    complete fast path

diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -8,6 +8,8 @@
 from pypy.interpreter.error import oefmt
 
 from pypy.module._cffi_backend import ctypefunc, ctypeprim, cdataobj, misc
+from pypy.module._cffi_backend import newtype
+from pypy.module.cppyy import ffitypes
 
 from pypy.module.cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
    C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX, C_FUNC_PTR
@@ -90,35 +92,35 @@
         self.library = None
         self.capi_calls = {}
 
-        import pypy.module._cffi_backend.newtype as nt
+        nt = newtype     # module from _cffi_backend
+        state = space.fromcache(ffitypes.State)   # factored out common types
 
         # TODO: the following need to match up with the globally defined C_XYZ 
low-level
         # types (see capi/__init__.py), but by using strings here, that isn't 
guaranteed
-        c_opaque_ptr = nt.new_primitive_type(space, 'unsigned long')
+        c_opaque_ptr = state.c_ulong
  
         c_scope  = c_opaque_ptr
         c_type   = c_scope
         c_object = c_opaque_ptr
         c_method = c_opaque_ptr
-        c_index  = nt.new_primitive_type(space, 'long')
+        c_index  = state.c_long
+        c_index_array = state.c_voidp
 
-        c_void   = nt.new_void_type(space)
-        c_char   = nt.new_primitive_type(space, 'char')
-        c_uchar  = nt.new_primitive_type(space, 'unsigned char')
-        c_short  = nt.new_primitive_type(space, 'short')
-        c_int    = nt.new_primitive_type(space, 'int')
-        c_long   = nt.new_primitive_type(space, 'long')
-        c_llong  = nt.new_primitive_type(space, 'long long')
-        c_ullong = nt.new_primitive_type(space, 'unsigned long long')
-        c_float  = nt.new_primitive_type(space, 'float')
-        c_double = nt.new_primitive_type(space, 'double')
+        c_void   = state.c_void
+        c_char   = state.c_char
+        c_uchar  = state.c_uchar
+        c_short  = state.c_short
+        c_int    = state.c_int
+        c_long   = state.c_long
+        c_llong  = state.c_llong
+        c_ullong = state.c_ullong
+        c_float  = state.c_float
+        c_double = state.c_double
 
-        c_ccharp = nt.new_pointer_type(space, c_char)
-        c_index_array = nt.new_pointer_type(space, c_void)
+        c_ccharp = state.c_ccharp
+        c_voidp  = state.c_voidp
 
-        c_voidp  = nt.new_pointer_type(space, c_void)
         c_size_t = nt.new_primitive_type(space, 'size_t')
-
         c_ptrdiff_t = nt.new_primitive_type(space, 'ptrdiff_t')
 
         self.capi_call_ifaces = {
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -4,7 +4,7 @@
 
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib.rarithmetic import r_singlefloat
-from rpython.rlib import jit_libffi, rfloat
+from rpython.rlib import rfloat
 
 from pypy.module._rawffi.interp_rawffi import letter2tp
 from pypy.module._rawffi.array import W_Array, W_ArrayInstance
@@ -81,11 +81,11 @@
 
 
 class TypeConverter(object):
-    _immutable_fields_ = ['libffitype', 'uses_local', 'name']
+    _immutable_fields_ = ['cffi_name', 'uses_local', 'name']
 
-    libffitype = lltype.nullptr(jit_libffi.FFI_TYPE_P.TO)
+    cffi_name  = None
     uses_local = False
-    name = ""
+    name       = ""
 
     def __init__(self, space, extra):
         pass
@@ -103,6 +103,10 @@
         raise oefmt(space.w_TypeError,
                     "no converter available for '%s'", self.name)
 
+    def cffi_type(self, space):
+        from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
+        raise FastCallNotPossible
+
     def convert_argument(self, space, w_obj, address, call_local):
         self._is_abstract(space)
 
@@ -143,9 +147,7 @@
 
 class ArrayTypeConverterMixin(object):
     _mixin_ = True
-    _immutable_fields_ = ['libffitype', 'size']
-
-    libffitype = jit_libffi.types.pointer
+    _immutable_fields_ = ['size']
 
     def __init__(self, space, array_size):
         if array_size <= 0:
@@ -153,6 +155,10 @@
         else:
             self.size = array_size
 
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
+
     def from_memory(self, space, w_obj, w_pycppclass, offset):
         # read access, so no copy needed
         address_value = self._get_raw_address(space, w_obj, offset)
@@ -172,13 +178,15 @@
 
 class PtrTypeConverterMixin(object):
     _mixin_ = True
-    _immutable_fields_ = ['libffitype', 'size']
-
-    libffitype = jit_libffi.types.pointer
+    _immutable_fields_ = ['size']
 
     def __init__(self, space, array_size):
         self.size = sys.maxint
 
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
+
     def convert_argument(self, space, w_obj, address, call_local):
         w_tc = space.findattr(w_obj, space.wrap('typecode'))
         if w_tc is not None and space.str_w(w_tc) != self.typecode:
@@ -241,6 +249,10 @@
 
     uses_local = True
 
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
+
     def convert_argument_libffi(self, space, w_obj, address, call_local):
         assert rffi.sizeof(self.c_type) <= 2*rffi.sizeof(rffi.VOIDP)  # see 
interp_cppyy.py
         obj = self._unwrap_object(space, w_obj)
@@ -269,13 +281,15 @@
 
 
 class VoidConverter(TypeConverter):
-    _immutable_fields_ = ['libffitype', 'name']
-
-    libffitype = jit_libffi.types.void
+    _immutable_fields_ = ['name']
 
     def __init__(self, space, name):
         self.name = name
 
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_void
+
     def convert_argument(self, space, w_obj, address, call_local):
         self._is_abstract(space)
 
@@ -340,10 +354,12 @@
         return space.wrap(float(rffiptr[0]))
 
 class ConstFloatRefConverter(FloatConverter):
-    _immutable_fields_ = ['libffitype', 'typecode']
+    _immutable_fields_ = ['typecode']
+    typecode = 'f'
 
-    libffitype = jit_libffi.types.pointer
-    typecode = 'f'
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
 
     def convert_argument_libffi(self, space, w_obj, address, call_local):
         from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
@@ -359,12 +375,9 @@
             self.default = rffi.cast(self.c_type, 0.)
 
 class ConstDoubleRefConverter(ConstRefNumericTypeConverterMixin, 
DoubleConverter):
-    _immutable_fields_ = ['libffitype', 'typecode']
-
-    libffitype = jit_libffi.types.pointer
+    _immutable_fields_ = ['typecode']
     typecode = 'd'
 
-
 class CStringConverter(TypeConverter):
     def convert_argument(self, space, w_obj, address, call_local):
         x = rffi.cast(rffi.LONGP, address)
@@ -383,10 +396,6 @@
 
 
 class VoidPtrConverter(TypeConverter):
-    _immutable_fields_ = ['libffitype']
-
-    libffitype = jit_libffi.types.pointer
-
     def _unwrap_object(self, space, w_obj):
         try:
             obj = get_rawbuffer(space, w_obj)
@@ -399,6 +408,10 @@
                 obj = rffi.cast(rffi.VOIDP, get_rawobject(space, w_obj))
         return obj
 
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
+
     def convert_argument(self, space, w_obj, address, call_local):
         x = rffi.cast(rffi.VOIDPP, address)
         x[0] = self._unwrap_object(space, w_obj)
@@ -457,9 +470,7 @@
     typecode   = 'V'
 
 class InstanceRefConverter(TypeConverter):
-    _immutable_fields_ = ['libffitype', 'typecode', 'cppclass']
-
-    libffitype  = jit_libffi.types.pointer
+    _immutable_fields_ = ['typecode', 'cppclass']
     typecode    = 'V'
 
     def __init__(self, space, cppclass):
@@ -478,6 +489,10 @@
         raise oefmt(space.w_TypeError,
                     "cannot pass %T as %s", w_obj, self.cppclass.name)
 
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
+
     def convert_argument(self, space, w_obj, address, call_local):
         x = rffi.cast(rffi.VOIDPP, address)
         x[0] = rffi.cast(rffi.VOIDP, self._unwrap_object(space, w_obj))
@@ -596,9 +611,9 @@
 
 
 class PyObjectConverter(TypeConverter):
-    _immutable_fields_ = ['libffitype']
-
-    libffitype = jit_libffi.types.pointer
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
 
     def convert_argument(self, space, w_obj, address, call_local):
         if hasattr(space, "fake"):
@@ -745,7 +760,6 @@
                 self.default = rffi.cast(self.c_type, capi.c_strtoll(space, 
default))
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, 
BasicConverter):
             _immutable_ = True
-            libffitype = jit_libffi.types.pointer
         for name in names:
             _converters[name] = BasicConverter
             _converters["const "+name+"&"] = ConstRefConverter
@@ -763,7 +777,6 @@
                 self.default = rffi.cast(self.c_type, capi.c_strtoll(space, 
default))
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, 
BasicConverter):
             _immutable_ = True
-            libffitype = jit_libffi.types.pointer
         for name in names:
             _converters[name] = BasicConverter
             _converters["const "+name+"&"] = ConstRefConverter
@@ -784,7 +797,6 @@
                 self.default = rffi.cast(self.c_type, capi.c_strtoull(space, 
default))
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, 
BasicConverter):
             _immutable_ = True
-            libffitype = jit_libffi.types.pointer
         for name in names:
             _converters[name] = BasicConverter
             _converters["const "+name+"&"] = ConstRefConverter
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -27,13 +27,13 @@
 NULL = lltype.nullptr(jit_libffi.FFI_TYPE_P.TO)
 
 class FunctionExecutor(object):
-    _immutable_fields_ = ['libffitype']
-
-    libffitype = NULL
-
     def __init__(self, space, extra):
         pass
 
+    def cffi_type(self, space):
+        from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
+        raise FastCallNotPossible
+
     def execute(self, space, cppmethod, cppthis, num_args, args):
         raise oefmt(space.w_TypeError,
                     "return type not available or supported")
@@ -44,10 +44,12 @@
 
 
 class PtrTypeExecutor(FunctionExecutor):
-    _immutable_fields_ = ['libffitype', 'typecode']
+    _immutable_fields_ = ['typecode']
+    typecode = 'P'
 
-    libffitype = jit_libffi.types.pointer
-    typecode = 'P'
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
 
     def execute(self, space, cppmethod, cppthis, num_args, args):
         if hasattr(space, "fake"):
@@ -62,9 +64,9 @@
 
 
 class VoidExecutor(FunctionExecutor):
-    _immutable_fields_ = ['libffitype']
-
-    libffitype = jit_libffi.types.void
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_void
 
     def execute(self, space, cppmethod, cppthis, num_args, args):
         capi.c_call_v(space, cppmethod, cppthis, num_args, args)
@@ -143,14 +145,16 @@
 
 
 class InstancePtrExecutor(FunctionExecutor):
-    _immutable_fields_ = ['libffitype', 'cppclass']
-
-    libffitype = jit_libffi.types.pointer
+    _immutable_fields_ = ['cppclass']
 
     def __init__(self, space, cppclass):
         FunctionExecutor.__init__(self, space, cppclass)
         self.cppclass = cppclass
 
+    def cffi_type(self, space):
+        state = space.fromcache(ffitypes.State)
+        return state.c_voidp
+
     def execute(self, space, cppmethod, cppthis, num_args, args):
         from pypy.module.cppyy import interp_cppyy
         long_result = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
@@ -331,8 +335,9 @@
             _immutable_ = True
             c_stubcall  = staticmethod(stub)
         class BasicRefExecutor(ffitypes.typeid(c_type), 
NumericRefExecutorMixin, FunctionExecutor):
-            _immutable_fields_ = ['libffitype']
-            libffitype = jit_libffi.types.pointer
+            def cffi_type(self, space):
+                state = space.fromcache(ffitypes.State)
+                return state.c_voidp
         for name in names:
             _executors[name]              = BasicExecutor
             _executors[name+'&']          = BasicRefExecutor
diff --git a/pypy/module/cppyy/ffitypes.py b/pypy/module/cppyy/ffitypes.py
--- a/pypy/module/cppyy/ffitypes.py
+++ b/pypy/module/cppyy/ffitypes.py
@@ -2,19 +2,50 @@
 
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rlib.rarithmetic import r_singlefloat
-from rpython.rlib import jit_libffi, rfloat
 
-# Mixins to share between converter and executor classes (in converter.py and
-# executor.py, respectively). Basically these mixins allow grouping of the
-# sets of jit_libffi, rffi, and different space unwrapping calls. To get the
-# right mixin, a non-RPython function typeid() is used.
+from pypy.module._cffi_backend import newtype
+
+# Mixins to refactor type-specific codef from converter and executor classes
+# (in converter.py and executor.py, respectively). To get the right mixin, a
+# non-RPython function typeid() is used.
+
+class State(object):
+    def __init__(self, space):
+        self.library = None
+        self.capi_calls = {}
+
+        nt = newtype     # module from _cffi_backend
+
+        # builtin types
+        self.c_void    = nt.new_void_type(space)
+        self.c_bool    = nt.new_primitive_type(space, '_Bool')
+        self.c_char    = nt.new_primitive_type(space, 'char')
+        self.c_uchar   = nt.new_primitive_type(space, 'unsigned char')
+        self.c_short   = nt.new_primitive_type(space, 'short')
+        self.c_ushort  = nt.new_primitive_type(space, 'unsigned short')
+        self.c_int     = nt.new_primitive_type(space, 'int')
+        self.c_uint    = nt.new_primitive_type(space, 'unsigned int')
+        self.c_long    = nt.new_primitive_type(space, 'long')
+        self.c_ulong   = nt.new_primitive_type(space, 'unsigned long')
+        self.c_llong   = nt.new_primitive_type(space, 'long long')
+        self.c_ullong  = nt.new_primitive_type(space, 'unsigned long long')
+        self.c_float   = nt.new_primitive_type(space, 'float')
+        self.c_double  = nt.new_primitive_type(space, 'double')
+        self.c_ldouble = nt.new_primitive_type(space, 'long double')
+        
+        # pointer types
+        self.c_ccharp = nt.new_pointer_type(space, self.c_char)
+        self.c_voidp  = nt.new_pointer_type(space, self.c_void)
+
+        # special types
+        self.c_size_t    = nt.new_primitive_type(space, 'size_t')
+        self.c_ptrdiff_t = nt.new_primitive_type(space, 'ptrdiff_t')
 
 
 class BoolTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.uchar
     c_type      = rffi.UCHAR
     c_ptrtype   = rffi.UCHARP
 
@@ -28,11 +59,14 @@
     def _wrap_object(self, space, obj):
         return space.wrap(bool(ord(rffi.cast(rffi.CHAR, obj))))
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_bool
+
 class CharTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.schar
     c_type      = rffi.CHAR
     c_ptrtype   = rffi.CCHARP           # there's no such thing as rffi.CHARP
 
@@ -52,100 +86,126 @@
                         "char expected, got string of size %d", len(value))
         return value[0] # turn it into a "char" to the annotator
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_char
+
 class ShortTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.sshort
     c_type      = rffi.SHORT
     c_ptrtype   = rffi.SHORTP
 
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(rffi.SHORT, space.int_w(w_obj))
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_short
+
 class UShortTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.ushort
     c_type      = rffi.USHORT
     c_ptrtype   = rffi.USHORTP
 
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(self.c_type, space.int_w(w_obj))
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_ushort
+
 class IntTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.sint
     c_type      = rffi.INT
     c_ptrtype   = rffi.INTP
-    ctype_name  = 'int'
 
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(self.c_type, space.c_int_w(w_obj))
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_int
+
 class UIntTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.uint
     c_type      = rffi.UINT
     c_ptrtype   = rffi.UINTP
 
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(self.c_type, space.uint_w(w_obj))
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_uint
+
 class LongTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.slong
     c_type      = rffi.LONG
     c_ptrtype   = rffi.LONGP
 
     def _unwrap_object(self, space, w_obj):
         return space.int_w(w_obj)
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_long
+
 class ULongTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.ulong
     c_type      = rffi.ULONG
     c_ptrtype   = rffi.ULONGP
 
     def _unwrap_object(self, space, w_obj):
         return space.uint_w(w_obj)
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_ulong
+
 class LongLongTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.sint64
     c_type      = rffi.LONGLONG
     c_ptrtype   = rffi.LONGLONGP
 
     def _unwrap_object(self, space, w_obj):
         return space.r_longlong_w(w_obj)
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_llong
+
 class ULongLongTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+    _immutable_fields_ = ['c_type', 'c_ptrtype']
 
-    libffitype  = jit_libffi.types.uint64
     c_type      = rffi.ULONGLONG
     c_ptrtype   = rffi.ULONGLONGP
 
     def _unwrap_object(self, space, w_obj):
         return space.r_ulonglong_w(w_obj)
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_ullong
+
 class FloatTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype', 'typecode']
+    _immutable_fields_ = ['c_type', 'c_ptrtype', 'typecode']
 
-    libffitype  = jit_libffi.types.float
     c_type      = rffi.FLOAT
     c_ptrtype   = rffi.FLOATP
     typecode    = 'f'
@@ -156,11 +216,14 @@
     def _wrap_object(self, space, obj):
         return space.wrap(float(obj))
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_float
+
 class DoubleTypeMixin(object):
     _mixin_     = True
-    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype', 'typecode']
+    _immutable_fields_ = ['c_type', 'c_ptrtype', 'typecode']
 
-    libffitype  = jit_libffi.types.double
     c_type      = rffi.DOUBLE
     c_ptrtype   = rffi.DOUBLEP
     typecode    = 'd'
@@ -168,6 +231,24 @@
     def _unwrap_object(self, space, w_obj):
         return space.float_w(w_obj)
 
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_double
+
+class LongDoubleTypeMixin(object):
+    _mixin_     = True
+    _immutable_fields_ = ['c_type', 'c_ptrtype', 'typecode']
+
+    c_type      = rffi.LONGDOUBLE
+    c_ptrtype   = rffi.LONGDOUBLEP
+    typecode    = 'D'
+
+    def _unwrap_object(self, space, w_obj):
+        return space.float_w(w_obj)
+
+    def cffi_type(self, space):
+        state = space.fromcache(State)
+        return state.c_ldouble
 
 def typeid(c_type):
     "NOT_RPYTHON"
@@ -183,6 +264,7 @@
     if c_type == rffi.ULONGLONG:  return ULongLongTypeMixin
     if c_type == rffi.FLOAT:      return FloatTypeMixin
     if c_type == rffi.DOUBLE:     return DoubleTypeMixin
+    if c_type == rffi.LONGDOUBLE: return LongDoubleTypeMixin
 
     # should never get here
     raise TypeError("unknown rffi type: %s" % c_type)
diff --git a/pypy/module/cppyy/interp_cppyy.py 
b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -11,8 +11,8 @@
 from rpython.rlib import jit_libffi, clibffi
 from rpython.rlib.objectmodel import we_are_translated, keepalive_until_here
 
-from pypy.module._cffi_backend import ctypefunc, newtype
-from pypy.module.cppyy import converter, executor, helper
+from pypy.module._cffi_backend import ctypefunc
+from pypy.module.cppyy import converter, executor, ffitypes, helper
 
 
 class FastCallNotPossible(Exception):
@@ -209,7 +209,7 @@
         if self.converters is None:
             try:
                 self._setup(cppthis)
-            except Exception as e:
+            except Exception:
                 pass
 
         # some calls, e.g. for ptr-ptr or reference need a local array to 
store data for
@@ -261,6 +261,7 @@
                 data = capi.exchange_address(buffer, cif_descr, j+1)
                 conv.default_argument_libffi(self.space, data)
 
+            assert self._funcaddr
             w_res = self.executor.execute_libffi(
                 self.space, cif_descr, self._funcaddr, buffer)
         finally:
@@ -326,14 +327,17 @@
         # uniquely defined and needs to be setup only once.
         self._funcaddr = capi.c_get_function_address(self.space, self.scope, 
self.index)
         if self._funcaddr and cppthis:      # methods only for now
+            state = self.space.fromcache(ffitypes.State)
+
             # argument type specification (incl. cppthis)
             fargs = []
-            fargs.append(newtype.new_pointer_type(self.space, 
newtype.new_void_type(self.space)))
-            for i, conv in enumerate(self.converters):
-                 if not conv.libffitype:
-                     raise FastCallNotPossible
-                 fargs.append(newtype.new_primitive_type(self.space, 
conv.ctype_name))
-            fresult = newtype.new_primitive_type(self.space, 
self.executor.ctype_name)
+            try:
+                fargs.append(state.c_voidp)
+                for i, conv in enumerate(self.converters):
+                    fargs.append(conv.cffi_type(self.space))
+                fresult = self.executor.cffi_type(self.space)
+            except:
+                raise FastCallNotPossible
 
             # the following is derived from _cffi_backend.ctypefunc
             builder = ctypefunc.CifDescrBuilder(fargs[:], fresult, 
clibffi.FFI_DEFAULT_ABI)
diff --git a/pypy/module/cppyy/test/test_zjit.py 
b/pypy/module/cppyy/test/test_zjit.py
--- a/pypy/module/cppyy/test/test_zjit.py
+++ b/pypy/module/cppyy/test/test_zjit.py
@@ -89,9 +89,10 @@
     def get_raw_address(self):
         raise ValueError("no raw buffer")
 class FakeException(FakeType):
-    def __init__(self, name):
+    def __init__(self, space, name):
         FakeType.__init__(self, name)
         self.msg = name
+        self.space = space
 
 class FakeUserDelAction(object):
     def __init__(self, space):
@@ -110,15 +111,6 @@
 class FakeSpace(object):
     fake = True
 
-    w_AttributeError      = FakeException("AttributeError")
-    w_KeyError            = FakeException("KeyError")
-    w_NotImplementedError = FakeException("NotImplementedError")
-    w_ReferenceError      = FakeException("ReferenceError")
-    w_RuntimeError        = FakeException("RuntimeError")
-    w_SystemError         = FakeException("SystemError")
-    w_TypeError           = FakeException("TypeError")
-    w_ValueError          = FakeException("ValueError")
-
     w_None = None
     w_str = FakeType("str")
     w_int = FakeType("int")
@@ -137,6 +129,15 @@
             return capi.c_call_i(space, cppmethod, cppobject, nargs, args)
         executor.get_executor(self, 'int').__class__.c_stubcall = 
staticmethod(c_call_i)
 
+        self.w_AttributeError      = FakeException(self, "AttributeError")
+        self.w_KeyError            = FakeException(self, "KeyError")
+        self.w_NotImplementedError = FakeException(self, "NotImplementedError")
+        self.w_ReferenceError      = FakeException(self, "ReferenceError")
+        self.w_RuntimeError        = FakeException(self, "RuntimeError")
+        self.w_SystemError         = FakeException(self, "SystemError")
+        self.w_TypeError           = FakeException(self, "TypeError")
+        self.w_ValueError          = FakeException(self, "ValueError")
+
     def issequence_w(self, w_obj):
         return True
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to