File indexing completed on 2025-11-19 09:50:50
0001 #ifndef Py_INTERNAL_RUNTIME_INIT_H
0002 #define Py_INTERNAL_RUNTIME_INIT_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007 #ifndef Py_BUILD_CORE
0008 # error "this header requires Py_BUILD_CORE define"
0009 #endif
0010
0011 #include "pycore_ceval_state.h" // _PyEval_RUNTIME_PERF_INIT
0012 #include "pycore_faulthandler.h" // _faulthandler_runtime_state_INIT
0013 #include "pycore_floatobject.h" // _py_float_format_unknown
0014 #include "pycore_object.h" // _PyObject_HEAD_INIT
0015 #include "pycore_obmalloc_init.h" // _obmalloc_global_state_INIT
0016 #include "pycore_parser.h" // _parser_runtime_state_INIT
0017 #include "pycore_pyhash.h" // pyhash_state_INIT
0018 #include "pycore_pymem_init.h" // _pymem_allocators_standard_INIT
0019 #include "pycore_pythread.h" // _pythread_RUNTIME_INIT
0020 #include "pycore_qsbr.h" // QSBR_INITIAL
0021 #include "pycore_runtime_init_generated.h" // _Py_bytes_characters_INIT
0022 #include "pycore_signal.h" // _signals_RUNTIME_INIT
0023 #include "pycore_tracemalloc.h" // _tracemalloc_runtime_state_INIT
0024
0025
0026 extern PyTypeObject _PyExc_MemoryError;
0027
0028
0029
0030
0031
0032 #define _PyRuntimeState_INIT(runtime, debug_cookie) \
0033 { \
0034 .debug_offsets = { \
0035 .cookie = debug_cookie, \
0036 .version = PY_VERSION_HEX, \
0037 .free_threaded = _Py_Debug_Free_Threaded, \
0038 .runtime_state = { \
0039 .size = sizeof(_PyRuntimeState), \
0040 .finalizing = offsetof(_PyRuntimeState, _finalizing), \
0041 .interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \
0042 }, \
0043 .interpreter_state = { \
0044 .size = sizeof(PyInterpreterState), \
0045 .id = offsetof(PyInterpreterState, id), \
0046 .next = offsetof(PyInterpreterState, next), \
0047 .threads_head = offsetof(PyInterpreterState, threads.head), \
0048 .gc = offsetof(PyInterpreterState, gc), \
0049 .imports_modules = offsetof(PyInterpreterState, imports.modules), \
0050 .sysdict = offsetof(PyInterpreterState, sysdict), \
0051 .builtins = offsetof(PyInterpreterState, builtins), \
0052 .ceval_gil = offsetof(PyInterpreterState, ceval.gil), \
0053 .gil_runtime_state = offsetof(PyInterpreterState, _gil), \
0054 .gil_runtime_state_enabled = _Py_Debug_gilruntimestate_enabled, \
0055 .gil_runtime_state_locked = offsetof(PyInterpreterState, _gil.locked), \
0056 .gil_runtime_state_holder = offsetof(PyInterpreterState, _gil.last_holder), \
0057 }, \
0058 .thread_state = { \
0059 .size = sizeof(PyThreadState), \
0060 .prev = offsetof(PyThreadState, prev), \
0061 .next = offsetof(PyThreadState, next), \
0062 .interp = offsetof(PyThreadState, interp), \
0063 .current_frame = offsetof(PyThreadState, current_frame), \
0064 .thread_id = offsetof(PyThreadState, thread_id), \
0065 .native_thread_id = offsetof(PyThreadState, native_thread_id), \
0066 .datastack_chunk = offsetof(PyThreadState, datastack_chunk), \
0067 .status = offsetof(PyThreadState, _status), \
0068 }, \
0069 .interpreter_frame = { \
0070 .size = sizeof(_PyInterpreterFrame), \
0071 .previous = offsetof(_PyInterpreterFrame, previous), \
0072 .executable = offsetof(_PyInterpreterFrame, f_executable), \
0073 .instr_ptr = offsetof(_PyInterpreterFrame, instr_ptr), \
0074 .localsplus = offsetof(_PyInterpreterFrame, localsplus), \
0075 .owner = offsetof(_PyInterpreterFrame, owner), \
0076 }, \
0077 .code_object = { \
0078 .size = sizeof(PyCodeObject), \
0079 .filename = offsetof(PyCodeObject, co_filename), \
0080 .name = offsetof(PyCodeObject, co_name), \
0081 .qualname = offsetof(PyCodeObject, co_qualname), \
0082 .linetable = offsetof(PyCodeObject, co_linetable), \
0083 .firstlineno = offsetof(PyCodeObject, co_firstlineno), \
0084 .argcount = offsetof(PyCodeObject, co_argcount), \
0085 .localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \
0086 .localspluskinds = offsetof(PyCodeObject, co_localspluskinds), \
0087 .co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \
0088 }, \
0089 .pyobject = { \
0090 .size = sizeof(PyObject), \
0091 .ob_type = offsetof(PyObject, ob_type), \
0092 }, \
0093 .type_object = { \
0094 .size = sizeof(PyTypeObject), \
0095 .tp_name = offsetof(PyTypeObject, tp_name), \
0096 .tp_repr = offsetof(PyTypeObject, tp_repr), \
0097 .tp_flags = offsetof(PyTypeObject, tp_flags), \
0098 }, \
0099 .tuple_object = { \
0100 .size = sizeof(PyTupleObject), \
0101 .ob_item = offsetof(PyTupleObject, ob_item), \
0102 .ob_size = offsetof(PyTupleObject, ob_base.ob_size), \
0103 }, \
0104 .list_object = { \
0105 .size = sizeof(PyListObject), \
0106 .ob_item = offsetof(PyListObject, ob_item), \
0107 .ob_size = offsetof(PyListObject, ob_base.ob_size), \
0108 }, \
0109 .dict_object = { \
0110 .size = sizeof(PyDictObject), \
0111 .ma_keys = offsetof(PyDictObject, ma_keys), \
0112 .ma_values = offsetof(PyDictObject, ma_values), \
0113 }, \
0114 .float_object = { \
0115 .size = sizeof(PyFloatObject), \
0116 .ob_fval = offsetof(PyFloatObject, ob_fval), \
0117 }, \
0118 .long_object = { \
0119 .size = sizeof(PyLongObject), \
0120 .lv_tag = offsetof(PyLongObject, long_value.lv_tag), \
0121 .ob_digit = offsetof(PyLongObject, long_value.ob_digit), \
0122 }, \
0123 .bytes_object = { \
0124 .size = sizeof(PyBytesObject), \
0125 .ob_size = offsetof(PyBytesObject, ob_base.ob_size), \
0126 .ob_sval = offsetof(PyBytesObject, ob_sval), \
0127 }, \
0128 .unicode_object = { \
0129 .size = sizeof(PyUnicodeObject), \
0130 .state = offsetof(PyUnicodeObject, _base._base.state), \
0131 .length = offsetof(PyUnicodeObject, _base._base.length), \
0132 .asciiobject_size = sizeof(PyASCIIObject), \
0133 }, \
0134 .gc = { \
0135 .size = sizeof(struct _gc_runtime_state), \
0136 .collecting = offsetof(struct _gc_runtime_state, collecting), \
0137 }, \
0138 }, \
0139 .allocators = { \
0140 .standard = _pymem_allocators_standard_INIT(runtime), \
0141 .debug = _pymem_allocators_debug_INIT, \
0142 .obj_arena = _pymem_allocators_obj_arena_INIT, \
0143 .is_debug_enabled = _pymem_is_debug_enabled_INIT, \
0144 }, \
0145 .obmalloc = _obmalloc_global_state_INIT, \
0146 .pyhash_state = pyhash_state_INIT, \
0147 .threads = _pythread_RUNTIME_INIT(runtime.threads), \
0148 .signals = _signals_RUNTIME_INIT, \
0149 .interpreters = { \
0150
0151 \
0152 .next_id = -1, \
0153 }, \
0154 .xi = { \
0155 .registry = { \
0156 .global = 1, \
0157 }, \
0158 }, \
0159
0160 \
0161 .autoTSSkey = Py_tss_NEEDS_INIT, \
0162 .parser = _parser_runtime_state_INIT, \
0163 .ceval = { \
0164 .pending_mainthread = { \
0165 .max = MAXPENDINGCALLS_MAIN, \
0166 .maxloop = MAXPENDINGCALLSLOOP_MAIN, \
0167 }, \
0168 .perf = _PyEval_RUNTIME_PERF_INIT, \
0169 }, \
0170 .gilstate = { \
0171 .check_enabled = 1, \
0172 }, \
0173 .fileutils = { \
0174 .force_ascii = -1, \
0175 }, \
0176 .faulthandler = _faulthandler_runtime_state_INIT, \
0177 .tracemalloc = _tracemalloc_runtime_state_INIT, \
0178 .ref_tracer = { \
0179 .tracer_func = NULL, \
0180 .tracer_data = NULL, \
0181 }, \
0182 .stoptheworld = { \
0183 .is_global = 1, \
0184 }, \
0185 .float_state = { \
0186 .float_format = _py_float_format_unknown, \
0187 .double_format = _py_float_format_unknown, \
0188 }, \
0189 .types = { \
0190 .next_version_tag = 1, \
0191 }, \
0192 .static_objects = { \
0193 .singletons = { \
0194 .small_ints = _Py_small_ints_INIT, \
0195 .bytes_empty = _PyBytes_SIMPLE_INIT(0, 0), \
0196 .bytes_characters = _Py_bytes_characters_INIT, \
0197 .strings = { \
0198 .literals = _Py_str_literals_INIT, \
0199 .identifiers = _Py_str_identifiers_INIT, \
0200 .ascii = _Py_str_ascii_INIT, \
0201 .latin1 = _Py_str_latin1_INIT, \
0202 }, \
0203 .tuple_empty = { \
0204 .ob_base = _PyVarObject_HEAD_INIT(&PyTuple_Type, 0), \
0205 }, \
0206 .hamt_bitmap_node_empty = { \
0207 .ob_base = _PyVarObject_HEAD_INIT(&_PyHamt_BitmapNode_Type, 0), \
0208 }, \
0209 .context_token_missing = { \
0210 .ob_base = _PyObject_HEAD_INIT(&_PyContextTokenMissing_Type), \
0211 }, \
0212 }, \
0213 }, \
0214 ._main_interpreter = _PyInterpreterState_INIT(runtime._main_interpreter), \
0215 }
0216
0217 #define _PyInterpreterState_INIT(INTERP) \
0218 { \
0219 .id_refcount = -1, \
0220 ._whence = _PyInterpreterState_WHENCE_NOTSET, \
0221 .imports = IMPORTS_INIT, \
0222 .ceval = { \
0223 .recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
0224 .pending = { \
0225 .max = MAXPENDINGCALLS, \
0226 .maxloop = MAXPENDINGCALLSLOOP, \
0227 }, \
0228 }, \
0229 .gc = { \
0230 .enabled = 1, \
0231 .generations = { \
0232 \
0233 { .threshold = 2000, }, \
0234 { .threshold = 10, }, \
0235 { .threshold = 10, }, \
0236 }, \
0237 }, \
0238 .qsbr = { \
0239 .wr_seq = QSBR_INITIAL, \
0240 .rd_seq = QSBR_INITIAL, \
0241 }, \
0242 .dtoa = _dtoa_state_INIT(&(INTERP)), \
0243 .dict_state = _dict_state_INIT, \
0244 .mem_free_queue = _Py_mem_free_queue_INIT(INTERP.mem_free_queue), \
0245 .func_state = { \
0246 .next_version = 1, \
0247 }, \
0248 .types = { \
0249 .next_version_tag = _Py_TYPE_BASE_VERSION_TAG, \
0250 }, \
0251 .static_objects = { \
0252 .singletons = { \
0253 ._not_used = 1, \
0254 .hamt_empty = { \
0255 .ob_base = _PyObject_HEAD_INIT(&_PyHamt_Type), \
0256 .h_root = (PyHamtNode*)&_Py_SINGLETON(hamt_bitmap_node_empty), \
0257 }, \
0258 .last_resort_memory_error = { \
0259 _PyObject_HEAD_INIT(&_PyExc_MemoryError), \
0260 .args = (PyObject*)&_Py_SINGLETON(tuple_empty) \
0261 }, \
0262 }, \
0263 }, \
0264 ._initial_thread = _PyThreadStateImpl_INIT, \
0265 }
0266
0267 #define _PyThreadStateImpl_INIT \
0268 { \
0269 .base = _PyThreadState_INIT, \
0270 }
0271
0272 #define _PyThreadState_INIT \
0273 { \
0274 ._whence = _PyThreadState_WHENCE_NOTSET, \
0275 .py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
0276 .context_ver = 1, \
0277 }
0278
0279
0280
0281
0282 #define _PyBytes_SIMPLE_INIT(CH, LEN) \
0283 { \
0284 _PyVarObject_HEAD_INIT(&PyBytes_Type, (LEN)), \
0285 .ob_shash = -1, \
0286 .ob_sval = { (CH) }, \
0287 }
0288 #define _PyBytes_CHAR_INIT(CH) \
0289 { \
0290 _PyBytes_SIMPLE_INIT((CH), 1) \
0291 }
0292
0293 #define _PyUnicode_ASCII_BASE_INIT(LITERAL, ASCII) \
0294 { \
0295 .ob_base = _PyObject_HEAD_INIT(&PyUnicode_Type), \
0296 .length = sizeof(LITERAL) - 1, \
0297 .hash = -1, \
0298 .state = { \
0299 .kind = 1, \
0300 .compact = 1, \
0301 .ascii = (ASCII), \
0302 .statically_allocated = 1, \
0303 }, \
0304 }
0305 #define _PyASCIIObject_INIT(LITERAL) \
0306 { \
0307 ._ascii = _PyUnicode_ASCII_BASE_INIT((LITERAL), 1), \
0308 ._data = (LITERAL) \
0309 }
0310 #define INIT_STR(NAME, LITERAL) \
0311 ._py_ ## NAME = _PyASCIIObject_INIT(LITERAL)
0312 #define INIT_ID(NAME) \
0313 ._py_ ## NAME = _PyASCIIObject_INIT(#NAME)
0314 #define _PyUnicode_LATIN1_INIT(LITERAL, UTF8) \
0315 { \
0316 ._latin1 = { \
0317 ._base = _PyUnicode_ASCII_BASE_INIT((LITERAL), 0), \
0318 .utf8 = (UTF8), \
0319 .utf8_length = sizeof(UTF8) - 1, \
0320 }, \
0321 ._data = (LITERAL), \
0322 }
0323
0324 #include "pycore_runtime_init_generated.h"
0325
0326 #ifdef __cplusplus
0327 }
0328 #endif
0329 #endif