File indexing completed on 2025-03-13 09:21:01
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_long.h"
0012 #include "pycore_object.h"
0013 #include "pycore_parser.h"
0014 #include "pycore_pymem_init.h"
0015 #include "pycore_obmalloc_init.h"
0016
0017
0018 extern PyTypeObject _PyExc_MemoryError;
0019
0020
0021
0022
0023
0024
0025 #define _PyRuntimeState_INIT(runtime) \
0026 { \
0027 .allocators = { \
0028 .standard = _pymem_allocators_standard_INIT(runtime), \
0029 .debug = _pymem_allocators_debug_INIT, \
0030 .obj_arena = _pymem_allocators_obj_arena_INIT, \
0031 }, \
0032 .obmalloc = _obmalloc_global_state_INIT, \
0033 .pyhash_state = pyhash_state_INIT, \
0034 .signals = _signals_RUNTIME_INIT, \
0035 .interpreters = { \
0036
0037 \
0038 .next_id = -1, \
0039 }, \
0040
0041 \
0042 .autoTSSkey = Py_tss_NEEDS_INIT, \
0043 .parser = _parser_runtime_state_INIT, \
0044 .ceval = { \
0045 .perf = _PyEval_RUNTIME_PERF_INIT, \
0046 }, \
0047 .gilstate = { \
0048 .check_enabled = 1, \
0049 }, \
0050 .fileutils = { \
0051 .force_ascii = -1, \
0052 }, \
0053 .faulthandler = _faulthandler_runtime_state_INIT, \
0054 .tracemalloc = _tracemalloc_runtime_state_INIT, \
0055 .float_state = { \
0056 .float_format = _py_float_format_unknown, \
0057 .double_format = _py_float_format_unknown, \
0058 }, \
0059 .types = { \
0060 .next_version_tag = 1, \
0061 }, \
0062 .static_objects = { \
0063 .singletons = { \
0064 .small_ints = _Py_small_ints_INIT, \
0065 .bytes_empty = _PyBytes_SIMPLE_INIT(0, 0), \
0066 .bytes_characters = _Py_bytes_characters_INIT, \
0067 .strings = { \
0068 .literals = _Py_str_literals_INIT, \
0069 .identifiers = _Py_str_identifiers_INIT, \
0070 .ascii = _Py_str_ascii_INIT, \
0071 .latin1 = _Py_str_latin1_INIT, \
0072 }, \
0073 .tuple_empty = { \
0074 .ob_base = _PyVarObject_HEAD_INIT(&PyTuple_Type, 0) \
0075 }, \
0076 .hamt_bitmap_node_empty = { \
0077 .ob_base = _PyVarObject_HEAD_INIT(&_PyHamt_BitmapNode_Type, 0) \
0078 }, \
0079 .context_token_missing = { \
0080 .ob_base = _PyObject_HEAD_INIT(&_PyContextTokenMissing_Type) \
0081 }, \
0082 }, \
0083 }, \
0084 ._main_interpreter = _PyInterpreterState_INIT(runtime._main_interpreter), \
0085 }
0086
0087 #define _PyInterpreterState_INIT(INTERP) \
0088 { \
0089 .id_refcount = -1, \
0090 .imports = IMPORTS_INIT, \
0091 .obmalloc = _obmalloc_state_INIT(INTERP.obmalloc), \
0092 .ceval = { \
0093 .recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
0094 }, \
0095 .gc = { \
0096 .enabled = 1, \
0097 .generations = { \
0098 \
0099 { .threshold = 700, }, \
0100 { .threshold = 10, }, \
0101 { .threshold = 10, }, \
0102 }, \
0103 }, \
0104 .object_state = _py_object_state_INIT(INTERP), \
0105 .dtoa = _dtoa_state_INIT(&(INTERP)), \
0106 .dict_state = _dict_state_INIT, \
0107 .func_state = { \
0108 .next_version = 1, \
0109 }, \
0110 .types = { \
0111 .next_version_tag = _Py_TYPE_BASE_VERSION_TAG, \
0112 }, \
0113 .static_objects = { \
0114 .singletons = { \
0115 ._not_used = 1, \
0116 .hamt_empty = { \
0117 .ob_base = _PyObject_HEAD_INIT(&_PyHamt_Type) \
0118 .h_root = (PyHamtNode*)&_Py_SINGLETON(hamt_bitmap_node_empty), \
0119 }, \
0120 .last_resort_memory_error = { \
0121 _PyObject_HEAD_INIT(&_PyExc_MemoryError) \
0122 .args = (PyObject*)&_Py_SINGLETON(tuple_empty) \
0123 }, \
0124 }, \
0125 }, \
0126 ._initial_thread = _PyThreadState_INIT, \
0127 }
0128
0129 #define _PyThreadState_INIT \
0130 { \
0131 .py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
0132 .context_ver = 1, \
0133 }
0134
0135 #ifdef Py_TRACE_REFS
0136 # define _py_object_state_INIT(INTERP) \
0137 { \
0138 .refchain = {&INTERP.object_state.refchain, &INTERP.object_state.refchain}, \
0139 }
0140 #else
0141 # define _py_object_state_INIT(INTERP) \
0142 { 0 }
0143 #endif
0144
0145
0146
0147
0148 #define _PyBytes_SIMPLE_INIT(CH, LEN) \
0149 { \
0150 _PyVarObject_HEAD_INIT(&PyBytes_Type, (LEN)) \
0151 .ob_shash = -1, \
0152 .ob_sval = { (CH) }, \
0153 }
0154 #define _PyBytes_CHAR_INIT(CH) \
0155 { \
0156 _PyBytes_SIMPLE_INIT((CH), 1) \
0157 }
0158
0159 #define _PyUnicode_ASCII_BASE_INIT(LITERAL, ASCII) \
0160 { \
0161 .ob_base = _PyObject_HEAD_INIT(&PyUnicode_Type) \
0162 .length = sizeof(LITERAL) - 1, \
0163 .hash = -1, \
0164 .state = { \
0165 .kind = 1, \
0166 .compact = 1, \
0167 .ascii = (ASCII), \
0168 .statically_allocated = 1, \
0169 }, \
0170 }
0171 #define _PyASCIIObject_INIT(LITERAL) \
0172 { \
0173 ._ascii = _PyUnicode_ASCII_BASE_INIT((LITERAL), 1), \
0174 ._data = (LITERAL) \
0175 }
0176 #define INIT_STR(NAME, LITERAL) \
0177 ._py_ ## NAME = _PyASCIIObject_INIT(LITERAL)
0178 #define INIT_ID(NAME) \
0179 ._py_ ## NAME = _PyASCIIObject_INIT(#NAME)
0180 #define _PyUnicode_LATIN1_INIT(LITERAL, UTF8) \
0181 { \
0182 ._latin1 = { \
0183 ._base = _PyUnicode_ASCII_BASE_INIT((LITERAL), 0), \
0184 .utf8 = (UTF8), \
0185 .utf8_length = sizeof(UTF8) - 1, \
0186 }, \
0187 ._data = (LITERAL), \
0188 }
0189
0190 #include "pycore_runtime_init_generated.h"
0191
0192 #ifdef __cplusplus
0193 }
0194 #endif
0195 #endif