[pypy-commit] pypy refactor-call_release_gil: add jit_libffi support for longlongs on 32bit, and make it fail with an AssertionError in case we have a return type which is not supported by the jit

antocuni noreply at buildbot.pypy.org
Tue Apr 9 17:33:40 CEST 2013


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: refactor-call_release_gil
Changeset: r63168:2507dbb27234
Date: 2013-04-09 17:35 +0200
http://bitbucket.org/pypy/pypy/changeset/2507dbb27234/

Log:	add jit_libffi support for longlongs on 32bit, and make it fail with
	an AssertionError in case we have a return type which is not
	supported by the jit

diff --git a/rpython/jit/metainterp/test/test_fficall.py b/rpython/jit/metainterp/test/test_fficall.py
--- a/rpython/jit/metainterp/test/test_fficall.py
+++ b/rpython/jit/metainterp/test/test_fficall.py
@@ -1,15 +1,18 @@
 import py
 from _pytest.monkeypatch import monkeypatch
+import sys
 import ctypes, math
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rtyper.annlowlevel import llhelper
 from rpython.jit.metainterp.test.support import LLJitMixin
+from rpython.jit.codewriter.longlong import is_longlong
 from rpython.rlib import jit
 from rpython.rlib import jit_libffi
 from rpython.rlib.jit_libffi import (types, CIF_DESCRIPTION, FFI_TYPE_PP,
                                      jit_ffi_call, jit_ffi_save_result)
 from rpython.rlib.unroll import unrolling_iterable
-from rpython.rlib.rarithmetic import intmask
+from rpython.rlib.rarithmetic import intmask, r_longlong
+from rpython.rlib.longlong2float import float2longlong
 
 def get_description(atypes, rtype):
     p = lltype.malloc(CIF_DESCRIPTION, len(atypes),
@@ -99,6 +102,10 @@
             res = f()
             assert res == rvalue or (res, rvalue) == (654321, None)
             res = self.interp_operations(f, [])
+            if is_longlong(FUNC.RESULT):
+                # longlongs are passed around as floats inside the JIT, we
+                # need to convert it back before checking the value
+                res = float2longlong(res)
             assert res == rvalue or (res, rvalue) == (654321, None)
             self.check_operations_history(call_may_force=0,
                                           call_release_gil=1)
@@ -115,6 +122,12 @@
     def test_simple_call_float(self):
         self._run([types.double] * 2, types.double, [45.6, 78.9], -4.2)
 
+    def test_simple_call_longlong(self):
+        maxint32 = 2147483647
+        a = r_longlong(maxint32) + 1
+        b = r_longlong(maxint32) + 2
+        self._run([types.slonglong] * 2, types.slonglong, [a, b], a)
+
     def test_returns_none(self):
         self._run([types.signed] * 2, types.void, [456, 789], None)
 
diff --git a/rpython/rlib/jit_libffi.py b/rpython/rlib/jit_libffi.py
--- a/rpython/rlib/jit_libffi.py
+++ b/rpython/rlib/jit_libffi.py
@@ -104,14 +104,17 @@
     """Wrapper around ffi_call().  Must receive a CIF_DESCRIPTION_P that
     describes the layout of the 'exchange_buffer'.
     """
-    if cif_description.rtype == types.void:
+    reskind = types.getkind(cif_description.rtype)
+    if reskind == 'v':
         jit_ffi_call_impl_void(cif_description, func_addr, exchange_buffer)
-    elif cif_description.rtype == types.double:
+    elif reskind == 'f' or reskind == 'L': # L is for longlongs, on 32bit
         result = jit_ffi_call_impl_float(cif_description, func_addr, exchange_buffer)
         jit_ffi_save_result('float', cif_description, exchange_buffer, result)
-    else:
+    elif reskind == 'i' or reskind == 'u':
         result = jit_ffi_call_impl_int(cif_description, func_addr, exchange_buffer)
         jit_ffi_save_result('int', cif_description, exchange_buffer, result)
+    else:
+        assert False, 'Unsupported result kind'
 
 
 # we must return a NonConstant else we get the constant -1 as the result of


More information about the pypy-commit mailing list