def test_typedef(): A = Typedef(Signed, 'test4') db = LowLevelDatabase() assert db.gettype(A) == "test4 @" PA = CArrayPtr(A) assert db.gettype(PA) == "test4 *@" F = FuncType((A,), A) assert db.gettype(F) == "test4 (@)(test4)"
def test_typedef(): A = Typedef(Signed, 'test4') db = LowLevelDatabase() assert db.gettype(A) == "test4 @" PA = CArrayPtr(A) assert db.gettype(PA) == "test4 *@" F = FuncType((A, ), A) assert db.gettype(F) == "test4 (@)(test4)"
def generate_macro_wrapper(name, macro, functype, eci): """Wraps a function-like macro inside a real function, and expose it with llexternal.""" # 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) if functype.RESULT is lltype.Void: pattern = '%s { %s(%s); }' else: pattern = '%s { return %s(%s); }' source = pattern % ( cdecl(implementationtypename, wrapper_name), macro, ', '.join(argnames)) # Now stuff this source into a "companion" eci that will be used # 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( 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 func = llexternal(wrapper_name, functype.ARGS, functype.RESULT, compilation_info=eci, _nowrapper=True) # _nowrapper=True returns a pointer which is not hashable return lambda *args: func(*args)
def test_intlong_unique(): A = INT_real B = Signed db = LowLevelDatabase() assert db.gettype(A) == "int @" assert db.gettype(B) == "long @"
def test_voidp(): A = VOIDP db = LowLevelDatabase() assert db.gettype(A) == "void *@"