[pypy-commit] pypy reflex-support: remove long double support during translation for now (it produces uncompilable code)

wlav noreply at buildbot.pypy.org
Wed May 7 00:00:42 CEST 2014


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r71347:f79785955a7d
Date: 2014-05-06 14:59 -0700
http://bitbucket.org/pypy/pypy/changeset/f79785955a7d/

Log:	remove long double support during translation for now (it produces
	uncompilable code)

diff --git a/pypy/module/cppyy/__init__.py b/pypy/module/cppyy/__init__.py
--- a/pypy/module/cppyy/__init__.py
+++ b/pypy/module/cppyy/__init__.py
@@ -43,3 +43,9 @@
         capi.verify_backend(space)      # may raise ImportError
 
         space.call_method(space.wrap(self), '_init_pythonify')
+
+    def setup_after_space_initialization(self):
+        """NOT_RPYTHON"""
+        from pypy.module.cppyy import converter, executor
+        converter._install_converters(self.space)
+        executor._install_executors(self.space)
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, r_longfloat
-from rpython.rlib import jit, jit_libffi, rfloat
+from rpython.rlib import jit_libffi, objectmodel, rfloat
 
 from pypy.module._rawffi.interp_rawffi import letter2tp
 from pypy.module._rawffi.array import W_Array, W_ArrayInstance
@@ -216,6 +216,9 @@
 class NumericTypeConverterMixin(object):
     _mixin_ = True
 
+    def _wrap_object(self, space, obj):
+        return space.wrap(obj)
+
     def convert_argument_libffi(self, space, w_obj, address, call_local):
         x = rffi.cast(self.c_ptrtype, address)
         x[0] = self._unwrap_object(space, w_obj)
@@ -227,7 +230,7 @@
     def from_memory(self, space, w_obj, w_pycppclass, offset):
         address = self._get_raw_address(space, w_obj, offset)
         rffiptr = rffi.cast(self.c_ptrtype, address)
-        return space.wrap(rffiptr[0])
+        return self._wrap_object(space, rffiptr[0])
 
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
@@ -248,7 +251,7 @@
         x[0] = call_local
 
     def to_memory(self, space, w_obj, w_value, offset):
-        self._is_abstract(space)
+        raise OperationError(space.w_TypeError, space.wrap("can not assign to reference"))
 
 
 class IntTypeConverterMixin(NumericTypeConverterMixin):
@@ -398,86 +401,30 @@
     typecode = 'D'
 
 
-class LongDoubleConverter(ffitypes.typeid(rffi.LONGDOUBLE), FloatTypeConverterMixin, TypeConverter):
-    _immutable_fields_ = ['default', 'typecode']
-    typecode = 'Q'
+if not objectmodel.we_are_translated():
+    # r_longfloat isn't supported in translation
+    class LongDoubleConverter(ffitypes.typeid(rffi.LONGDOUBLE), FloatTypeConverterMixin, TypeConverter):
+        _immutable_fields_ = ['default', 'typecode']
+        typecode = 'Q'
 
-    @jit.dont_look_inside
-    def __init__(self, space, default):
-        # TODO: loses precision
-        if default:
-            self.default = rffi.cast(self.c_type, rfloat.rstring_to_float(default))
-        else:
-            self.default = rffi.cast(self.c_type, 0.)
+        def __init__(self, space, default):
+            # TODO: loses precision
+            if default:
+                self.default = rffi.cast(self.c_type, rfloat.rstring_to_float(default))
+            else:
+                self.default = rffi.cast(self.c_type, 0.)
 
-    def default_argument_libffi(self, space, address):
-        from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
-        raise FastCallNotPossible
+        def _wrap_object(self, space, obj):
+            # TODO: this loses precision, but r_longfloat can not be wrapped
+            return space.wrap(float(obj))
 
-    @jit.dont_look_inside
-    def from_memory(self, space, w_obj, w_pycppclass, offset):
-        address = self._get_raw_address(space, w_obj, offset)
-        rffiptr = rffi.cast(self.c_ptrtype, address)
-        # TODO: this loses precision, but r_longfloat can not be wrapped
-        return space.wrap(float(rffiptr[0]))
+    class ConstLongDoubleRefConverter(ConstRefNumericTypeConverterMixin, LongDoubleConverter):
+        _immutable_fields_ = ['libffitype']
+        libffitype = jit_libffi.types.pointer
 
-    # repeats to suppress: "[jitcodewriter:WARNING] type LongFloat is too large, ignoring graph"
-    @jit.dont_look_inside
-    def convert_argument(self, space, w_obj, address, call_local):
-        x = rffi.cast(self.c_ptrtype, address)
-        x[0] = self._unwrap_object(space, w_obj)
-        ba = rffi.cast(rffi.CCHARP, address)
-        ba[capi.c_function_arg_typeoffset(space)] = self.typecode
-
-    @jit.dont_look_inside 
-    def convert_argument_libffi(self, space, w_obj, address, call_local):
-        x = rffi.cast(self.c_ptrtype, address)
-        x[0] = self._unwrap_object(space, w_obj)
-
-    @jit.dont_look_inside
-    def default_argument_libffi(self, space, address):
-        x = rffi.cast(self.c_ptrtype, address) 
-        x[0] = self.default
-
-    @jit.dont_look_inside
-    def to_memory(self, space, w_obj, w_value, offset):
-        address = self._get_raw_address(space, w_obj, offset)
-        rffiptr = rffi.cast(self.c_ptrtype, address)   
-        rffiptr[0] = self._unwrap_object(space, w_value)
-
-
-class ConstLongDoubleRefConverter(ConstRefNumericTypeConverterMixin, LongDoubleConverter):
-    _immutable_fields_ = ['libffitype']
-    libffitype = jit_libffi.types.pointer
-
-    def convert_argument_libffi(self, space, w_obj, address, call_local):
-        from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
-        raise FastCallNotPossible
-
-    def default_argument_libffi(self, space, address):
-        # suppress: "[jitcodewriter:WARNING] type LongFloat is too large, ignoring graph"
-        from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
-        raise FastCallNotPossible
-
-    @jit.dont_look_inside
-    def from_memory(self, space, w_obj, w_pycppclass, offset):
-        address = self._get_raw_address(space, w_obj, offset)
-        rffiptr = rffi.cast(self.c_ptrtype, address)
-        # TODO: this loses precision, but r_longfloat can not be wrapped
-        return space.wrap(float(rffiptr[0]))
-
-    # repeatss to suppress: "[jitcodewriter:WARNING] type LongFloat is too large, ignoring graph"
-    @jit.dont_look_inside
-    def convert_argument(self, space, w_obj, address, call_local):
-        x = rffi.cast(self.c_ptrtype, address)
-        x[0] = self._unwrap_object(space, w_obj)
-        ba = rffi.cast(rffi.CCHARP, address)
-        ba[capi.c_function_arg_typeoffset(space)] = self.typecode
-
-    @jit.dont_look_inside
-    def default_argument_libffi(self, space, address):
-        x = rffi.cast(self.c_ptrtype, address)
-        x[0] = self.default
+        def _wrap_object(self, space, obj):
+            # TODO: this loses precision, but r_longfloat can not be wrapped
+            return space.wrap(float(obj))
 
 
 class CStringConverter(TypeConverter):
@@ -812,32 +759,94 @@
     return VoidConverter(space, name)
 
 
-_converters["bool"]                     = BoolConverter
-_converters["char"]                     = CharConverter
-_converters["const char&"]              = ConstRefCharConverter
-_converters["signed char"]              = SCharConverter
-_converters["const signed char&"]       = ConstRefSCharConverter
-_converters["float"]                    = FloatConverter
-_converters["const float&"]             = ConstFloatRefConverter
-_converters["double"]                   = DoubleConverter
-_converters["const double&"]            = ConstDoubleRefConverter
-_converters["long double"]              = LongDoubleConverter
-_converters["const long double&"]       = ConstLongDoubleRefConverter
-_converters["const char*"]              = CStringConverter
-_converters["void*"]                    = VoidPtrConverter
-_converters["void**"]                   = VoidPtrPtrConverter
-_converters["void*&"]                   = VoidPtrRefConverter
+def _install_converters(space):
+    "NOT_RPYTHON"
+    global _converters
+    if not space.config.translating:
+        # r_longfloat isn't supported in translation
+        class LongDoubleConverter(ffitypes.typeid(rffi.LONGDOUBLE), FloatTypeConverterMixin, TypeConverter):
+            _immutable_fields_ = ['default', 'typecode']
+            typecode = 'Q'
 
-# special cases (note: 'string' aliases added below)
-_converters["std::basic_string<char>"]           = StdStringConverter
-_converters["const std::basic_string<char>&"]    = StdStringConverter     # TODO: shouldn't copy
-_converters["std::basic_string<char>&"]          = StdStringRefConverter
+            def __init__(self, space, default):
+                # TODO: loses precision
+                if default:
+                    self.default = rffi.cast(self.c_type, rfloat.rstring_to_float(default))
+                else:
+                    self.default = rffi.cast(self.c_type, 0.)
 
-_converters["PyObject*"]                         = PyObjectConverter
+            def _wrap_object(self, space, obj):
+                # TODO: this loses precision, but r_longfloat can not be wrapped
+                return space.wrap(float(obj))
 
-_converters["#define"]                           = MacroConverter
+        class ConstLongDoubleRefConverter(ConstRefNumericTypeConverterMixin, LongDoubleConverter):
+            _immutable_fields_ = ['libffitype']
+            libffitype = jit_libffi.types.pointer
 
-# add basic (builtin) converters
+            def _wrap_object(self, space, obj):
+                # TODO: this loses precision, but r_longfloat can not be wrapped
+                return space.wrap(float(obj))
+
+    _converters["bool"]                     = BoolConverter
+    _converters["char"]                     = CharConverter
+    _converters["const char&"]              = ConstRefCharConverter
+    _converters["signed char"]              = SCharConverter
+    _converters["const signed char&"]       = ConstRefSCharConverter
+    _converters["float"]                    = FloatConverter
+    _converters["const float&"]             = ConstFloatRefConverter
+    _converters["double"]                   = DoubleConverter
+    _converters["const double&"]            = ConstDoubleRefConverter
+    if not space.config.translating:
+        # r_longfloat isn't supported in translation
+        _converters["long double"]              = LongDoubleConverter
+        _converters["const long double&"]       = ConstLongDoubleRefConverter
+    _converters["const char*"]              = CStringConverter
+    _converters["void*"]                    = VoidPtrConverter
+    _converters["void**"]                   = VoidPtrPtrConverter
+    _converters["void*&"]                   = VoidPtrRefConverter
+
+    # special cases (note: 'string' aliases added below)
+    _converters["std::basic_string<char>"]           = StdStringConverter
+    _converters["const std::basic_string<char>&"]    = StdStringConverter     # TODO: shouldn't copy
+    _converters["std::basic_string<char>&"]          = StdStringRefConverter
+
+    _converters["PyObject*"]                         = PyObjectConverter
+
+    _converters["#define"]                           = MacroConverter
+
+    # add basic (builtin) converters
+    _build_basic_converters()
+
+    # create the array and pointer converters; all real work is in the mixins
+    _build_array_converters()
+
+    # add another set of aliased names
+    _add_aliased_converters()
+
+    # ROOT-specific converters (TODO: this is a general use case and should grow
+    # an API; putting it here is done only to circumvent circular imports)
+    if capi.identify() == "CINT":
+
+        class TStringConverter(InstanceConverter):
+            def __init__(self, space, extra):
+                from pypy.module.cppyy import interp_cppyy
+                cppclass = interp_cppyy.scope_byname(space, "TString")
+                InstanceConverter.__init__(self, space, cppclass)
+
+            def _unwrap_object(self, space, w_obj):
+               from pypy.module.cppyy import interp_cppyy
+               if isinstance(w_obj, interp_cppyy.W_CPPInstance):
+                   arg = InstanceConverter._unwrap_object(self, space, w_obj)
+                   return capi.backend.c_TString2TString(space, arg)
+               else:
+                   return capi.backend.c_charp2TString(space, space.str_w(w_obj))
+
+            def free_argument(self, space, arg, call_local):
+                capi.c_destruct(space, self.cppclass, rffi.cast(capi.C_OBJECT, rffi.cast(rffi.VOIDPP, arg)[0]))
+
+        _converters["TString"]        = TStringConverter
+        _converters["const TString&"] = TStringConverter
+
 def _build_basic_converters():
     "NOT_RPYTHON"
     # signed types (use strtoll in setting of default in __init__)
@@ -904,9 +913,7 @@
         for name in names:
             _converters[name] = BasicConverter
             _converters["const "+name+"&"] = ConstRefConverter
-_build_basic_converters()
 
-# create the array and pointer converters; all real work is in the mixins
 def _build_array_converters():
     "NOT_RPYTHON"
     array_info = (
@@ -931,9 +938,7 @@
         for name in names:
             _a_converters[name+'[]'] = ArrayConverter
             _a_converters[name+'*']  = PtrConverter
-_build_array_converters()
 
-# add another set of aliased names
 def _add_aliased_converters():
     "NOT_RPYTHON"
     aliases = (
@@ -950,31 +955,6 @@
 
         ("PyObject*",                       "_object*"),
     )
- 
+
     for c_type, alias in aliases:
         _converters[alias] = _converters[c_type]
-_add_aliased_converters()
-
-# ROOT-specific converters (TODO: this is a general use case and should grow
-# an API; putting it here is done only to circumvent circular imports)
-if capi.identify() == "CINT":
-
-    class TStringConverter(InstanceConverter):
-        def __init__(self, space, extra):
-            from pypy.module.cppyy import interp_cppyy
-            cppclass = interp_cppyy.scope_byname(space, "TString")
-            InstanceConverter.__init__(self, space, cppclass)
-
-        def _unwrap_object(self, space, w_obj):
-            from pypy.module.cppyy import interp_cppyy
-            if isinstance(w_obj, interp_cppyy.W_CPPInstance):
-                arg = InstanceConverter._unwrap_object(self, space, w_obj)
-                return capi.backend.c_TString2TString(space, arg)
-            else:
-                return capi.backend.c_charp2TString(space, space.str_w(w_obj))
-
-        def free_argument(self, space, arg, call_local):
-            capi.c_destruct(space, self.cppclass, rffi.cast(capi.C_OBJECT, rffi.cast(rffi.VOIDPP, arg)[0]))
-
-    _converters["TString"]        = TStringConverter
-    _converters["const TString&"] = TStringConverter
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
@@ -122,49 +122,6 @@
             rffi.cast(self.c_ptrtype, rffi.cast(rffi.VOIDPP, result)[0]))
 
 
-class LongDoubleExecutor(ffitypes.typeid(rffi.LONGDOUBLE), NumericExecutorMixin, FunctionExecutor):
-    # exists to suppress: "[jitcodewriter:WARNING] type LongFloat is too large, ignoring graph"
-    _immutable_ = True
-    c_stubcall  = staticmethod(capi.c_call_ld)
-
-    def _wrap_object(self, space, obj):
-        # TODO: this loses precision, but r_longfloat can not be wrapped
-        return space.wrap(float(obj))
-
-    @jit.dont_look_inside
-    def execute(self, space, cppmethod, cppthis, num_args, args):
-        result = self.c_stubcall(space, cppmethod, cppthis, num_args, args)
-        return self._wrap_object(space, rffi.cast(self.c_type, result))
-
-    def execute_libffi(self, space, cif_descr, funcaddr, buffer):
-        from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
-        raise FastCallNotPossible
-
-class LongDoubleRefExecutor(ffitypes.typeid(rffi.LONGDOUBLE),
-                            NumericRefExecutorMixin, FunctionExecutor):
-    # exists to suppress: "[jitcodewriter:WARNING] type LongFloat is too large, ignoring graph"
-    _immutable_fields_ = ['libffitype']
-    libffitype = jit_libffi.types.pointer
-
-    @jit.dont_look_inside
-    def set_item(self, space, w_item):
-        self.item = self._unwrap_object(space, w_item)
-        self.do_assign = True
-
-    def _wrap_object(self, space, obj):
-        # TODO: this loses precision, but r_longfloat can not be wrapped
-        return space.wrap(float(rffi.cast(self.c_type, obj)))
-
-    @jit.dont_look_inside
-    def execute(self, space, cppmethod, cppthis, num_args, args):
-        result = capi.c_call_r(space, cppmethod, cppthis, num_args, args)
-        return self._wrap_reference(space, rffi.cast(self.c_ptrtype, result))
-
-    def execute_libffi(self, space, cif_descr, funcaddr, buffer):
-        from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
-        raise FastCallNotPossible
-
-
 class CStringExecutor(FunctionExecutor):
 
     def execute(self, space, cppmethod, cppthis, num_args, args):
@@ -335,25 +292,36 @@
 
     # currently used until proper lazy instantiation available in interp_cppyy
     return FunctionExecutor(space, None)
- 
 
-_executors["void"]                = VoidExecutor
-_executors["void*"]               = PtrTypeExecutor
-_executors["const char*"]         = CStringExecutor
 
-# special cases (note: 'string' aliases added below)
-_executors["constructor"]         = ConstructorExecutor
+def _install_executors(space):
+    "NOT_RPYTHON"
+    global _executors
+    _executors["void"]                = VoidExecutor
+    _executors["void*"]               = PtrTypeExecutor
+    _executors["const char*"]         = CStringExecutor
 
-_executors["std::basic_string<char>"]         = StdStringExecutor
-_executors["const std::basic_string<char>&"]  = StdStringRefExecutor
-_executors["std::basic_string<char>&"]        = StdStringRefExecutor
+    # special cases (note: 'string' aliases added below)
+    _executors["constructor"]         = ConstructorExecutor
 
-_executors["PyObject*"]           = PyObjectExecutor
+    _executors["std::basic_string<char>"]         = StdStringExecutor
+    _executors["const std::basic_string<char>&"]  = StdStringRefExecutor
+    _executors["std::basic_string<char>&"]        = StdStringRefExecutor
 
-# add basic (builtin) executors
-def _build_basic_executors():
+    _executors["PyObject*"]           = PyObjectExecutor
+
+    # add basic (builtin) executors
+    _build_basic_executors(space)
+
+    # add pointer type executors
+    _build_ptr_executors()
+
+    # add another set of aliased names
+    _add_aliased_executors()
+
+def _build_basic_executors(space):
     "NOT_RPYTHON"
-    type_info = (
+    type_info = [
         (bool,            capi.c_call_b,   ("bool",)),
         (rffi.CHAR,       capi.c_call_c,   ("char", "unsigned char")),
         (rffi.SIGNEDCHAR, capi.c_call_c,   ("signed char",)),
@@ -366,7 +334,10 @@
         (rffi.ULONGLONG,  capi.c_call_ll,  ("unsigned long long", "unsigned long long int")),
         (rffi.FLOAT,      capi.c_call_f,   ("float",)),
         (rffi.DOUBLE,     capi.c_call_d,   ("double",)),
-    )
+    ]
+
+    if not space.config.translating:
+        type_info.append((rffi.LONGDOUBLE, capi.c_call_ld,  ("long double",)))
 
     for c_type, stub, names in type_info:
         class BasicExecutor(ffitypes.typeid(c_type), NumericExecutorMixin, FunctionExecutor):
@@ -379,11 +350,6 @@
             _executors[name]              = BasicExecutor
             _executors[name+'&']          = BasicRefExecutor
             _executors['const '+name+'&'] = BasicRefExecutor     # no copy needed for builtins
-    # exists to suppress: "[jitcodewriter:WARNING] type LongFloat is too large, ignoring graph"
-    _executors["long double"]             = LongDoubleExecutor
-    _executors["long double&"]            = LongDoubleRefExecutor
-    _executors["const long double&"]      = LongDoubleRefExecutor
-_build_basic_executors()
 
 # create the pointer executors; all real work is in the PtrTypeExecutor, since
 # all pointer types are of the same size
@@ -407,9 +373,7 @@
             typecode = tcode
         for name in names:
             _executors[name+'*'] = PtrExecutor
-_build_ptr_executors()
 
-# add another set of aliased names
 def _add_aliased_executors():
     "NOT_RPYTHON"
     aliases = (
@@ -424,4 +388,3 @@
 
     for c_type, alias in aliases:
         _executors[alias] = _executors[c_type]
-_add_aliased_executors()
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
@@ -103,7 +103,12 @@
         self.user_del_action = FakeUserDelAction(self)
         class dummy: pass
         self.config = dummy()
-        self.config.translating = False
+        self.config.translating = True
+
+        # otherwise called through setup_after_space_initialization()
+        from pypy.module.cppyy import converter, executor
+        converter._install_converters(self)
+        executor._install_executors(self)
 
     def issequence_w(self, w_obj):
         return True


More information about the pypy-commit mailing list