Debian Codegraph @

Include/internal/pycore_runtime_init.h

raw
1 #ifndef Py_INTERNAL_RUNTIME_INIT_H
2 #define Py_INTERNAL_RUNTIME_INIT_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 #ifndef Py_BUILD_CORE
8 # error "this header requires Py_BUILD_CORE define"
9 #endif
10
11 #include "pycore_structs.h"
12 #include "pycore_ceval_state.h" // _PyEval_RUNTIME_PERF_INIT
13 #include "pycore_debug_offsets.h" // _Py_DebugOffsets_INIT()
14 #include "pycore_dtoa.h" // _dtoa_state_INIT()
15 #include "pycore_faulthandler.h" // _faulthandler_runtime_state_INIT
16 #include "pycore_floatobject.h" // _py_float_format_unknown
17 #include "pycore_function.h"
18 #include "pycore_hamt.h" // _PyHamt_BitmapNode_Type
19 #include "pycore_import.h" // IMPORTS_INIT
20 #include "pycore_object.h" // _PyObject_HEAD_INIT
21 #include "pycore_obmalloc_init.h" // _obmalloc_global_state_INIT
22 #include "pycore_parser.h" // _parser_runtime_state_INIT
23 #include "pycore_pyhash.h" // pyhash_state_INIT
24 #include "pycore_pymem_init.h" // _pymem_allocators_standard_INIT
25 #include "pycore_pythread.h" // _pythread_RUNTIME_INIT
26 #include "pycore_qsbr.h" // QSBR_INITIAL
27 #include "pycore_runtime_init_generated.h" // _Py_bytes_characters_INIT
28 #include "pycore_signal.h" // _signals_RUNTIME_INIT
29 #include "pycore_tracemalloc.h" // _tracemalloc_runtime_state_INIT
30 #include "pycore_tuple.h" // _PyTuple_HASH_EMPTY
31
32
33 extern PyTypeObject _PyExc_MemoryError;
34
35
36 /* The static initializers defined here should only be used
37 in the runtime init code (in pystate.c and pylifecycle.c). */
38
39 #define _PyRuntimeState_INIT(runtime, debug_cookie) \
40 { \
41 .debug_offsets = _Py_DebugOffsets_INIT(debug_cookie), \
42 .allocators = { \
43 .standard = _pymem_allocators_standard_INIT(runtime), \
44 .debug = _pymem_allocators_debug_INIT, \
45 .obj_arena = _pymem_allocators_obj_arena_INIT, \
46 .is_debug_enabled = _pymem_is_debug_enabled_INIT, \
47 }, \
48 .obmalloc = _obmalloc_global_state_INIT, \
49 .pyhash_state = pyhash_state_INIT, \
50 .threads = _pythread_RUNTIME_INIT(runtime.threads), \
51 .signals = _signals_RUNTIME_INIT, \
52 .interpreters = { \
53 /* This prevents interpreters from getting created \
54 until _PyInterpreterState_Enable() is called. */ \
55 .next_id = -1, \
56 }, \
57 .xi = { \
58 .data_lookup = { \
59 .registry = { \
60 .global = 1, \
61 }, \
62 }, \
63 }, \
64 /* A TSS key must be initialized with Py_tss_NEEDS_INIT \
65 in accordance with the specification. */ \
66 .autoTSSkey = Py_tss_NEEDS_INIT, \
67 .parser = _parser_runtime_state_INIT, \
68 .ceval = { \
69 .pending_mainthread = { \
70 .max = MAXPENDINGCALLS_MAIN, \
71 .maxloop = MAXPENDINGCALLSLOOP_MAIN, \
72 }, \
73 .perf = _PyEval_RUNTIME_PERF_INIT, \
74 }, \
75 .gilstate = { \
76 .check_enabled = 1, \
77 }, \
78 .fileutils = { \
79 .force_ascii = -1, \
80 }, \
81 .faulthandler = _faulthandler_runtime_state_INIT, \
82 .tracemalloc = _tracemalloc_runtime_state_INIT, \
83 .ref_tracer = { \
84 .tracer_func = NULL, \
85 .tracer_data = NULL, \
86 }, \
87 .stoptheworld = { \
88 .is_global = 1, \
89 }, \
90 .float_state = { \
91 .float_format = _py_float_format_unknown, \
92 .double_format = _py_float_format_unknown, \
93 }, \
94 .types = { \
95 .next_version_tag = _Py_TYPE_VERSION_NEXT, \
96 }, \
97 .static_objects = { \
98 .singletons = { \
99 .small_ints = _Py_small_ints_INIT, \
100 .bytes_empty = _PyBytes_SIMPLE_INIT(0, 0), \
101 .bytes_characters = _Py_bytes_characters_INIT, \
102 .strings = { \
103 .literals = _Py_str_literals_INIT, \
104 .identifiers = _Py_str_identifiers_INIT, \
105 .ascii = _Py_str_ascii_INIT, \
106 .latin1 = _Py_str_latin1_INIT, \
107 }, \
108 .tuple_empty = { \
109 .ob_base = _PyVarObject_HEAD_INIT(&PyTuple_Type, 0), \
110 .ob_hash = _PyTuple_HASH_EMPTY, \
111 }, \
112 .hamt_bitmap_node_empty = { \
113 .ob_base = _PyVarObject_HEAD_INIT(&_PyHamt_BitmapNode_Type, 0), \
114 }, \
115 .context_token_missing = { \
116 .ob_base = _PyObject_HEAD_INIT(&_PyContextTokenMissing_Type), \
117 }, \
118 }, \
119 }, \
120 ._main_interpreter = _PyInterpreterState_INIT(runtime._main_interpreter), \
121 }
122
123 #define _PyInterpreterState_INIT(INTERP) \
124 { \
125 .id_refcount = -1, \
126 ._whence = _PyInterpreterState_WHENCE_NOTSET, \
127 .threads = { \
128 .preallocated = &(INTERP)._initial_thread, \
129 }, \
130 .imports = IMPORTS_INIT, \
131 .ceval = { \
132 .recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
133 .pending = { \
134 .max = MAXPENDINGCALLS, \
135 .maxloop = MAXPENDINGCALLSLOOP, \
136 }, \
137 }, \
138 .gc = { \
139 .enabled = 1, \
140 GC_GENERATION_INIT \
141 }, \
142 .qsbr = { \
143 .wr_seq = QSBR_INITIAL, \
144 .rd_seq = QSBR_INITIAL, \
145 }, \
146 .dtoa = _dtoa_state_INIT(&(INTERP)), \
147 .dict_state = _dict_state_INIT, \
148 .mem_free_queue = _Py_mem_free_queue_INIT(INTERP.mem_free_queue), \
149 .func_state = { \
150 .next_version = FUNC_VERSION_FIRST_VALID, \
151 }, \
152 .types = { \
153 .next_version_tag = _Py_TYPE_BASE_VERSION_TAG, \
154 }, \
155 .static_objects = { \
156 .singletons = { \
157 ._not_used = 1, \
158 .hamt_empty = { \
159 .ob_base = _PyObject_HEAD_INIT(&_PyHamt_Type), \
160 .h_root = (PyHamtNode*)&_Py_SINGLETON(hamt_bitmap_node_empty), \
161 }, \
162 .last_resort_memory_error = { \
163 _PyObject_HEAD_INIT(&_PyExc_MemoryError), \
164 .args = (PyObject*)&_Py_SINGLETON(tuple_empty) \
165 }, \
166 }, \
167 }, \
168 ._initial_thread = _PyThreadStateImpl_INIT, \
169 }
170
171 #define _PyThreadStateImpl_INIT \
172 { \
173 .base = _PyThreadState_INIT, \
174 /* The thread and the interpreter's linked list hold a reference */ \
175 .refcount = 2, \
176 }
177
178 #define _PyThreadState_INIT \
179 { \
180 ._whence = _PyThreadState_WHENCE_NOTSET, \
181 .py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
182 .context_ver = 1, \
183 }
184
185
186 // global objects
187
188 #define _PyBytes_SIMPLE_INIT(CH, LEN) \
189 { \
190 _PyVarObject_HEAD_INIT(&PyBytes_Type, (LEN)), \
191 .ob_shash = -1, \
192 .ob_sval = { (CH) }, \
193 }
194 #define _PyBytes_CHAR_INIT(CH) \
195 { \
196 _PyBytes_SIMPLE_INIT((CH), 1) \
197 }
198
199 #define _PyUnicode_ASCII_BASE_INIT(LITERAL, ASCII) \
200 { \
201 .ob_base = _PyObject_HEAD_INIT(&PyUnicode_Type), \
202 .length = sizeof(LITERAL) - 1, \
203 .hash = -1, \
204 .state = { \
205 .kind = 1, \
206 .compact = 1, \
207 .ascii = (ASCII), \
208 .statically_allocated = 1, \
209 }, \
210 }
211 #define _PyASCIIObject_INIT(LITERAL) \
212 { \
213 ._ascii = _PyUnicode_ASCII_BASE_INIT((LITERAL), 1), \
214 ._data = (LITERAL) \
215 }
216 #define INIT_STR(NAME, LITERAL) \
217 ._py_ ## NAME = _PyASCIIObject_INIT(LITERAL)
218 #define INIT_ID(NAME) \
219 ._py_ ## NAME = _PyASCIIObject_INIT(#NAME)
220 #define _PyUnicode_LATIN1_INIT(LITERAL, UTF8) \
221 { \
222 ._latin1 = { \
223 ._base = _PyUnicode_ASCII_BASE_INIT((LITERAL), 0), \
224 .utf8 = (UTF8), \
225 .utf8_length = sizeof(UTF8) - 1, \
226 }, \
227 ._data = (LITERAL), \
228 }
229
230 #ifdef __cplusplus
231 }
232 #endif
233 #endif /* !Py_INTERNAL_RUNTIME_INIT_H */