forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
90 lines (55 loc) · 1.94 KB
/
Copy pathutil.py
File metadata and controls
90 lines (55 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from ctypes import *
uint_ptr = POINTER(c_uint)
int_ptr = POINTER(c_int)
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)
def _alloc_int_buffer(ptr, count):
a = _allocate_array(c_int, count)
ptr = addressof(a[0])
return 1
_int_functype = CFUNCTYPE(c_int, POINTER(c_int), c_uint)
alloc_int_buffer = _int_functype(_alloc_int_buffer)
def _alloc_uint_buffer(ptr, count):
a = _allocate_array(c_uint, count)
ptr = addressof(a[0])
return 1
_uint_functype = CFUNCTYPE(c_int, POINTER(c_uint), c_uint)
alloc_uint_buffer = _uint_functype(_alloc_uint_buffer)
def _alloc_short_buffer(ptr, count):
a = _allocate_array(c_short, count)
ptr = addressof(a[0])
return 1
_short_functype = CFUNCTYPE(c_int, POINTER(c_short), c_uint)
alloc_short_buffer = _short_functype(_alloc_short_buffer)
def _alloc_ushort_buffer(ptr, count):
a = _allocate_array(c_ushort, count)
ptr = addressof(a[0])
return 1
_ushort_functype = CFUNCTYPE(c_int, POINTER(c_ushort), c_uint)
alloc_ushort_buffer = _ushort_functype(_alloc_ushort_buffer)
def _alloc_byte_buffer(ptr, count):
a = _allocate_array(c_byte, count)
ptr = addressof(a[0])
return 1
_byte_functype = CFUNCTYPE(c_int, POINTER(c_byte), c_uint)
alloc_byte_buffer = _byte_functype(_alloc_byte_buffer)
def _alloc_ubyte_buffer(ptr, count):
a = _allocate_array(c_ubyte, count)
ptr = addressof(a[0])
return 1
_ubyte_functype = CFUNCTYPE(c_int, POINTER(c_ubyte), c_uint)
alloc_ubyte_buffer = _ubyte_functype(_alloc_ubyte_buffer)
def _alloc_char_buffer(ptr, count):
c = create_string_buffer(count)
if ptr is None:
ptr = c_void_p
ptr = addressof(c)
return 1
_char_functype = CFUNCTYPE(c_int, POINTER(c_char), c_uint)
alloc_char_buffer = _char_functype(_alloc_char_buffer)