예제 #1
0
def _c_call2(c_type1, c_type2, c_fun, *args, handler=None):
    '''
    Helper to simplify calling C functions where the last two parameters are a
    reference to the return value.
    '''
    p_ret1 = _ffi.new(f'{c_type1}*')
    p_ret2 = _ffi.new(f'{c_type2}*')
    _handle_error(c_fun(*args, p_ret1, p_ret2), handler)
    return p_ret1[0], p_ret2[0]
예제 #2
0
def _c_call(c_type, c_fun, *args, handler=None):
    '''
    Helper to simplify calling C functions where the last parameter is a
    reference to the return value.
    '''
    if isinstance(c_type, str):
        p_ret = _ffi.new(f'{c_type}*')
    else:
        p_ret = c_type
    _handle_error(c_fun(*args, p_ret), handler)
    return p_ret[0]
예제 #3
0
def _str(f_size, f_str, *args, handler=None):
    p_size = _ffi.new('size_t*')
    _handle_error(f_size(*args, p_size), handler)
    p_str = _ffi.new('char[]', p_size[0])
    _handle_error(f_str(*args, p_str, p_size[0]), handler)
    return _ffi.string(p_str).decode()