Commits

wlav committed 2886bd1

rpython fixes (r_longfloat not being fully supported)

Comments (0)

Files changed (3)

pypy/module/cppyy/converter.py

 from pypy.interpreter.error import OperationError, oefmt
 
 from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib.rarithmetic import r_singlefloat
-from rpython.rlib import jit_libffi, rfloat
+from rpython.rlib.rarithmetic import r_singlefloat, r_longfloat
+from rpython.rlib import jit, jit_libffi, rfloat
 
 from pypy.module._rawffi.interp_rawffi import letter2tp
 from pypy.module._rawffi.array import W_Array, W_ArrayInstance
         x = rffi.cast(rffi.VOIDPP, address)
         x[0] = call_local
 
+    def to_memory(self, space, w_obj, w_value, offset):
+        self._is_abstract(space)
+
+
 class IntTypeConverterMixin(NumericTypeConverterMixin):
     _mixin_ = True
 
 
 class ConstRefCharConverter(ffitypes.typeid(rffi.CHAR),
                             ConstRefCharTypeConverterMixin, TypeConverter):
-    _immuteable_ = True
+    _immutable_ = True
     uses_local = True
     libffitype = jit_libffi.types.pointer
 
 
 class ConstRefSCharConverter(ffitypes.typeid(rffi.SIGNEDCHAR),
                              ConstRefCharTypeConverterMixin, TypeConverter):
-    _immuteable_ = True
+    _immutable_ = True
     uses_local = True
     libffitype = jit_libffi.types.pointer
 
 
 class ConstFloatRefConverter(FloatConverter):
     _immutable_fields_ = ['libffitype', 'typecode']
-
     libffitype = jit_libffi.types.pointer
     typecode = 'F'
 
 
 class ConstDoubleRefConverter(ConstRefNumericTypeConverterMixin, DoubleConverter):
     _immutable_fields_ = ['libffitype', 'typecode']
-
     libffitype = jit_libffi.types.pointer
     typecode = 'D'
 
 
 class LongDoubleConverter(ffitypes.typeid(rffi.LONGDOUBLE), FloatTypeConverterMixin, TypeConverter):
-    _immutable_fields_ = ['default']
+    _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 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 looses precision
+        # TODO: this loses precision, but r_longfloat can not be wrapped
         return space.wrap(float(rffiptr[0]))
 
+    # 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', 'typecode']
+    _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
+
+
 class CStringConverter(TypeConverter):
     def convert_argument(self, space, w_obj, address, call_local):
         x = rffi.cast(rffi.LONGP, address)

pypy/module/cppyy/executor.py

     _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)
     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))

pypy/module/cppyy/ffitypes.py

     c_ptrtype   = rffi.LONGDOUBLEP
 
     def _unwrap_object(self, space, w_obj):
-        # TODO: this looses precision
-        return r_longfloat(space.float_w(w_obj))
+        return rffi.cast(rffi.LONGDOUBLE, r_longfloat(space.float_w(w_obj)))
 
     def _wrap_object(self, space, obj):
-        # TODO: this looses precision
+        # TODO: this loses precision
         return space.wrap(float(obj))