[pypy-commit] pypy ffi-backend: Separate the parts that the JIT should see from the others.
arigo
noreply at buildbot.pypy.org
Wed Aug 1 14:50:24 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r56520:ca17f248a97a
Date: 2012-08-01 14:50 +0200
http://bitbucket.org/pypy/pypy/changeset/ca17f248a97a/
Log: Separate the parts that the JIT should see from the others.
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -209,10 +209,6 @@
misc.write_raw_float_data(self._cdata, source, self.ctype.size)
keepalive_until_here(self)
- def write_raw_longdouble_data(self, source):
- misc.write_raw_longdouble_data(self._cdata, source)
- keepalive_until_here(self)
-
def convert_to_object(self):
w_obj = self.ctype.convert_to_object(self._cdata)
keepalive_until_here(self)
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -6,6 +6,7 @@
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.rarithmetic import intmask, r_ulonglong
from pypy.rlib.objectmodel import keepalive_until_here
+from pypy.rlib import jit
from pypy.module._cffi_backend.ctypeobj import W_CType
from pypy.module._cffi_backend import cdataobj, misc
@@ -247,8 +248,8 @@
if not isinstance(self, W_CTypePrimitiveLongDouble):
w_cdata.write_raw_float_data(value)
else:
- lvalue = rffi.cast(rffi.LONGDOUBLE, value)
- w_cdata.write_raw_longdouble_data(lvalue)
+ self._to_longdouble_and_write(value, w_cdata._cdata)
+ keepalive_until_here(w_cdata)
return w_cdata
def int(self, cdata):
@@ -271,6 +272,7 @@
class W_CTypePrimitiveLongDouble(W_CTypePrimitiveFloat):
_attrs_ = []
+ @jit.dont_look_inside
def extra_repr(self, cdata):
lvalue = misc.read_raw_longdouble_data(cdata)
return misc.longdouble2str(lvalue)
@@ -286,15 +288,30 @@
else:
return W_CTypePrimitiveFloat.cast(self, w_ob)
- def float(self, cdata):
+ @jit.dont_look_inside
+ def _to_longdouble_and_write(self, value, cdata):
+ lvalue = rffi.cast(rffi.LONGDOUBLE, value)
+ misc.write_raw_longdouble_data(cdata, lvalue)
+
+ @jit.dont_look_inside
+ def _read_from_longdouble(self, cdata):
lvalue = misc.read_raw_longdouble_data(cdata)
value = rffi.cast(lltype.Float, lvalue)
+ return value
+
+ @jit.dont_look_inside
+ def _copy_longdouble(self, cdatasrc, cdatadst):
+ lvalue = misc.read_raw_longdouble_data(cdatasrc)
+ misc.write_raw_longdouble_data(cdatadst, lvalue)
+
+ def float(self, cdata):
+ value = self._read_from_longdouble(cdata)
return self.space.wrap(value)
def convert_to_object(self, cdata):
- lvalue = misc.read_raw_longdouble_data(cdata)
w_cdata = cdataobj.W_CDataCasted(self.space, self.size, self)
- w_cdata.write_raw_longdouble_data(lvalue)
+ self._copy_longdouble(cdata, w_cdata._cdata)
+ keepalive_until_here(w_cdata)
return w_cdata
def convert_from_object(self, cdata, w_ob):
@@ -302,9 +319,8 @@
ob = space.interpclass_w(w_ob)
if (isinstance(ob, cdataobj.W_CData) and
isinstance(ob.ctype, W_CTypePrimitiveLongDouble)):
- lvalue = misc.read_raw_longdouble_data(ob._cdata)
+ self._copy_longdouble(ob._cdata, cdata)
keepalive_until_here(ob)
else:
value = space.float_w(space.float(w_ob))
- lvalue = rffi.cast(rffi.LONGDOUBLE, value)
- misc.write_raw_longdouble_data(cdata, lvalue)
+ self._to_longdouble_and_write(value, cdata)
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -1735,18 +1735,21 @@
assert float(x) == 12.5
def test_longdouble():
+ py_py = 'PY_DOT_PY' in globals()
BLongDouble = new_primitive_type("long double")
BLongDoublePtr = new_pointer_type(BLongDouble)
BLongDoubleArray = new_array_type(BLongDoublePtr, None)
a = newp(BLongDoubleArray, 1)
x = a[0]
- assert repr(x).startswith("<cdata 'long double' 0.0")
+ if not py_py:
+ assert repr(x).startswith("<cdata 'long double' 0.0")
assert float(x) == 0.0
assert int(x) == 0
#
b = newp(BLongDoubleArray, [1.23])
x = b[0]
- assert repr(x).startswith("<cdata 'long double' 1.23")
+ if not py_py:
+ assert repr(x).startswith("<cdata 'long double' 1.23")
assert float(x) == 1.23
assert int(x) == 1
#
@@ -1756,11 +1759,12 @@
for i in range(107):
start = f(start)
if sizeof(BLongDouble) > sizeof(new_primitive_type("double")):
- if 'PY_DOT_PY' in globals(): py.test.skip('py.py: long double->double')
- assert repr(start).startswith("<cdata 'long double' 6.15")
- assert repr(start).endswith("E+902>")
+ if not py_py:
+ assert repr(start).startswith("<cdata 'long double' 6.15")
+ assert repr(start).endswith("E+902>")
#
c = newp(BLongDoubleArray, [start])
x = c[0]
- assert repr(x).endswith("E+902>")
- assert float(x) == float("inf")
+ if not py_py:
+ assert repr(x).endswith("E+902>")
+ assert float(x) == float("inf")
More information about the pypy-commit
mailing list