[pypy-commit] pypy llvm-translation-backend: Fix the rffi tests for the LLVM backend.

Manuel Jacob noreply at buildbot.pypy.org
Fri Aug 30 15:43:36 CEST 2013


Author: Manuel Jacob
Branch: llvm-translation-backend
Changeset: r66482:5716cea0e2cd
Date: 2012-05-19 17:42 +0200
http://bitbucket.org/pypy/pypy/changeset/5716cea0e2cd/

Log:	Fix the rffi tests for the LLVM backend.

diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -62,7 +62,8 @@
                sandboxsafe=False, threadsafe='auto',
                _nowrapper=False, calling_conv='c',
                oo_primitive=None, elidable_function=False,
-               macro=None, random_effects_on_gcobjs='auto'):
+               macro=None, random_effects_on_gcobjs='auto',
+               llvm_wrapper=None):
     """Build an external function that will invoke the C function 'name'
     with the given 'args' types and 'result' type.
 
@@ -123,6 +124,15 @@
             invoke_around_handlers or   # because it can release the GIL
             has_callback)               # because the callback can do it
 
+    if llvm_wrapper is None:
+        llvm_wrapper = macro
+    if llvm_wrapper is not None:
+        if llvm_wrapper is True:
+            llvm_wrapper = name
+        wrapper_name = 'pypy_llvm_wrapper_%s' % (name,)
+        _write_wrapper(wrapper_name, llvm_wrapper, ext_type, compilation_info, '_with_llvm')
+        name = wrapper_name
+
     funcptr = lltype.functionptr(ext_type, name, external='C',
                                  compilation_info=compilation_info,
                                  _callable=_callable,
@@ -341,14 +351,10 @@
                       compilation_info=eci, sandboxsafe=True, _nowrapper=True,
                       _callable=lambda: None)
 
-def generate_macro_wrapper(name, macro, functype, eci):
-    """Wraps a function-like macro inside a real function, and expose
-    it with llexternal."""
-
+def _write_wrapper(wrapper_name, macro, functype, eci, wrapped_eci_name):
     # Generate the function call
     from pypy.translator.c.database import LowLevelDatabase
     from pypy.translator.c.support import cdecl
-    wrapper_name = 'pypy_macro_wrapper_%s' % (name,)
     argnames = ['arg%d' % (i,) for i in range(len(functype.ARGS))]
     db = LowLevelDatabase()
     implementationtypename = db.gettype(functype, argnames=argnames)
@@ -364,13 +370,20 @@
     # by ll2ctypes.  We replace eci._with_ctypes, so that only one
     # shared library is actually compiled (when ll2ctypes calls the
     # first function)
-    ctypes_eci = eci.merge(ExternalCompilationInfo(
+    wrapped_eci = eci.merge(ExternalCompilationInfo(
             separate_module_sources=[source],
             export_symbols=[wrapper_name],
             ))
-    if hasattr(eci, '_with_ctypes'):
-        ctypes_eci = eci._with_ctypes.merge(ctypes_eci)
-    eci._with_ctypes = ctypes_eci
+    if hasattr(eci, wrapped_eci_name):
+        wrapped_eci = getattr(eci, wrapped_eci_name).merge(wrapped_eci)
+    setattr(eci, wrapped_eci_name, wrapped_eci)
+
+def generate_macro_wrapper(name, macro, functype, eci):
+    """Wraps a function-like macro inside a real function, and expose
+    it with llexternal."""
+
+    wrapper_name = 'pypy_macro_wrapper_%s' % (name,)
+    _write_wrapper(wrapper_name, macro, functype, eci, '_with_ctypes')
     func = llexternal(wrapper_name, functype.ARGS, functype.RESULT,
                       compilation_info=eci, _nowrapper=True)
     # _nowrapper=True returns a pointer which is not hashable
diff --git a/pypy/rpython/lltypesystem/test/test_rffi.py b/pypy/rpython/lltypesystem/test/test_rffi.py
--- a/pypy/rpython/lltypesystem/test/test_rffi.py
+++ b/pypy/rpython/lltypesystem/test/test_rffi.py
@@ -49,7 +49,7 @@
 
         eci = ExternalCompilationInfo(includes=['stuff.h'],
                                       include_dirs=[udir])
-        z = llexternal('X', [Signed], Signed, compilation_info=eci)
+        z = llexternal('X', [Signed], Signed, compilation_info=eci, macro=True)
 
         def f():
             return z(8)
@@ -300,7 +300,7 @@
 
         STUFFP = COpaquePtr(typedef='stuff_ptr', compilation_info=eci)
         ll_get = llexternal('get', [STUFFP], lltype.Signed,
-                            compilation_info=eci)
+                            compilation_info=eci, llvm_wrapper=True)
 
         def f():
             return ll_get(lltype.nullptr(STUFFP.TO))
@@ -312,7 +312,7 @@
         ctype_pref = ["un", ""][signed]
         rffi_type = [UCHAR, SIGNEDCHAR][signed]
         h_source = py.code.Source("""
-        %ssigned char returnchar(void)
+        static %ssigned char returnchar(void)
         {
             return 42;
         }
@@ -325,7 +325,8 @@
             includes=[h_file.basename],
             include_dirs=[str(udir)]
         )
-        ll_returnchar = llexternal('returnchar', [], rffi_type, compilation_info=eci)
+        ll_returnchar = llexternal('returnchar', [], rffi_type,
+                                   compilation_info=eci, llvm_wrapper=True)
     
         def f():
             result = ll_returnchar()
diff --git a/pypy/translator/llvm/genllvm.py b/pypy/translator/llvm/genllvm.py
--- a/pypy/translator/llvm/genllvm.py
+++ b/pypy/translator/llvm/genllvm.py
@@ -274,6 +274,7 @@
     lltype.Signed: LLVMSigned,
     lltype.Unsigned: LLVMUnsigned,
     lltype.Char: LLVMChar,
+    rffi.SIGNEDCHAR: LLVMSignedChar,
     lltype.UniChar: LLVMUniChar,
     lltype.Bool: LLVMBool,
     lltype.Float: LLVMFloat,
@@ -610,7 +611,10 @@
                 database.f.write('declare {} {}({})\n'.format(
                         self.result.repr_type(), name,
                         ', '.join(arg.repr_type() for arg in self.args)))
-                database.genllvm.ecis.append(obj.compilation_info)
+                eci = obj.compilation_info
+                if hasattr(eci, '_with_llvm'):
+                    eci = eci._with_llvm
+                database.genllvm.ecis.append(eci)
         else:
             if obj._name == '__main':
                 name = '@main'
@@ -1395,6 +1399,8 @@
         if repr_.lowleveltype in PRIMITIVES:
             if repr_.lowleveltype is lltype.Bool:
                 return bool(result)
+            if repr_.lowleveltype is rffi.SIGNEDCHAR:
+                return chr(result)
             return result
         convert = getattr(self, '_from_ctype_' + repr_.__class__.__name__)
         return convert(repr_, result)


More information about the pypy-commit mailing list