Exemplo n.º 1
0
def sizeof(ctype, count):
    ctype = to_type(ctype)
    if count:
        size = simple.sizeof_a(ctype, count.value)
    else:
        size = simple.sizeof(ctype)
    return Integer(size)
Exemplo n.º 2
0
def sizeof(ctype, count):
    ctype = to_type(ctype)
    if count:
        size = simple.sizeof_a(ctype, count.value)
    else:
        size = simple.sizeof(ctype)
    return Integer(size)
Exemplo n.º 3
0
def cast(obj, ctype):
    ctype = to_type(ctype)
    if isinstance(obj, Handle):
        return Handle(obj.library, obj.name, obj.pointer, ctype)
    if isinstance(obj, Mem):
        return Mem(ctype, obj.pointer)
    if isinstance(obj, Uint8Data):
        return Mem(ctype, rffi.cast(rffi.VOIDP, obj.uint8data))
    if isinstance(obj, Integer) and isinstance(ctype, Pointer):
        return Mem(ctype, rffi.cast(rffi.VOIDP, obj.value))
    raise unwind(LTypeError(u"Can cast memory locations only"))
Exemplo n.º 4
0
def cast(obj, ctype):
    ctype = to_type(ctype)
    if isinstance(obj, Handle):
        return Handle(obj.library, obj.name, obj.pointer, ctype)
    if isinstance(obj, Mem):
        return Mem(ctype, obj.pointer)
    if isinstance(obj, Uint8Array):
        return Mem(ctype, rffi.cast(rffi.VOIDP, obj.uint8data))
    if isinstance(obj, Integer) and isinstance(ctype, Pointer):
        return Mem(ctype, rffi.cast(rffi.VOIDP, obj.value))
    raise unwind(LTypeError(u"Can cast memory locations only"))
Exemplo n.º 5
0
def automem(ctype, count, clear):
    ctype = to_type(ctype)
    if count:
        n = count.value
        size = simple.sizeof_a(ctype, n)
    else:
        n = 1
        size = simple.sizeof(ctype)
    pointer = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw')
    if is_true(clear):
        rffi.c_memset(pointer, 0, size)
    return systemv.AutoMem(systemv.Pointer(ctype), pointer, n)
Exemplo n.º 6
0
def automem(ctype, count, clear):
    ctype = to_type(ctype)
    if count:
        n = count.value
        size = simple.sizeof_a(ctype, n)
    else:
        n = 1
        size = simple.sizeof(ctype)
    pointer = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw')
    if is_true(clear):
        rffi.c_memset(pointer, 0, size)
    return systemv.AutoMem(systemv.Pointer(ctype), pointer, n)