2022-01-13 18:54:36 -04:00
|
|
|
#ifndef Py_INTERNAL_RUNTIME_INIT_H
|
|
|
|
#define Py_INTERNAL_RUNTIME_INIT_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef Py_BUILD_CORE
|
|
|
|
# error "this header requires Py_BUILD_CORE define"
|
|
|
|
#endif
|
|
|
|
|
2023-03-22 11:49:51 -03:00
|
|
|
#include "pycore_long.h"
|
2022-01-13 18:54:36 -04:00
|
|
|
#include "pycore_object.h"
|
2022-12-16 09:48:03 -04:00
|
|
|
#include "pycore_parser.h"
|
2022-11-11 19:30:46 -04:00
|
|
|
#include "pycore_pymem_init.h"
|
|
|
|
#include "pycore_obmalloc_init.h"
|
2022-01-13 18:54:36 -04:00
|
|
|
|
|
|
|
|
2023-03-06 22:40:09 -04:00
|
|
|
extern PyTypeObject _PyExc_MemoryError;
|
|
|
|
|
|
|
|
|
2022-01-13 18:54:36 -04:00
|
|
|
/* The static initializers defined here should only be used
|
|
|
|
in the runtime init code (in pystate.c and pylifecycle.c). */
|
|
|
|
|
2022-11-11 19:30:46 -04:00
|
|
|
#define _PyRuntimeState_INIT(runtime) \
|
2022-01-13 18:54:36 -04:00
|
|
|
{ \
|
2023-07-11 16:35:41 -03:00
|
|
|
.debug_offsets = { \
|
|
|
|
.cookie = "xdebugpy", \
|
|
|
|
.version = PY_VERSION_HEX, \
|
|
|
|
.runtime_state = { \
|
|
|
|
.finalizing = offsetof(_PyRuntimeState, _finalizing), \
|
|
|
|
.interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \
|
|
|
|
}, \
|
|
|
|
.interpreter_state = { \
|
|
|
|
.next = offsetof(PyInterpreterState, next), \
|
|
|
|
.threads_head = offsetof(PyInterpreterState, threads.head), \
|
|
|
|
.gc = offsetof(PyInterpreterState, gc), \
|
|
|
|
.imports_modules = offsetof(PyInterpreterState, imports.modules), \
|
|
|
|
.sysdict = offsetof(PyInterpreterState, sysdict), \
|
|
|
|
.builtins = offsetof(PyInterpreterState, builtins), \
|
|
|
|
.ceval_gil = offsetof(PyInterpreterState, ceval.gil), \
|
|
|
|
.gil_runtime_state_locked = offsetof(PyInterpreterState, _gil.locked), \
|
|
|
|
.gil_runtime_state_holder = offsetof(PyInterpreterState, _gil.last_holder), \
|
|
|
|
}, \
|
|
|
|
.thread_state = { \
|
|
|
|
.prev = offsetof(PyThreadState, prev), \
|
|
|
|
.next = offsetof(PyThreadState, next), \
|
|
|
|
.interp = offsetof(PyThreadState, interp), \
|
|
|
|
.cframe = offsetof(PyThreadState, cframe), \
|
|
|
|
.thread_id = offsetof(PyThreadState, thread_id), \
|
|
|
|
.native_thread_id = offsetof(PyThreadState, native_thread_id), \
|
|
|
|
}, \
|
|
|
|
.interpreter_frame = { \
|
|
|
|
.previous = offsetof(_PyInterpreterFrame, previous), \
|
|
|
|
.executable = offsetof(_PyInterpreterFrame, f_executable), \
|
|
|
|
.prev_instr = offsetof(_PyInterpreterFrame, prev_instr), \
|
|
|
|
.localsplus = offsetof(_PyInterpreterFrame, localsplus), \
|
|
|
|
.owner = offsetof(_PyInterpreterFrame, owner), \
|
|
|
|
}, \
|
|
|
|
.cframe = { \
|
|
|
|
.current_frame = offsetof(_PyCFrame, current_frame), \
|
|
|
|
.previous = offsetof(_PyCFrame, previous), \
|
|
|
|
}, \
|
|
|
|
.code_object = { \
|
|
|
|
.filename = offsetof(PyCodeObject, co_filename), \
|
|
|
|
.name = offsetof(PyCodeObject, co_name), \
|
|
|
|
.linetable = offsetof(PyCodeObject, co_linetable), \
|
|
|
|
.firstlineno = offsetof(PyCodeObject, co_firstlineno), \
|
|
|
|
.argcount = offsetof(PyCodeObject, co_argcount), \
|
|
|
|
.localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \
|
|
|
|
.localspluskinds = offsetof(PyCodeObject, co_localspluskinds), \
|
|
|
|
.co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \
|
|
|
|
}, \
|
|
|
|
.pyobject = { \
|
|
|
|
.ob_type = offsetof(PyObject, ob_type), \
|
|
|
|
}, \
|
|
|
|
.type_object = { \
|
|
|
|
.tp_name = offsetof(PyTypeObject, tp_name), \
|
|
|
|
}, \
|
|
|
|
.tuple_object = { \
|
|
|
|
.ob_item = offsetof(PyTupleObject, ob_item), \
|
|
|
|
}, \
|
|
|
|
}, \
|
2022-11-11 19:30:46 -04:00
|
|
|
.allocators = { \
|
2023-06-08 17:06:54 -03:00
|
|
|
.standard = _pymem_allocators_standard_INIT(runtime), \
|
|
|
|
.debug = _pymem_allocators_debug_INIT, \
|
|
|
|
.obj_arena = _pymem_allocators_obj_arena_INIT, \
|
2022-11-11 19:30:46 -04:00
|
|
|
}, \
|
2023-04-24 20:23:57 -03:00
|
|
|
.obmalloc = _obmalloc_global_state_INIT, \
|
2022-11-16 12:37:14 -04:00
|
|
|
.pyhash_state = pyhash_state_INIT, \
|
2022-12-12 19:50:19 -04:00
|
|
|
.signals = _signals_RUNTIME_INIT, \
|
2022-01-13 19:33:40 -04:00
|
|
|
.interpreters = { \
|
|
|
|
/* This prevents interpreters from getting created \
|
|
|
|
until _PyInterpreterState_Enable() is called. */ \
|
|
|
|
.next_id = -1, \
|
|
|
|
}, \
|
2023-01-19 19:04:14 -04:00
|
|
|
/* A TSS key must be initialized with Py_tss_NEEDS_INIT \
|
|
|
|
in accordance with the specification. */ \
|
|
|
|
.autoTSSkey = Py_tss_NEEDS_INIT, \
|
2022-12-16 09:48:03 -04:00
|
|
|
.parser = _parser_runtime_state_INIT, \
|
2023-03-29 20:15:43 -03:00
|
|
|
.imports = { \
|
|
|
|
.extensions = { \
|
|
|
|
.main_tstate = _PyThreadState_INIT, \
|
|
|
|
}, \
|
|
|
|
}, \
|
2022-12-08 20:17:20 -04:00
|
|
|
.ceval = { \
|
|
|
|
.perf = _PyEval_RUNTIME_PERF_INIT, \
|
|
|
|
}, \
|
2022-11-16 12:37:14 -04:00
|
|
|
.gilstate = { \
|
|
|
|
.check_enabled = 1, \
|
|
|
|
}, \
|
|
|
|
.fileutils = { \
|
|
|
|
.force_ascii = -1, \
|
|
|
|
}, \
|
2022-12-12 12:58:46 -04:00
|
|
|
.faulthandler = _faulthandler_runtime_state_INIT, \
|
2022-12-12 11:44:23 -04:00
|
|
|
.tracemalloc = _tracemalloc_runtime_state_INIT, \
|
2022-11-16 12:37:14 -04:00
|
|
|
.float_state = { \
|
|
|
|
.float_format = _py_float_format_unknown, \
|
|
|
|
.double_format = _py_float_format_unknown, \
|
|
|
|
}, \
|
|
|
|
.types = { \
|
|
|
|
.next_version_tag = 1, \
|
|
|
|
}, \
|
2022-12-14 14:53:57 -04:00
|
|
|
.static_objects = { \
|
2022-11-11 16:23:41 -04:00
|
|
|
.singletons = { \
|
|
|
|
.small_ints = _Py_small_ints_INIT, \
|
|
|
|
.bytes_empty = _PyBytes_SIMPLE_INIT(0, 0), \
|
|
|
|
.bytes_characters = _Py_bytes_characters_INIT, \
|
|
|
|
.strings = { \
|
|
|
|
.literals = _Py_str_literals_INIT, \
|
|
|
|
.identifiers = _Py_str_identifiers_INIT, \
|
|
|
|
.ascii = _Py_str_ascii_INIT, \
|
|
|
|
.latin1 = _Py_str_latin1_INIT, \
|
|
|
|
}, \
|
|
|
|
.tuple_empty = { \
|
2023-04-22 16:39:37 -03:00
|
|
|
.ob_base = _PyVarObject_HEAD_INIT(&PyTuple_Type, 0) \
|
2022-11-11 16:23:41 -04:00
|
|
|
}, \
|
2022-11-16 12:54:28 -04:00
|
|
|
.hamt_bitmap_node_empty = { \
|
2023-04-22 16:39:37 -03:00
|
|
|
.ob_base = _PyVarObject_HEAD_INIT(&_PyHamt_BitmapNode_Type, 0) \
|
2022-11-16 12:54:28 -04:00
|
|
|
}, \
|
|
|
|
.context_token_missing = { \
|
2023-04-22 16:39:37 -03:00
|
|
|
.ob_base = _PyObject_HEAD_INIT(&_PyContextTokenMissing_Type) \
|
2022-11-16 12:54:28 -04:00
|
|
|
}, \
|
2022-11-11 16:23:41 -04:00
|
|
|
}, \
|
|
|
|
}, \
|
2023-02-28 16:14:40 -04:00
|
|
|
._main_interpreter = _PyInterpreterState_INIT(runtime._main_interpreter), \
|
2022-01-13 18:54:36 -04:00
|
|
|
}
|
|
|
|
|
2023-02-28 16:14:40 -04:00
|
|
|
#define _PyInterpreterState_INIT(INTERP) \
|
2022-01-13 18:54:36 -04:00
|
|
|
{ \
|
2022-01-13 20:17:28 -04:00
|
|
|
.id_refcount = -1, \
|
2023-02-15 18:32:31 -04:00
|
|
|
.imports = IMPORTS_INIT, \
|
2023-04-24 20:23:57 -03:00
|
|
|
.obmalloc = _obmalloc_state_INIT(INTERP.obmalloc), \
|
2022-01-13 20:17:28 -04:00
|
|
|
.ceval = { \
|
|
|
|
.recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
|
|
|
|
}, \
|
|
|
|
.gc = { \
|
|
|
|
.enabled = 1, \
|
|
|
|
.generations = { \
|
|
|
|
/* .head is set in _PyGC_InitState(). */ \
|
|
|
|
{ .threshold = 700, }, \
|
|
|
|
{ .threshold = 10, }, \
|
|
|
|
{ .threshold = 10, }, \
|
|
|
|
}, \
|
|
|
|
}, \
|
2023-02-28 16:14:40 -04:00
|
|
|
.dtoa = _dtoa_state_INIT(&(INTERP)), \
|
2023-05-10 10:28:40 -03:00
|
|
|
.dict_state = _dict_state_INIT, \
|
2023-03-08 18:56:36 -04:00
|
|
|
.func_state = { \
|
|
|
|
.next_version = 1, \
|
|
|
|
}, \
|
2023-04-24 19:30:13 -03:00
|
|
|
.types = { \
|
|
|
|
.next_version_tag = _Py_TYPE_BASE_VERSION_TAG, \
|
|
|
|
}, \
|
2022-11-11 17:24:18 -04:00
|
|
|
.static_objects = { \
|
|
|
|
.singletons = { \
|
|
|
|
._not_used = 1, \
|
2022-11-16 12:54:28 -04:00
|
|
|
.hamt_empty = { \
|
2023-04-22 16:39:37 -03:00
|
|
|
.ob_base = _PyObject_HEAD_INIT(&_PyHamt_Type) \
|
2022-11-16 12:54:28 -04:00
|
|
|
.h_root = (PyHamtNode*)&_Py_SINGLETON(hamt_bitmap_node_empty), \
|
|
|
|
}, \
|
2023-03-06 22:40:09 -04:00
|
|
|
.last_resort_memory_error = { \
|
2023-04-22 16:39:37 -03:00
|
|
|
_PyObject_HEAD_INIT(&_PyExc_MemoryError) \
|
2023-03-06 22:40:09 -04:00
|
|
|
}, \
|
2022-11-11 17:24:18 -04:00
|
|
|
}, \
|
|
|
|
}, \
|
2022-01-13 18:54:36 -04:00
|
|
|
._initial_thread = _PyThreadState_INIT, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _PyThreadState_INIT \
|
|
|
|
{ \
|
2022-10-04 21:34:03 -03:00
|
|
|
.py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
|
2022-01-13 20:09:24 -04:00
|
|
|
.context_ver = 1, \
|
2022-01-13 18:54:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// global objects
|
|
|
|
|
|
|
|
#define _PyBytes_SIMPLE_INIT(CH, LEN) \
|
|
|
|
{ \
|
2023-04-22 16:39:37 -03:00
|
|
|
_PyVarObject_HEAD_INIT(&PyBytes_Type, (LEN)) \
|
2022-01-13 18:54:36 -04:00
|
|
|
.ob_shash = -1, \
|
2022-06-20 11:04:52 -03:00
|
|
|
.ob_sval = { (CH) }, \
|
2022-01-13 18:54:36 -04:00
|
|
|
}
|
|
|
|
#define _PyBytes_CHAR_INIT(CH) \
|
|
|
|
{ \
|
2022-06-20 11:04:52 -03:00
|
|
|
_PyBytes_SIMPLE_INIT((CH), 1) \
|
2022-01-13 18:54:36 -04:00
|
|
|
}
|
|
|
|
|
2022-03-09 19:02:00 -04:00
|
|
|
#define _PyUnicode_ASCII_BASE_INIT(LITERAL, ASCII) \
|
2022-02-08 16:39:07 -04:00
|
|
|
{ \
|
2023-04-22 16:39:37 -03:00
|
|
|
.ob_base = _PyObject_HEAD_INIT(&PyUnicode_Type) \
|
2022-03-09 19:02:00 -04:00
|
|
|
.length = sizeof(LITERAL) - 1, \
|
|
|
|
.hash = -1, \
|
|
|
|
.state = { \
|
|
|
|
.kind = 1, \
|
|
|
|
.compact = 1, \
|
2022-06-20 11:04:52 -03:00
|
|
|
.ascii = (ASCII), \
|
2022-02-08 16:39:07 -04:00
|
|
|
}, \
|
2022-03-09 19:02:00 -04:00
|
|
|
}
|
|
|
|
#define _PyASCIIObject_INIT(LITERAL) \
|
|
|
|
{ \
|
2022-06-20 11:04:52 -03:00
|
|
|
._ascii = _PyUnicode_ASCII_BASE_INIT((LITERAL), 1), \
|
|
|
|
._data = (LITERAL) \
|
2022-02-08 16:39:07 -04:00
|
|
|
}
|
|
|
|
#define INIT_STR(NAME, LITERAL) \
|
2022-11-07 16:06:23 -04:00
|
|
|
._py_ ## NAME = _PyASCIIObject_INIT(LITERAL)
|
2022-02-08 16:39:07 -04:00
|
|
|
#define INIT_ID(NAME) \
|
2022-11-07 16:06:23 -04:00
|
|
|
._py_ ## NAME = _PyASCIIObject_INIT(#NAME)
|
2022-09-03 03:43:08 -03:00
|
|
|
#define _PyUnicode_LATIN1_INIT(LITERAL, UTF8) \
|
2022-03-09 19:02:00 -04:00
|
|
|
{ \
|
|
|
|
._latin1 = { \
|
2022-06-20 11:04:52 -03:00
|
|
|
._base = _PyUnicode_ASCII_BASE_INIT((LITERAL), 0), \
|
2022-09-03 03:43:08 -03:00
|
|
|
.utf8 = (UTF8), \
|
|
|
|
.utf8_length = sizeof(UTF8) - 1, \
|
2022-03-09 19:02:00 -04:00
|
|
|
}, \
|
2022-06-20 11:04:52 -03:00
|
|
|
._data = (LITERAL), \
|
2022-03-09 19:02:00 -04:00
|
|
|
}
|
2022-01-27 14:06:09 -04:00
|
|
|
|
2022-07-07 17:04:05 -03:00
|
|
|
#include "pycore_runtime_init_generated.h"
|
2022-01-13 18:54:36 -04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_INTERNAL_RUNTIME_INIT_H */
|