2010-05-11 15:34:59 -06:00
|
|
|
from ctypes import *
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
uint_ptr = POINTER(c_uint)
|
|
|
|
int_ptr = POINTER(c_int)
|
|
|
|
|
2010-05-11 15:34:59 -06:00
|
|
|
def _uintify(x, y, z):
|
|
|
|
return (c_uint(x), c_uint(y), c_uint(z))
|
|
|
|
|
|
|
|
def _allocate_array(t_type, count):
|
|
|
|
arr_type = t_type * count
|
|
|
|
|
|
|
|
arr = arr_type()
|
|
|
|
|
|
|
|
ptr = c_void_p()
|
|
|
|
ptr = addressof(arr)
|
|
|
|
|
|
|
|
return (arr, ptr)
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
def _alloc_int_buffer(ptr, count):
|
2010-05-25 14:37:40 -06:00
|
|
|
a = _allocate_array(c_int, count)
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
ptr = addressof(a[0])
|
|
|
|
|
|
|
|
return 1
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
_int_functype = CFUNCTYPE(c_int, POINTER(c_int), c_uint)
|
|
|
|
alloc_int_buffer = _int_functype(_alloc_int_buffer)
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
def _alloc_uint_buffer(ptr, count):
|
2010-05-25 14:37:40 -06:00
|
|
|
a = _allocate_array(c_uint, count)
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
ptr = addressof(a[0])
|
|
|
|
|
|
|
|
return 1
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
_uint_functype = CFUNCTYPE(c_int, POINTER(c_uint), c_uint)
|
|
|
|
alloc_uint_buffer = _uint_functype(_alloc_uint_buffer)
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
def _alloc_short_buffer(ptr, count):
|
2010-05-25 14:37:40 -06:00
|
|
|
a = _allocate_array(c_short, count)
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
ptr = addressof(a[0])
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
return 1
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
_short_functype = CFUNCTYPE(c_int, POINTER(c_short), c_uint)
|
|
|
|
alloc_short_buffer = _short_functype(_alloc_short_buffer)
|
|
|
|
|
|
|
|
def _alloc_ushort_buffer(ptr, count):
|
2010-05-25 14:37:40 -06:00
|
|
|
a = _allocate_array(c_ushort, count)
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
ptr = addressof(a[0])
|
|
|
|
|
|
|
|
return 1
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
_ushort_functype = CFUNCTYPE(c_int, POINTER(c_ushort), c_uint)
|
|
|
|
alloc_ushort_buffer = _ushort_functype(_alloc_ushort_buffer)
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
def _alloc_byte_buffer(ptr, count):
|
2010-05-25 14:37:40 -06:00
|
|
|
a = _allocate_array(c_byte, count)
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
ptr = addressof(a[0])
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
return 1
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
_byte_functype = CFUNCTYPE(c_int, POINTER(c_byte), c_uint)
|
|
|
|
alloc_byte_buffer = _byte_functype(_alloc_byte_buffer)
|
|
|
|
|
|
|
|
def _alloc_ubyte_buffer(ptr, count):
|
2010-05-25 14:37:40 -06:00
|
|
|
a = _allocate_array(c_ubyte, count)
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
ptr = addressof(a[0])
|
|
|
|
|
|
|
|
return 1
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
_ubyte_functype = CFUNCTYPE(c_int, POINTER(c_ubyte), c_uint)
|
|
|
|
alloc_ubyte_buffer = _ubyte_functype(_alloc_ubyte_buffer)
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
def _alloc_char_buffer(ptr, count):
|
2010-05-25 14:37:40 -06:00
|
|
|
c = create_string_buffer(count)
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
if ptr is None:
|
|
|
|
ptr = c_void_p
|
|
|
|
|
2010-05-25 14:37:40 -06:00
|
|
|
ptr = addressof(c)
|
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
return 1
|
2010-05-25 14:37:40 -06:00
|
|
|
|
2010-05-27 11:35:40 -06:00
|
|
|
_char_functype = CFUNCTYPE(c_int, POINTER(c_char), c_uint)
|
|
|
|
alloc_char_buffer = _char_functype(_alloc_char_buffer)
|