[pypy-commit] pypy jit-singlefloat: In-progress: simplify rlib/libffi to not depend on casting longlongs
arigo
noreply at buildbot.pypy.org
Fri Jul 29 12:45:27 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: jit-singlefloat
Changeset: r46088:066a4bfeb276
Date: 2011-07-29 12:44 +0200
http://bitbucket.org/pypy/pypy/changeset/066a4bfeb276/
Log: In-progress: simplify rlib/libffi to not depend on casting longlongs
to floats. It was done this way to work around some small but
obscure bugs left and right in the jit. Instead, fix these bugs.
diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py
--- a/pypy/jit/backend/llgraph/llimpl.py
+++ b/pypy/jit/backend/llgraph/llimpl.py
@@ -1145,6 +1145,7 @@
del _future_values[:]
def set_future_value_int(index, value):
+ assert type(value) is int
set_future_value_ref(index, value)
def set_future_value_float(index, value):
diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py
--- a/pypy/jit/backend/llgraph/runner.py
+++ b/pypy/jit/backend/llgraph/runner.py
@@ -328,12 +328,16 @@
def calldescrof_dynamic(self, ffi_args, ffi_result, extrainfo=None):
from pypy.jit.backend.llsupport.ffisupport import get_ffi_type_kind
+ from pypy.jit.backend.llsupport.ffisupport import UnsupportedKind
arg_types = []
- for arg in ffi_args:
- kind = get_ffi_type_kind(arg)
- if kind != history.VOID:
- arg_types.append(kind)
- reskind = get_ffi_type_kind(ffi_result)
+ try:
+ for arg in ffi_args:
+ kind = get_ffi_type_kind(self, arg)
+ if kind != history.VOID:
+ arg_types.append(kind)
+ reskind = get_ffi_type_kind(self, ffi_result)
+ except UnsupportedKind:
+ return None
return self.getdescr(0, reskind, extrainfo=extrainfo,
arg_types=''.join(arg_types))
diff --git a/pypy/jit/backend/llsupport/ffisupport.py b/pypy/jit/backend/llsupport/ffisupport.py
--- a/pypy/jit/backend/llsupport/ffisupport.py
+++ b/pypy/jit/backend/llsupport/ffisupport.py
@@ -6,14 +6,14 @@
class UnsupportedKind(Exception):
pass
-def get_call_descr_dynamic(ffi_args, ffi_result, extrainfo=None):
+def get_call_descr_dynamic(cpu, ffi_args, ffi_result, extrainfo=None):
"""Get a call descr: the types of result and args are represented by
rlib.libffi.types.*"""
try:
- reskind = get_ffi_type_kind(ffi_result)
- argkinds = [get_ffi_type_kind(arg) for arg in ffi_args]
+ reskind = get_ffi_type_kind(cpu, ffi_result)
+ argkinds = [get_ffi_type_kind(cpu, arg) for arg in ffi_args]
except UnsupportedKind:
- return None # ??
+ return None
arg_classes = ''.join(argkinds)
if reskind == history.INT:
size = intmask(ffi_result.c_size)
@@ -27,15 +27,19 @@
return VoidCallDescr(arg_classes, extrainfo)
assert False
-def get_ffi_type_kind(ffi_type):
+def get_ffi_type_kind(cpu, ffi_type):
from pypy.rlib.libffi import types
kind = types.getkind(ffi_type)
if kind == 'i' or kind == 'u':
return history.INT
- elif kind == 'f':
+ elif cpu.supports_floats and kind == 'f':
return history.FLOAT
elif kind == 'v':
return history.VOID
+ elif cpu.supports_longlong and (kind == 'I' or kind == 'U'): # longlong
+ return 'L'
+ elif cpu.supports_singlefloats and kind == 's': # singlefloat
+ return 'S'
raise UnsupportedKind("Unsupported kind '%s'" % kind)
def is_ffi_type_signed(ffi_type):
diff --git a/pypy/jit/backend/llsupport/llmodel.py b/pypy/jit/backend/llsupport/llmodel.py
--- a/pypy/jit/backend/llsupport/llmodel.py
+++ b/pypy/jit/backend/llsupport/llmodel.py
@@ -259,7 +259,7 @@
def calldescrof_dynamic(self, ffi_args, ffi_result, extrainfo=None):
from pypy.jit.backend.llsupport import ffisupport
- return ffisupport.get_call_descr_dynamic(ffi_args, ffi_result,
+ return ffisupport.get_call_descr_dynamic(self, ffi_args, ffi_result,
extrainfo)
def get_overflow_error(self):
diff --git a/pypy/jit/codewriter/test/test_longlong.py b/pypy/jit/codewriter/test/test_longlong.py
--- a/pypy/jit/codewriter/test/test_longlong.py
+++ b/pypy/jit/codewriter/test/test_longlong.py
@@ -230,3 +230,18 @@
assert list(op1.args[3]) == []
assert list(op1.args[4]) == vlist
assert op1.result == v_result
+
+
+##def test_singlefloat_constants():
+## v_x = varoftype(TYPE)
+## vlist = [v_x, const(rffi.cast(TYPE, 7))]
+## v_result = varoftype(TYPE)
+## op = SpaceOperation('llong_add', vlist, v_result)
+## tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
+## op1 = tr.rewrite_operation(op)
+## #
+## assert op1.opname == 'residual_call_irf_f'
+## assert list(op1.args[2]) == []
+## assert list(op1.args[3]) == []
+## assert list(op1.args[4]) == vlist
+## assert op1.result == v_result
diff --git a/pypy/jit/metainterp/optimizeopt/fficall.py b/pypy/jit/metainterp/optimizeopt/fficall.py
--- a/pypy/jit/metainterp/optimizeopt/fficall.py
+++ b/pypy/jit/metainterp/optimizeopt/fficall.py
@@ -6,7 +6,6 @@
from pypy.jit.metainterp.resoperation import rop, ResOperation
from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
from pypy.jit.metainterp.optimizeopt.optimizer import Optimization
-from pypy.jit.backend.llsupport.ffisupport import UnsupportedKind
class FuncInfo(object):
@@ -20,11 +19,8 @@
self.funcval = funcval
self.opargs = []
argtypes, restype = self._get_signature(funcval)
- try:
- self.descr = cpu.calldescrof_dynamic(argtypes, restype)
- except UnsupportedKind:
- # e.g., I or U for long longs
- self.descr = None
+ self.descr = cpu.calldescrof_dynamic(argtypes, restype)
+ # ^^^ may be None if unsupported
self.prepare_op = prepare_op
self.delayed_ops = []
@@ -184,7 +180,8 @@
def do_call(self, op):
funcval = self._get_funcval(op)
funcinfo = self.funcinfo
- if not funcinfo or funcinfo.funcval is not funcval:
+ if (not funcinfo or funcinfo.funcval is not funcval or
+ funcinfo.descr is None):
return [op] # cannot optimize
funcsymval = self.getvalue(op.getarg(2))
arglist = [funcsymval.force_box()]
diff --git a/pypy/jit/metainterp/test/test_fficall.py b/pypy/jit/metainterp/test/test_fficall.py
--- a/pypy/jit/metainterp/test/test_fficall.py
+++ b/pypy/jit/metainterp/test/test_fficall.py
@@ -3,7 +3,7 @@
from pypy.rlib.rarithmetic import r_singlefloat, r_longlong, r_ulonglong
from pypy.rlib.jit import JitDriver, promote, dont_look_inside
from pypy.rlib.unroll import unrolling_iterable
-from pypy.rlib.libffi import ArgChain, longlong2float, float2longlong
+from pypy.rlib.libffi import ArgChain
from pypy.rlib.libffi import IS_32_BIT
from pypy.rlib.test.test_libffi import TestLibffiCall as _TestLibffiCall
from pypy.rpython.lltypesystem import lltype, rffi
@@ -12,10 +12,22 @@
from pypy.jit.metainterp.test.support import LLJitMixin
class TestFfiCall(LLJitMixin, _TestLibffiCall):
+ supports_all = False # supports_{floats,longlong,singlefloats}
# ===> ../../../rlib/test/test_libffi.py
- def call(self, funcspec, args, RESULT, init_result=0, is_struct=False):
+ def check_loops_if_supported(self, *args, **kwds):
+ if self.supports_all:
+ self.check_loops(*args, **kwds)
+ else:
+ self.check_loops({'call': 1,
+ 'guard_no_exception': 1,
+ 'int_add': 1,
+ 'int_lt': 1,
+ 'guard_true': 1,
+ 'jump': 1})
+
+ def call(self, funcspec, args, RESULT, is_struct=False):
"""
Call the function specified by funcspec in a loop, and let the jit to
see and optimize it.
@@ -24,14 +36,7 @@
lib, name, argtypes, restype = funcspec
method_and_args = []
for argval in args:
- if type(argval) is r_singlefloat:
- method_name = 'arg_singlefloat'
- argval = float(argval)
- elif IS_32_BIT and type(argval) in [r_longlong, r_ulonglong]:
- method_name = 'arg_longlong'
- argval = rffi.cast(rffi.LONGLONG, argval)
- argval = longlong2float(argval)
- elif isinstance(argval, tuple):
+ if isinstance(argval, tuple):
method_name, argval = argval
else:
method_name = 'arg'
@@ -39,10 +44,20 @@
method_and_args = unrolling_iterable(method_and_args)
#
reds = ['n', 'res', 'func']
- if (RESULT in [rffi.FLOAT, rffi.DOUBLE] or
+ if (RESULT is rffi.DOUBLE or
IS_32_BIT and RESULT in [rffi.LONGLONG, rffi.ULONGLONG]):
- reds = ['n', 'func', 'res'] # floats must be *after* refs
+ reds = ['n', 'func', 'res'] # 'double' floats must be *after* refs
driver = JitDriver(reds=reds, greens=[])
+ init_result = rffi.cast(RESULT, 0)
+ #
+ def g(func):
+ # a different function, which is marked as "dont_look_inside"
+ # in case it uses an unsupported argument
+ argchain = ArgChain()
+ # this loop is unrolled
+ for method_name, argval in method_and_args:
+ getattr(argchain, method_name)(argval)
+ return func.call(argchain, RESULT, is_struct=is_struct)
#
def f(n):
func = lib.getpointer(name, argtypes, restype)
@@ -50,18 +65,22 @@
while n < 10:
driver.jit_merge_point(n=n, res=res, func=func)
promote(func)
- argchain = ArgChain()
- # this loop is unrolled
- for method_name, argval in method_and_args:
- getattr(argchain, method_name)(argval)
- res = func.call(argchain, RESULT, is_struct=is_struct)
+ res = g(func)
n += 1
return res
#
- res = self.meta_interp(f, [0], backendopt=True)
+ res = self.meta_interp(f, [0], backendopt=True,
+ supports_floats = self.supports_all,
+ supports_longlong = self.supports_all,
+ supports_singlefloats = False) # XXX self.supports_all)
+ # the calls to check_loops() are in pypy.rlib.test.test_libffi
return res
def test_byval_result(self):
_TestLibffiCall.test_byval_result(self)
test_byval_result.__doc__ = _TestLibffiCall.test_byval_result.__doc__
test_byval_result.dont_track_allocations = True
+
+
+class TestFfiCallSupportAll(TestFfiCall):
+ supports_all = True # supports_{floats,longlong,singlefloats}
diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -284,7 +284,9 @@
auto_inline_graphs(self.translator, graphs, 0.01)
def build_cpu(self, CPUClass, translate_support_code=False,
- no_stats=False, **kwds):
+ no_stats=False, supports_floats=True,
+ supports_longlong=True, supports_singlefloats=True,
+ **kwds):
assert CPUClass is not None
self.opt = history.Options(**kwds)
if no_stats:
@@ -296,6 +298,9 @@
self.annhelper = MixLevelHelperAnnotator(self.translator.rtyper)
cpu = CPUClass(self.translator.rtyper, self.stats, self.opt,
translate_support_code, gcdescr=self.gcdescr)
+ if not supports_floats: cpu.supports_floats = False
+ if not supports_longlong: cpu.supports_longlong = False
+ if not supports_singlefloats: cpu.supports_singlefloats = False
self.cpu = cpu
def build_meta_interp(self, ProfilerClass):
diff --git a/pypy/module/_ffi/interp_ffi.py b/pypy/module/_ffi/interp_ffi.py
--- a/pypy/module/_ffi/interp_ffi.py
+++ b/pypy/module/_ffi/interp_ffi.py
@@ -224,7 +224,7 @@
elif w_argtype.is_double():
argchain.arg(space.float_w(w_arg))
elif w_argtype.is_singlefloat():
- argchain.arg_singlefloat(space.float_w(w_arg))
+ self.arg_singlefloat(space, argchain, w_arg)
elif w_argtype.is_struct():
# arg_raw directly takes value to put inside ll_args
w_arg = space.interp_w(W_StructureInstance, w_arg)
@@ -267,15 +267,23 @@
else:
return w_arg
- @jit.dont_look_inside
def arg_longlong(self, space, argchain, w_arg):
+ # a separate function, which can be seen by the jit or not,
+ # depending on whether longlongs are supported
bigarg = space.bigint_w(w_arg)
ullval = bigarg.ulonglongmask()
llval = rffi.cast(rffi.LONGLONG, ullval)
- # this is a hack: we store the 64 bits of the long long into the
- # 64 bits of a float (i.e., a C double)
- floatval = libffi.longlong2float(llval)
- argchain.arg_longlong(floatval)
+ argchain.arg(llval)
+ arg_longlong._dont_inline_ = True
+
+ def arg_singlefloat(self, space, argchain, w_arg):
+ # a separate function, which can be seen by the jit or not,
+ # depending on whether singlefloats are supported
+ from pypy.rlib.rarithmetic import r_singlefloat
+ fval = space.float_w(w_arg)
+ sfval = r_singlefloat(fval)
+ argchain.arg(sfval)
+ arg_singlefloat._dont_inline_ = True
def call(self, space, args_w):
self = jit.promote(self)
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -2,14 +2,13 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.rlib.objectmodel import specialize, enforceargs, we_are_translated
-from pypy.rlib.rarithmetic import intmask, r_uint, r_singlefloat
+from pypy.rlib.rarithmetic import intmask, r_uint, r_singlefloat, r_longlong
from pypy.rlib import jit
from pypy.rlib import clibffi
from pypy.rlib.clibffi import get_libc_name, FUNCFLAG_CDECL, AbstractFuncPtr, \
push_arg_as_ffiptr, c_ffi_call, FFI_TYPE_STRUCT
from pypy.rlib.rdynload import dlopen, dlclose, dlsym, dlsym_byordinal
from pypy.rlib.rdynload import DLLHANDLE
-from pypy.rlib.longlong2float import longlong2float, float2longlong
class types(object):
"""
@@ -122,9 +121,9 @@
elif TYPE is rffi.DOUBLE:
cls = FloatArg
elif TYPE is rffi.LONGLONG or TYPE is rffi.ULONGLONG:
- raise TypeError, 'r_(u)longlong not supported by arg(), use arg_(u)longlong()'
+ cls = LongLongArg
elif TYPE is rffi.FLOAT:
- raise TypeError, 'r_singlefloat not supported by arg(), use arg_singlefloat()'
+ cls = SingleFloatArg
else:
raise TypeError, 'Unsupported argument type: %s' % TYPE
self._append(cls(val))
@@ -133,25 +132,6 @@
def arg_raw(self, val):
self._append(RawArg(val))
- def arg_longlong(self, val):
- """
- Note: this is a hack. So far, the JIT does not support long longs, so
- you must pass it as if it were a python Float (rffi.DOUBLE). You can
- use the convenience functions longlong2float and float2longlong to do
- the conversions. Note that if you use long longs, the call won't
- be jitted at all.
- """
- assert IS_32_BIT # use a normal integer on 64-bit platforms
- self._append(LongLongArg(val))
-
- def arg_singlefloat(self, val):
- """
- Note: you must pass a python Float (rffi.DOUBLE), not a r_singlefloat
- (else the jit complains). Note that if you use single floats, the
- call won't be jitted at all.
- """
- self._append(SingleFloatArg(val))
-
def _append(self, arg):
if self.first is None:
self.first = self.last = arg
@@ -196,25 +176,25 @@
func._push_raw(self.ptrval, ll_args, i)
class SingleFloatArg(AbstractArg):
- """ An argument representing a C float (but holding a C double)
+ """ An argument representing a C float
"""
- def __init__(self, floatval):
- self.floatval = floatval
+ def __init__(self, singlefloatval):
+ self.singlefloatval = singlefloatval
def push(self, func, ll_args, i):
- func._push_single_float(self.floatval, ll_args, i)
+ func._push_singlefloat(self.singlefloatval, ll_args, i)
class LongLongArg(AbstractArg):
- """ An argument representing a C long long (but holding a C double)
+ """ An argument representing a C long long
"""
- def __init__(self, floatval):
- self.floatval = floatval
+ def __init__(self, longlongval):
+ self.longlongval = longlongval
def push(self, func, ll_args, i):
- func._push_longlong(self.floatval, ll_args, i)
+ func._push_longlong(self.longlongval, ll_args, i)
# ======================================================================
@@ -274,15 +254,10 @@
elif RESULT is rffi.DOUBLE:
return self._do_call_float(self.funcsym, ll_args)
elif RESULT is rffi.FLOAT:
- # XXX: even if RESULT is FLOAT, we still return a DOUBLE, else the
- # jit complains. Note that the jit is disabled in this case
- return self._do_call_single_float(self.funcsym, ll_args)
+ return self._do_call_singlefloat(self.funcsym, ll_args)
elif RESULT is rffi.LONGLONG or RESULT is rffi.ULONGLONG:
- # XXX: even if RESULT is LONGLONG, we still return a DOUBLE, else the
- # jit complains. Note that the jit is disabled in this case
- # (it's not a typo, we really return a DOUBLE)
assert IS_32_BIT
- return self._do_call_longlong(self.funcsym, ll_args)
+ res = self._do_call_longlong(self.funcsym, ll_args)
elif RESULT is lltype.Void:
return self._do_call_void(self.funcsym, ll_args)
else:
@@ -320,16 +295,15 @@
def _push_float(self, value, ll_args, i):
self._push_arg(value, ll_args, i)
- @jit.dont_look_inside
- def _push_single_float(self, value, ll_args, i):
- self._push_arg(r_singlefloat(value), ll_args, i)
+ @jit.oopspec('libffi_push_singlefloat(self, value, ll_args, i)')
+ @enforceargs(None, r_singlefloat, None, int) # fix the annotation for tests
+ def _push_singlefloat(self, value, ll_args, i):
+ self._push_arg(value, ll_args, i)
- @jit.dont_look_inside
- def _push_longlong(self, floatval, ll_args, i):
- """
- Takes a longlong represented as a python Float. It's a hack for the
- jit, else we could not see the whole libffi module at all"""
- self._push_arg(float2longlong(floatval), ll_args, i)
+ @jit.oopspec('libffi_push_longlong(self, value, ll_args, i)')
+ @enforceargs(None, r_longlong, None, int) # fix the annotation for tests
+ def _push_longlong(self, value, ll_args, i):
+ self._push_arg(value, ll_args, i)
@jit.oopspec('libffi_call_int(self, funcsym, ll_args)')
def _do_call_int(self, funcsym, ll_args):
@@ -339,20 +313,18 @@
def _do_call_float(self, funcsym, ll_args):
return self._do_call(funcsym, ll_args, rffi.DOUBLE)
- @jit.dont_look_inside
- def _do_call_single_float(self, funcsym, ll_args):
- single_res = self._do_call(funcsym, ll_args, rffi.FLOAT)
- return float(single_res)
+ @jit.oopspec('libffi_call_singlefloat(self, funcsym, ll_args)')
+ def _do_call_singlefloat(self, funcsym, ll_args):
+ return self._do_call(funcsym, ll_args, rffi.FLOAT)
@jit.dont_look_inside
def _do_call_raw(self, funcsym, ll_args):
# same as _do_call_int, but marked as jit.dont_look_inside
return self._do_call(funcsym, ll_args, rffi.LONG)
- @jit.dont_look_inside
+ @jit.oopspec('libffi_call_longlong(self, funcsym, ll_args)')
def _do_call_longlong(self, funcsym, ll_args):
- llres = self._do_call(funcsym, ll_args, rffi.LONGLONG)
- return longlong2float(llres)
+ return self._do_call(funcsym, ll_args, rffi.LONGLONG)
@jit.oopspec('libffi_call_void(self, funcsym, ll_args)')
def _do_call_void(self, funcsym, ll_args):
diff --git a/pypy/rlib/test/test_libffi.py b/pypy/rlib/test/test_libffi.py
--- a/pypy/rlib/test/test_libffi.py
+++ b/pypy/rlib/test/test_libffi.py
@@ -5,7 +5,7 @@
from pypy.rlib.rarithmetic import r_singlefloat, r_longlong, r_ulonglong
from pypy.rlib.test.test_clibffi import BaseFfiTest, get_libm_name, make_struct_ffitype_e
from pypy.rlib.libffi import CDLL, Func, get_libc_name, ArgChain, types
-from pypy.rlib.libffi import longlong2float, float2longlong, IS_32_BIT
+from pypy.rlib.libffi import IS_32_BIT
class TestLibffiMisc(BaseFfiTest):
@@ -52,19 +52,6 @@
del lib
assert not ALLOCATED
- def test_longlong_as_float(self):
- from pypy.translator.c.test.test_genc import compile
- maxint64 = r_longlong(9223372036854775807)
- def fn(x):
- d = longlong2float(x)
- ll = float2longlong(d)
- return ll
- assert fn(maxint64) == maxint64
- #
- fn2 = compile(fn, [r_longlong])
- res = fn2(maxint64)
- assert res == maxint64
-
class TestLibffiCall(BaseFfiTest):
"""
Test various kind of calls through libffi.
@@ -111,7 +98,7 @@
def get_libfoo(self):
return self.CDLL(self.libfoo_name)
- def call(self, funcspec, args, RESULT, init_result=0, is_struct=False):
+ def call(self, funcspec, args, RESULT, is_struct=False):
"""
Call the specified function after constructing and ArgChain with the
arguments in ``args``.
@@ -128,14 +115,7 @@
func = lib.getpointer(name, argtypes, restype)
chain = ArgChain()
for arg in args:
- if isinstance(arg, r_singlefloat):
- chain.arg_singlefloat(float(arg))
- elif IS_32_BIT and isinstance(arg, r_longlong):
- chain.arg_longlong(longlong2float(arg))
- elif IS_32_BIT and isinstance(arg, r_ulonglong):
- arg = rffi.cast(rffi.LONGLONG, arg)
- chain.arg_longlong(longlong2float(arg))
- elif isinstance(arg, tuple):
+ if isinstance(arg, tuple):
methname, arg = arg
meth = getattr(chain, methname)
meth(arg)
@@ -149,8 +129,35 @@
"""
pass
+ def check_loops_if_supported(self, *args, **kwds):
+ """
+ Same as check_loops(), but only if support for
+ float/longlong/singlefloat has been enabled
+ """
+ pass
+
# ------------------------------------------------------------------------
+ def test_very_simple(self):
+ """
+ int diff_xy(int x, long y)
+ {
+ return x - y;
+ }
+ """
+ libfoo = self.get_libfoo()
+ func = (libfoo, 'diff_xy', [types.sint, types.slong], types.sint)
+ res = self.call(func, [50, 8], lltype.Signed)
+ assert res == 42
+ self.check_loops({
+ 'call_release_gil': 1,
+ 'guard_no_exception': 1,
+ 'guard_not_forced': 1,
+ 'int_add': 1,
+ 'int_lt': 1,
+ 'guard_true': 1,
+ 'jump': 1})
+
def test_simple(self):
"""
int sum_xy(int x, double y)
@@ -160,9 +167,9 @@
"""
libfoo = self.get_libfoo()
func = (libfoo, 'sum_xy', [types.sint, types.double], types.sint)
- res = self.call(func, [38, 4.2], rffi.LONG)
+ res = self.call(func, [38, 4.2], lltype.Signed)
assert res == 42
- self.check_loops({
+ self.check_loops_if_supported({
'call_release_gil': 1,
'guard_no_exception': 1,
'guard_not_forced': 1,
@@ -174,9 +181,11 @@
def test_float_result(self):
libm = self.get_libm()
func = (libm, 'pow', [types.double, types.double], types.double)
- res = self.call(func, [2.0, 3.0], rffi.DOUBLE, init_result=0.0)
+ res = self.call(func, [2.0, 3.0], rffi.DOUBLE)
assert res == 8.0
- self.check_loops(call_release_gil=1, guard_no_exception=1, guard_not_forced=1)
+ self.check_loops_if_supported(call_release_gil=1,
+ guard_no_exception=1,
+ guard_not_forced=1)
def test_cast_result(self):
"""
@@ -271,8 +280,7 @@
libfoo = self.get_libfoo()
func = (libfoo, 'get_pointer_to_b', [], types.pointer)
LONGP = lltype.Ptr(rffi.CArray(rffi.LONG))
- null = lltype.nullptr(LONGP.TO)
- res = self.call(func, [], LONGP, init_result=null)
+ res = self.call(func, [], LONGP)
assert res[0] == 20
def test_void_result(self):
@@ -287,7 +295,7 @@
#
initval = self.call(get_dummy, [], rffi.LONG)
#
- res = self.call(set_dummy, [initval+1], lltype.Void, init_result=None)
+ res = self.call(set_dummy, [initval+1], lltype.Void)
assert res is None
#
res = self.call(get_dummy, [], rffi.LONG)
@@ -305,9 +313,10 @@
func = (libfoo, 'sum_xy_float', [types.float, types.float], types.float)
x = r_singlefloat(12.34)
y = r_singlefloat(56.78)
- res = self.call(func, [x, y], rffi.FLOAT, init_result=0.0)
+ res = self.call(func, [x, y], rffi.FLOAT)
expected = c_float(c_float(12.34).value + c_float(56.78).value).value
- assert res == expected
+ assert float(res) == expected
+ self.check_loops_if_supported({})
def test_slonglong_args(self):
"""
@@ -325,18 +334,15 @@
if IS_32_BIT:
x = r_longlong(maxint32+1)
y = r_longlong(maxint32+2)
- zero = longlong2float(r_longlong(0))
else:
x = maxint32+1
y = maxint32+2
- zero = 0
- res = self.call(func, [x, y], rffi.LONGLONG, init_result=zero)
- if IS_32_BIT:
- # obscure, on 32bit it's really a long long, so it returns a
- # DOUBLE because of the JIT hack
- res = float2longlong(res)
+ res = self.call(func, [x, y], rffi.LONGLONG)
expected = maxint32*2 + 3
assert res == expected
+ self.check_loops_if_supported(call_release_gil=1,
+ guard_no_exception=1,
+ guard_not_forced=1)
def test_ulonglong_args(self):
"""
@@ -354,12 +360,7 @@
types.ulonglong)
x = r_ulonglong(maxint64+1)
y = r_ulonglong(2)
- res = self.call(func, [x, y], rffi.ULONGLONG, init_result=0)
- if IS_32_BIT:
- # obscure, on 32bit it's really a long long, so it returns a
- # DOUBLE because of the JIT hack
- res = float2longlong(res)
- res = rffi.cast(rffi.ULONGLONG, res)
+ res = self.call(func, [x, y], rffi.ULONGLONG)
expected = maxint64 + 3
assert res == expected
@@ -406,7 +407,7 @@
buf[0] = 30
buf[1] = 12
adr = rffi.cast(rffi.VOIDP, buf)
- res = self.call(sum_point, [('arg_raw', adr)], rffi.LONG, init_result=0)
+ res = self.call(sum_point, [('arg_raw', adr)], rffi.LONG)
assert res == 42
# check that we still have the ownership on the buffer
assert buf[0] == 30
@@ -431,8 +432,7 @@
make_point = (libfoo, 'make_point', [types.slong, types.slong], ffi_point)
#
PTR = lltype.Ptr(rffi.CArray(rffi.LONG))
- p = self.call(make_point, [12, 34], PTR, init_result=lltype.nullptr(PTR.TO),
- is_struct=True)
+ p = self.call(make_point, [12, 34], PTR, is_struct=True)
assert p[0] == 12
assert p[1] == 34
lltype.free(p, flavor='raw')
More information about the pypy-commit
mailing list