コード例 #1
0
ファイル: cffi_support.py プロジェクト: jenshnielsen/numba
def make_function_type(cffi_func):
    cffi_type = ffi.typeof(cffi_func)
    signature = map_type(cffi_type)
    cases = [signature]
    template = typing.make_concrete_template("CFFIFuncPtr", cffi_func, cases)
    result = types.FunctionPointer(template, get_pointer(cffi_func))
    return result
コード例 #2
0
ファイル: ctypes_utils.py プロジェクト: genba/numba
def make_function_type(cfnptr):
    cargs = [convert_ctypes(a) for a in cfnptr.argtypes]
    cret = convert_ctypes(cfnptr.restype)

    cases = [templates.signature(cret, *cargs)]
    template = templates.make_concrete_template("CFuncPtr", cfnptr, cases)

    pointer = ctypes.cast(cfnptr, ctypes.c_void_p).value
    return types.FunctionPointer(template, pointer)
コード例 #3
0
def make_function_type(cfnptr):
    if cfnptr.argtypes is None:
        raise TypeError(
            "ctypes function %r doesn't define its argument types; "
            "consider setting the `argtypes` attribute" % (cfnptr.__name__, ))
    cargs = [convert_ctypes(a) for a in cfnptr.argtypes]
    cret = convert_ctypes(cfnptr.restype)
    if sys.platform == 'win32' and not cfnptr._flags_ & ctypes._FUNCFLAG_CDECL:
        # 'stdcall' calling convention under Windows
        cconv = 'x86_stdcallcc'
    else:
        # Default C calling convention
        cconv = None

    cases = [templates.signature(cret, *cargs)]
    template = templates.make_concrete_template("CFuncPtr", cfnptr, cases)

    pointer = ctypes.cast(cfnptr, ctypes.c_void_p).value
    return types.FunctionPointer(template, pointer, cconv=cconv)