[pypy-commit] pypy default: (antocuni, arigo)

arigo pypy.commits at gmail.com
Tue Oct 3 08:36:23 EDT 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r92573:3e50a1272650
Date: 2017-10-02 12:13 +0200
http://bitbucket.org/pypy/pypy/changeset/3e50a1272650/

Log:	(antocuni, arigo)

	Aaaaah. Found that this simple new test in test_ll2ctypes doesn't
	actually pass. Fix.

diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -815,6 +815,10 @@
             else:
                 container = llobj._obj
             if isinstance(T.TO, lltype.FuncType):
+                if hasattr(llobj._obj0, '_real_integer_addr'):
+                    ctypes_func_type = get_ctypes_type(T)
+                    return ctypes.cast(llobj._obj0._real_integer_addr,
+                                       ctypes_func_type)
                 # XXX a temporary workaround for comparison of lltype.FuncType
                 key = llobj._obj.__dict__.copy()
                 key['_TYPE'] = repr(key['_TYPE'])
@@ -1039,7 +1043,8 @@
                     cobj = ctypes.cast(cobjkey, type(cobj))
                     _callable = get_ctypes_trampoline(T.TO, cobj)
                     return lltype.functionptr(T.TO, name,
-                                              _callable=_callable)
+                                              _callable=_callable,
+                                              _real_integer_addr=cobjkey)
             elif isinstance(T.TO, lltype.OpaqueType):
                 if T == llmemory.GCREF:
                     container = _llgcopaque(cobj)
diff --git a/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py b/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py
@@ -1443,6 +1443,12 @@
         assert seen[0]() == 42
         assert seen[1]() == 43
 
+    def test_keep_value_across_lltype_callable(self):
+        PtrF = lltype.Ptr(lltype.FuncType([], lltype.Void))
+        f = rffi.cast(PtrF, 42)
+        assert lltype.typeOf(f) == PtrF
+        assert rffi.cast(lltype.Signed, f) == 42
+
 
 class TestPlatform(object):
     def test_lib_on_libpaths(self):


More information about the pypy-commit mailing list