|
|
@ -1,7 +1,15 @@
|
|
|
|
from ctypes import *
|
|
|
|
from ctypes import *
|
|
|
|
|
|
|
|
|
|
|
|
uint_ptr = POINTER(c_uint)
|
|
|
|
|
|
|
|
int_ptr = POINTER(c_int)
|
|
|
|
int_ptr = POINTER(c_int)
|
|
|
|
|
|
|
|
uint_ptr = POINTER(c_uint)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
short_ptr = POINTER(c_short)
|
|
|
|
|
|
|
|
ushort_ptr = POINTER(c_ushort)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte_ptr = POINTER(c_byte)
|
|
|
|
|
|
|
|
ubyte_ptr = POINTER(c_ubyte)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointer_dict = {}
|
|
|
|
|
|
|
|
|
|
|
|
def _uintify(x, y, z):
|
|
|
|
def _uintify(x, y, z):
|
|
|
|
return (c_uint(x), c_uint(y), c_uint(z))
|
|
|
|
return (c_uint(x), c_uint(y), c_uint(z))
|
|
|
@ -11,80 +19,92 @@ def _allocate_array(t_type, count):
|
|
|
|
|
|
|
|
|
|
|
|
arr = arr_type()
|
|
|
|
arr = arr_type()
|
|
|
|
|
|
|
|
|
|
|
|
ptr = c_void_p()
|
|
|
|
return arr
|
|
|
|
ptr = addressof(arr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (arr, ptr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _alloc_int_buffer(ptr, count):
|
|
|
|
def _alloc_int_buffer(ptr, count):
|
|
|
|
a = _allocate_array(c_int, count)
|
|
|
|
a = _allocate_array(c_int, count)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p = cast(a, int_ptr)
|
|
|
|
|
|
|
|
|
|
|
|
ptr = addressof(a[0])
|
|
|
|
ptr[0] = p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointer_dict[id(ptr[0])] = (ptr, a, p)
|
|
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
_int_functype = CFUNCTYPE(c_int, POINTER(c_int), c_uint)
|
|
|
|
_int_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_int)), c_uint)
|
|
|
|
alloc_int_buffer = _int_functype(_alloc_int_buffer)
|
|
|
|
alloc_int_buffer = _int_functype(_alloc_int_buffer)
|
|
|
|
|
|
|
|
|
|
|
|
def _alloc_uint_buffer(ptr, count):
|
|
|
|
def _alloc_uint_buffer(ptr, count):
|
|
|
|
a = _allocate_array(c_uint, count)
|
|
|
|
a = _allocate_array(c_uint, count)
|
|
|
|
|
|
|
|
|
|
|
|
ptr = addressof(a[0])
|
|
|
|
ptr[0] = cast(a, uint_ptr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointer_dict[id(ptr[0])] = (ptr, a, p)
|
|
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
_uint_functype = CFUNCTYPE(c_int, POINTER(c_uint), c_uint)
|
|
|
|
_uint_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_uint)), c_uint)
|
|
|
|
alloc_uint_buffer = _uint_functype(_alloc_uint_buffer)
|
|
|
|
alloc_uint_buffer = _uint_functype(_alloc_uint_buffer)
|
|
|
|
|
|
|
|
|
|
|
|
def _alloc_short_buffer(ptr, count):
|
|
|
|
def _alloc_short_buffer(ptr, count):
|
|
|
|
a = _allocate_array(c_short, count)
|
|
|
|
a = _allocate_array(c_short, count)
|
|
|
|
|
|
|
|
|
|
|
|
ptr = addressof(a[0])
|
|
|
|
ptr[0] = cast(a, short_ptr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointer_dict[id(ptr[0])] = (ptr, a, p)
|
|
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
_short_functype = CFUNCTYPE(c_int, POINTER(c_short), c_uint)
|
|
|
|
_short_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_short)), c_uint)
|
|
|
|
alloc_short_buffer = _short_functype(_alloc_short_buffer)
|
|
|
|
alloc_short_buffer = _short_functype(_alloc_short_buffer)
|
|
|
|
|
|
|
|
|
|
|
|
def _alloc_ushort_buffer(ptr, count):
|
|
|
|
def _alloc_ushort_buffer(ptr, count):
|
|
|
|
a = _allocate_array(c_ushort, count)
|
|
|
|
a = _allocate_array(c_ushort, count)
|
|
|
|
|
|
|
|
|
|
|
|
ptr = addressof(a[0])
|
|
|
|
ptr[0] = cast(a, ushort_ptr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointer_dict[id(ptr[0])] = (ptr, a, p)
|
|
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
_ushort_functype = CFUNCTYPE(c_int, POINTER(c_ushort), c_uint)
|
|
|
|
_ushort_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_ushort)), c_uint)
|
|
|
|
alloc_ushort_buffer = _ushort_functype(_alloc_ushort_buffer)
|
|
|
|
alloc_ushort_buffer = _ushort_functype(_alloc_ushort_buffer)
|
|
|
|
|
|
|
|
|
|
|
|
def _alloc_byte_buffer(ptr, count):
|
|
|
|
def _alloc_byte_buffer(ptr, count):
|
|
|
|
a = _allocate_array(c_byte, count)
|
|
|
|
a = _allocate_array(c_byte, count)
|
|
|
|
|
|
|
|
|
|
|
|
ptr = addressof(a[0])
|
|
|
|
ptr[0] = cast(a, byte_ptr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointer_dict[id(ptr[0])] = (ptr, a, p)
|
|
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
_byte_functype = CFUNCTYPE(c_int, POINTER(c_byte), c_uint)
|
|
|
|
_byte_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_byte)), c_uint)
|
|
|
|
alloc_byte_buffer = _byte_functype(_alloc_byte_buffer)
|
|
|
|
alloc_byte_buffer = _byte_functype(_alloc_byte_buffer)
|
|
|
|
|
|
|
|
|
|
|
|
def _alloc_ubyte_buffer(ptr, count):
|
|
|
|
def _alloc_ubyte_buffer(ptr, count):
|
|
|
|
a = _allocate_array(c_ubyte, count)
|
|
|
|
a = _allocate_array(c_ubyte, count)
|
|
|
|
|
|
|
|
|
|
|
|
ptr = addressof(a[0])
|
|
|
|
ptr[0] = cast(a, ubyte_ptr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointer_dict[id(ptr[0])] = (ptr, a, p)
|
|
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
_ubyte_functype = CFUNCTYPE(c_int, POINTER(c_ubyte), c_uint)
|
|
|
|
_ubyte_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_ubyte)), c_uint)
|
|
|
|
alloc_ubyte_buffer = _ubyte_functype(_alloc_ubyte_buffer)
|
|
|
|
alloc_ubyte_buffer = _ubyte_functype(_alloc_ubyte_buffer)
|
|
|
|
|
|
|
|
|
|
|
|
def _alloc_char_buffer(ptr, count):
|
|
|
|
def _alloc_char_buffer(ptr, count):
|
|
|
|
c = create_string_buffer(count)
|
|
|
|
c = create_string_buffer(count)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p = cast(c, POINTER(c_char))
|
|
|
|
|
|
|
|
|
|
|
|
if ptr is None:
|
|
|
|
ptr[0] = p
|
|
|
|
ptr = c_void_p
|
|
|
|
|
|
|
|
|
|
|
|
pointer_dict[id(ptr[0])] = (ptr, c, p)
|
|
|
|
ptr = addressof(c)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
_char_functype = CFUNCTYPE(c_int, POINTER(c_char), c_uint)
|
|
|
|
_char_functype = CFUNCTYPE(c_int, POINTER(POINTER(c_char)), c_uint)
|
|
|
|
alloc_char_buffer = _char_functype(_alloc_char_buffer)
|
|
|
|
alloc_char_buffer = _char_functype(_alloc_char_buffer)
|
|
|
|