Beispiel #1
0
def _cast_ptr2(x, _type):
    if isinstance(x, ffi.CData):
        if (_type.item == ffi.typeof(x) or
            (_type.item.cname == 'void' and ffi.typeof(x).kind in
             ['struct', 'union'])):
            return ffi.addressof(x), x
        return x, x

    if isinstance(x, _collections.Iterable):
        if _type.item.kind == 'pointer':
            ptrs = [_cast_ptr(i, _type.item) for i in x]
            ret = ffi.new(_type.item.cname+'[]', [i for i, _ in ptrs])
            _weakkey_dict[ret] = tuple(i for _, i in ptrs if i != ffi.NULL)
        else:
            ret = ffi.new(_type.item.cname+'[]', x)

        return ret, ret

    return ffi.cast(_type, x), x
Beispiel #2
0
def _cstr(x):
    if not isinstance(x, ffi.CData):
        return x

    t = ffi.typeof(x)
    if 'item' not in dir(t) or t.item.cname != 'char':
        return x

    if PY3:
        return ffi.string(x).decode('ascii')
    else:
        return ffi.string(x)
Beispiel #3
0
def _callApi(fn, *args):
    fn_args = [_auto_handle(i, j) for i, j in zip(args, ffi.typeof(fn).args)]
Beispiel #4
0
def _new(ctype, **kwargs):
    _type = ffi.typeof(ctype)