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_long.h"
12 #include "pycore_object.h"
13 #include "pycore_parser.h"
14 #include "pycore_pymem_init.h"
15 #include "pycore_obmalloc_init.h"
16
17
18 extern PyTypeObject _PyExc_MemoryError;
19
20
21 /* The static initializers defined here should only be used
22 in the runtime init code (in pystate.c and pylifecycle.c). */
23
24
25 #define _PyRuntimeState_INIT(runtime) \
26 { \
27 .allocators = { \
28 .standard = _pymem_allocators_standard_INIT(runtime), \
29 .debug = _pymem_allocators_debug_INIT, \
30 .obj_arena = _pymem_allocators_obj_arena_INIT, \
31 }, \
32 .obmalloc = _obmalloc_global_state_INIT, \
33 .pyhash_state = pyhash_state_INIT, \
34 .signals = _signals_RUNTIME_INIT, \
35 .interpreters = { \
36 /* This prevents interpreters from getting created \
37 until _PyInterpreterState_Enable() is called. */ \
38 .next_id = -1, \
39 }, \
40 /* A TSS key must be initialized with Py_tss_NEEDS_INIT \
41 in accordance with the specification. */ \
42 .autoTSSkey = Py_tss_NEEDS_INIT, \
43 .parser = _parser_runtime_state_INIT, \
44 .ceval = { \
45 .perf = _PyEval_RUNTIME_PERF_INIT, \
46 }, \
47 .gilstate = { \
48 .check_enabled = 1, \
49 }, \
50 .fileutils = { \
51 .force_ascii = -1, \
52 }, \
53 .faulthandler = _faulthandler_runtime_state_INIT, \
54 .tracemalloc = _tracemalloc_runtime_state_INIT, \
55 .float_state = { \
56 .float_format = _py_float_format_unknown, \
57 .double_format = _py_float_format_unknown, \
58 }, \
59 .types = { \
60 .next_version_tag = 1, \
61 }, \
62 .static_objects = { \
63 .singletons = { \
64 .small_ints = _Py_small_ints_INIT, \
65 .bytes_empty = _PyBytes_SIMPLE_INIT(0, 0), \
66 .bytes_characters = _Py_bytes_characters_INIT, \
67 .strings = { \
68 .literals = _Py_str_literals_INIT, \
69 .identifiers = _Py_str_identifiers_INIT, \
70 .ascii = _Py_str_ascii_INIT, \
71 .latin1 = _Py_str_latin1_INIT, \
72 }, \
73 .tuple_empty = { \
74 .ob_base = _PyVarObject_HEAD_INIT(&PyTuple_Type, 0) \
75 }, \
76 .hamt_bitmap_node_empty = { \
77 .ob_base = _PyVarObject_HEAD_INIT(&_PyHamt_BitmapNode_Type, 0) \
78 }, \
79 .context_token_missing = { \
80 .ob_base = _PyObject_HEAD_INIT(&_PyContextTokenMissing_Type) \
81 }, \
82 }, \
83 }, \
84 ._main_interpreter = _PyInterpreterState_INIT(runtime._main_interpreter), \
85 }
86
87 #define _PyInterpreterState_INIT(INTERP) \
88 { \
89 .id_refcount = -1, \
90 .imports = IMPORTS_INIT, \
91 .obmalloc = _obmalloc_state_INIT(INTERP.obmalloc), \
92 .ceval = { \
93 .recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
94 }, \
95 .gc = { \
96 .enabled = 1, \
97 .generations = { \
98 /* .head is set in _PyGC_InitState(). */ \
99 { .threshold = 700, }, \
100 { .threshold = 10, }, \
101 { .threshold = 10, }, \
102 }, \
103 }, \
104 .object_state = _py_object_state_INIT(INTERP), \
105 .dtoa = _dtoa_state_INIT(&(INTERP)), \
106 .dict_state = _dict_state_INIT, \
107 .func_state = { \
108 .next_version = 1, \
109 }, \
110 .types = { \
111 .next_version_tag = _Py_TYPE_BASE_VERSION_TAG, \
112 }, \
113 .static_objects = { \
114 .singletons = { \
115 ._not_used = 1, \
116 .hamt_empty = { \
117 .ob_base = _PyObject_HEAD_INIT(&_PyHamt_Type) \
118 .h_root = (PyHamtNode*)&_Py_SINGLETON(hamt_bitmap_node_empty), \
119 }, \
120 .last_resort_memory_error = { \
121 _PyObject_HEAD_INIT(&_PyExc_MemoryError) \
122 }, \
123 }, \
124 }, \
125 ._initial_thread = _PyThreadState_INIT, \
126 }
127
128 #define _PyThreadState_INIT \
129 { \
130 .py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
131 .context_ver = 1, \
132 }
133
134 #ifdef Py_TRACE_REFS
135 # define _py_object_state_INIT(INTERP) \
136 { \
137 .refchain = {&INTERP.object_state.refchain, &INTERP.object_state.refchain}, \
138 }
139 #else
140 # define _py_object_state_INIT(INTERP) \
141 { 0 }
142 #endif
143
144
145 // global objects
146
147 #define _PyBytes_SIMPLE_INIT(CH, LEN) \
148 { \
149 _PyVarObject_HEAD_INIT(&PyBytes_Type, (LEN)) \
150 .ob_shash = -1, \
151 .ob_sval = { (CH) }, \
152 }
153 #define _PyBytes_CHAR_INIT(CH) \
154 { \
155 _PyBytes_SIMPLE_INIT((CH), 1) \
156 }
157
158 #define _PyUnicode_ASCII_BASE_INIT(LITERAL, ASCII) \
159 { \
160 .ob_base = _PyObject_HEAD_INIT(&PyUnicode_Type) \
161 .length = sizeof(LITERAL) - 1, \
162 .hash = -1, \
163 .state = { \
164 .kind = 1, \
165 .compact = 1, \
166 .ascii = (ASCII), \
167 }, \
168 }
169 #define _PyASCIIObject_INIT(LITERAL) \
170 { \
171 ._ascii = _PyUnicode_ASCII_BASE_INIT((LITERAL), 1), \
172 ._data = (LITERAL) \
173 }
174 #define INIT_STR(NAME, LITERAL) \
175 ._py_ ## NAME = _PyASCIIObject_INIT(LITERAL)
176 #define INIT_ID(NAME) \
177 ._py_ ## NAME = _PyASCIIObject_INIT(#NAME)
178 #define _PyUnicode_LATIN1_INIT(LITERAL, UTF8) \
179 { \
180 ._latin1 = { \
181 ._base = _PyUnicode_ASCII_BASE_INIT((LITERAL), 0), \
182 .utf8 = (UTF8), \
183 .utf8_length = sizeof(UTF8) - 1, \
184 }, \
185 ._data = (LITERAL), \
186 }
187
188 #include "pycore_runtime_init_generated.h"
189
190 #ifdef __cplusplus
191 }
192 #endif
193 #endif /* !Py_INTERNAL_RUNTIME_INIT_H */