Exemple #1
0
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)"
Exemple #2
0
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)"
Exemple #3
0
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 rpython.translator.c.database import LowLevelDatabase
    from rpython.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)
Exemple #4
0
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 rpython.translator.c.database import LowLevelDatabase
    from rpython.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(%s); }'
    else:
        pattern = '%s%s { return %s(%s); }'
    source = pattern % (
        'RPY_EXTERN ',
        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],
            ))
    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)
Exemple #5
0
def test_intlong_unique():
    A = INT_real
    B = Signed
    db = LowLevelDatabase()
    assert db.gettype(A) == "int @"
    assert db.gettype(B) == "Signed @"
Exemple #6
0
def test_voidp():
    A = VOIDP
    db = LowLevelDatabase()
    assert db.gettype(A) == "void *@"
Exemple #7
0
def test_intlong_unique():
    A = INT_real
    B = Signed
    db = LowLevelDatabase()
    assert db.gettype(A) == "int @"
    assert db.gettype(B) == "Signed @"
Exemple #8
0
def test_voidp():
    A = VOIDP
    db = LowLevelDatabase()
    assert db.gettype(A) == "void *@"