Repository navigation
Expand file tree
/
Copy pathstd_structs.py
More file actions
181 lines (143 loc) · 3.27 KB
/
Copy pathstd_structs.py
File metadata and controls
181 lines (143 loc) · 3.27 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import ctypes
from typing import Any, Callable, Dict, Type
from ._cstd import div_t, lconv, ldiv_t, tm
from ._pyapi import (
Py_buffer,
Py_tss_t,
PyCodeObject,
PyFrameObject,
PyGetSetDef,
PyInterpreterState,
PyMethodDef,
PyModuleDef,
PyThreadState,
PyType_Slot,
PyType_Spec,
PyTypeObject,
PyVarObject,
)
from .c_pointer import TypedCPointer, VoidPointer
from .structure import Struct, StructPointer
from .util import raw_type
__all__ = (
"Tm",
"DivT",
"LDivT",
"Lconv",
"PyTypeSlot",
"PyTypeSpec",
"Buffer",
"TypeObject",
"ThreadState",
"FrameObject",
"VarObject",
"ModuleDef",
"TssT",
"InterpreterState",
"CodeObject",
"MethodDef",
"GetSetDef",
"STRUCT_MAP",
)
class Tm(Struct):
tm_sec: int
tm_min: int
tm_hour: int
tm_mday: int
tm_mon: int
tm_year: int
tm_wday: int
tm_yday: int
tm_isdst: int
class DivT(Struct):
quot: int
rem: int
class LDivT(DivT):
pass
class Lconv(Struct):
decimal_point: bytes
thousands_sep: bytes
grouping: bytes
int_curr_symbol: bytes
currency_symbol: bytes
mon_decimal_point: bytes
mon_thousands_sep: bytes
mon_grouping: bytes
positive_sign: bytes
negative_sign: bytes
frac_digits: bytes
p_cs_precedes: bytes
p_sep_by_space: bytes
n_sep_by_space: bytes
p_sign_posn: bytes
n_sign_posn: bytes
class PyTypeSlot(Struct):
slot: int
pfunc: VoidPointer
class PyTypeSpec(Struct):
name: bytes
basic_size: int
itemsize: int
flags: int
slots: StructPointer[PyTypeSlot]
class Buffer(Struct):
buf: VoidPointer
obj: VoidPointer
len: int
readonly: int
itemsize: int
format: bytes
ndim: int
shape: TypedCPointer[int] = raw_type(ctypes.POINTER(ctypes.c_ssize_t))
strides: TypedCPointer[int] = raw_type(ctypes.POINTER(ctypes.c_ssize_t))
suboffsets: TypedCPointer[int] = raw_type(ctypes.POINTER(ctypes.c_ssize_t))
internal: VoidPointer
class TypeObject(Struct):
__PYOBJECT__ = True
class ThreadState(Struct):
pass
class FrameObject(Struct):
__PYOBJECT__ = True
class VarObject(Struct):
ob_size: int = raw_type(ctypes.c_ssize_t)
ob_refcnt: int = raw_type(ctypes.c_ssize_t)
ob_type: StructPointer[TypeObject]
class ModuleDef(Struct):
m_base: bytes
pfunc: VoidPointer
class TssT(Struct):
pass
class InterpreterState(Struct):
pass
class CodeObject(Struct):
pass
class MethodDef(Struct):
ml_name: bytes
ml_meth: Callable[[Any], Any]
ml_flags: int
ml_doc: bytes
class GetSetDef(Struct):
name: bytes
get: Callable[[Any, VoidPointer], Any]
set: Callable[[Any, Any, VoidPointer], int]
doc: bytes
closure: VoidPointer
STRUCT_MAP: Dict[Type[ctypes.Structure], Type[Struct]] = {
tm: Tm,
div_t: DivT,
ldiv_t: LDivT,
lconv: Lconv,
PyType_Slot: PyTypeSlot,
PyType_Spec: PyTypeSpec,
Py_buffer: Buffer,
PyInterpreterState: InterpreterState,
PyModuleDef: ModuleDef,
Py_tss_t: TssT,
PyVarObject: VarObject,
PyFrameObject: FrameObject,
PyThreadState: ThreadState,
PyTypeObject: TypeObject,
PyCodeObject: CodeObject,
PyMethodDef: MethodDef,
PyGetSetDef: GetSetDef,
}