Author: Antonio Cuni <[email protected]>
Branch: refactor-call_release_gil
Changeset: r62829:48666ddb2250
Date: 2013-03-27 14:22 +0100
http://bitbucket.org/pypy/pypy/changeset/48666ddb2250/

Log:    add a workaround to make test_fficall::test_guard_not_forced_fail
        passing on the x86 backend; see the comment for details

diff --git a/rpython/jit/backend/llsupport/llmodel.py 
b/rpython/jit/backend/llsupport/llmodel.py
--- a/rpython/jit/backend/llsupport/llmodel.py
+++ b/rpython/jit/backend/llsupport/llmodel.py
@@ -275,6 +275,10 @@
     def cast_adr_to_int(x):
         return rffi.cast(lltype.Signed, x)
 
+    @staticmethod
+    def cast_int_to_ptr(x, TYPE):
+        return rffi.cast(TYPE, x)
+
     def sizeof(self, S):
         return get_size_descr(self.gc_ll_descr, S)
 
diff --git a/rpython/jit/backend/model.py b/rpython/jit/backend/model.py
--- a/rpython/jit/backend/model.py
+++ b/rpython/jit/backend/model.py
@@ -1,6 +1,6 @@
 import weakref
 from rpython.rlib.debug import debug_start, debug_print, debug_stop
-from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.lltypesystem import lltype, llmemory
 
 class CPUTotalTracker(object):
     total_compiled_loops = 0
@@ -194,6 +194,11 @@
     def typedescrof(self, TYPE):
         raise NotImplementedError
 
+    @staticmethod
+    def cast_int_to_ptr(x, TYPE):
+        x = llmemory.cast_int_to_adr(x)
+        return llmemory.cast_adr_to_ptr(x, TYPE)
+
     # ---------- the backend-dependent operations ----------
 
     # lltype specific operations
diff --git a/rpython/jit/backend/x86/test/test_fficall.py 
b/rpython/jit/backend/x86/test/test_fficall.py
--- a/rpython/jit/backend/x86/test/test_fficall.py
+++ b/rpython/jit/backend/x86/test/test_fficall.py
@@ -5,4 +5,19 @@
 class TestFfiCall(Jit386Mixin, test_fficall.FfiCallTests):
     # for the individual tests see
     # ====> ../../../metainterp/test/test_fficall.py
-    pass
+
+    def _add_libffi_types_to_ll2types_maybe(self):
+        # this is needed by test_guard_not_forced_fails, because it produces a
+        # loop which reads the value of types.* in a variable, then a guard
+        # fail and we switch to blackhole: the problem is that at this point
+        # the blackhole interp has a real integer, but it needs to convert it
+        # back to a lltype pointer (which is handled by ll2ctypes, deeply in
+        # the logic). The workaround is to teach ll2ctypes in advance which
+        # are the addresses of the various types.* structures.
+        # Try to comment this code out and run the test to see how it fails :)
+        from rpython.rtyper.lltypesystem import rffi, lltype, ll2ctypes
+        from rpython.rlib.jit_libffi import types
+        for key, value in types.__dict__.iteritems():
+            if isinstance(value, lltype._ptr):
+                addr = rffi.cast(lltype.Signed, value)
+                ll2ctypes._int2obj[addr] = value
diff --git a/rpython/jit/metainterp/blackhole.py 
b/rpython/jit/metainterp/blackhole.py
--- a/rpython/jit/metainterp/blackhole.py
+++ b/rpython/jit/metainterp/blackhole.py
@@ -8,8 +8,9 @@
 from rpython.rlib.rarithmetic import intmask, LONG_BIT, r_uint, ovfcheck
 from rpython.rlib.rtimer import read_timestamp
 from rpython.rlib.unroll import unrolling_iterable
-from rpython.rtyper.lltypesystem import lltype, llmemory, rclass
+from rpython.rtyper.lltypesystem import lltype, llmemory, rclass, rffi
 from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rlib.jit_libffi import CIF_DESCRIPTION_P
 
 
 def arguments(*argtypes, **kwds):
@@ -1350,35 +1351,19 @@
 
     @arguments("cpu", "i", "i", "i")
     def bhimpl_libffi_save_result_int(self, cif_description, exchange_buffer, 
result):
-        from rpython.rtyper.lltypesystem import llmemory, rffi
-        from rpython.rlib.jit_libffi import CIF_DESCRIPTION_P
         ARRAY = lltype.Ptr(rffi.CArray(lltype.Signed))
-        
-        cif_description = llmemory.cast_int_to_adr(cif_description)
-        cif_description = llmemory.cast_adr_to_ptr(cif_description,
-                                                   CIF_DESCRIPTION_P)
-
-        exchange_buffer = llmemory.cast_int_to_adr(exchange_buffer)
-        exchange_buffer = llmemory.cast_adr_to_ptr(exchange_buffer,
-                                                   rffi.CCHARP)
-
+        cif_description = self.cast_int_to_ptr(cif_description, 
CIF_DESCRIPTION_P)
+        exchange_buffer = self.cast_int_to_ptr(exchange_buffer, rffi.CCHARP)
+        #
         data_out = rffi.ptradd(exchange_buffer, 
cif_description.exchange_result)
         rffi.cast(ARRAY, data_out)[0] = result
 
     @arguments("cpu", "i", "i", "f")
     def bhimpl_libffi_save_result_float(self, cif_description, 
exchange_buffer, result):
-        from rpython.rtyper.lltypesystem import llmemory, rffi
-        from rpython.rlib.jit_libffi import CIF_DESCRIPTION_P
         ARRAY = lltype.Ptr(rffi.CArray(lltype.Float))
-        
-        cif_description = llmemory.cast_int_to_adr(cif_description)
-        cif_description = llmemory.cast_adr_to_ptr(cif_description,
-                                                   CIF_DESCRIPTION_P)
-
-        exchange_buffer = llmemory.cast_int_to_adr(exchange_buffer)
-        exchange_buffer = llmemory.cast_adr_to_ptr(exchange_buffer,
-                                                   rffi.CCHARP)
-
+        cif_description = self.cast_int_to_ptr(cif_description, 
CIF_DESCRIPTION_P)
+        exchange_buffer = self.cast_int_to_ptr(exchange_buffer, rffi.CCHARP)
+        #
         data_out = rffi.ptradd(exchange_buffer, 
cif_description.exchange_result)
         rffi.cast(ARRAY, data_out)[0] = result
 
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
@@ -122,8 +122,13 @@
         self._run([types.signed], types.sint8, [456],
                   rffi.cast(rffi.SIGNEDCHAR, -42))
 
+    def _add_libffi_types_to_ll2types_maybe(self):
+        # not necessary on the llgraph backend, but needed for x86.
+        # see rpython/jit/backend/x86/test/test_fficall.py
+        pass
 
     def test_guard_not_forced_fails(self):
+        self._add_libffi_types_to_ll2types_maybe()
         FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
 
         cif_description = get_description([types.slong], types.slong)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to