[pypy-commit] pypy reflex-support: rpython fixes (r_longfloat not being fully supported)
wlav
noreply at buildbot.pypy.org
Tue May 6 10:34:53 CEST 2014
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r71320:2886bd193622
Date: 2014-05-06 01:33 -0700
http://bitbucket.org/pypy/pypy/changeset/2886bd193622/
Log: rpython fixes (r_longfloat not being fully supported)
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
@@ -3,8 +3,8 @@
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
@@ -247,6 +247,10 @@
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
@@ -330,7 +334,7 @@
class ConstRefCharConverter(ffitypes.typeid(rffi.CHAR),
ConstRefCharTypeConverterMixin, TypeConverter):
- _immuteable_ = True
+ _immutable_ = True
uses_local = True
libffitype = jit_libffi.types.pointer
@@ -347,7 +351,7 @@
class ConstRefSCharConverter(ffitypes.typeid(rffi.SIGNEDCHAR),
ConstRefCharTypeConverterMixin, TypeConverter):
- _immuteable_ = True
+ _immutable_ = True
uses_local = True
libffitype = jit_libffi.types.pointer
@@ -372,7 +376,6 @@
class ConstFloatRefConverter(FloatConverter):
_immutable_fields_ = ['libffitype', 'typecode']
-
libffitype = jit_libffi.types.pointer
typecode = 'F'
@@ -391,41 +394,92 @@
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)
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
@@ -127,6 +127,10 @@
_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)
@@ -143,6 +147,15 @@
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))
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
@@ -208,11 +208,10 @@
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))
More information about the pypy-commit
mailing list