File indexing completed on 2025-01-30 10:18:09
0001 #ifndef Py_INTERNAL_RUNTIME_H
0002 #define Py_INTERNAL_RUNTIME_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_atexit.h" // struct atexit_runtime_state
0012 #include "pycore_atomic.h" /* _Py_atomic_address */
0013 #include "pycore_ceval_state.h" // struct _ceval_runtime_state
0014 #include "pycore_floatobject.h" // struct _Py_float_runtime_state
0015 #include "pycore_faulthandler.h" // struct _faulthandler_runtime_state
0016 #include "pycore_global_objects.h" // struct _Py_global_objects
0017 #include "pycore_import.h" // struct _import_runtime_state
0018 #include "pycore_interp.h" // PyInterpreterState
0019 #include "pycore_object_state.h" // struct _py_object_runtime_state
0020 #include "pycore_parser.h" // struct _parser_runtime_state
0021 #include "pycore_pymem.h" // struct _pymem_allocators
0022 #include "pycore_pyhash.h" // struct pyhash_runtime_state
0023 #include "pycore_pythread.h" // struct _pythread_runtime_state
0024 #include "pycore_signal.h" // struct _signals_runtime_state
0025 #include "pycore_time.h" // struct _time_runtime_state
0026 #include "pycore_tracemalloc.h" // struct _tracemalloc_runtime_state
0027 #include "pycore_typeobject.h" // struct types_runtime_state
0028 #include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
0029
0030 struct _getargs_runtime_state {
0031 PyThread_type_lock mutex;
0032 struct _PyArg_Parser *static_parsers;
0033 };
0034
0035
0036
0037 struct _gilstate_runtime_state {
0038
0039
0040 int check_enabled;
0041
0042
0043
0044
0045 PyInterpreterState *autoInterpreterState;
0046 };
0047
0048
0049
0050 typedef struct _Py_AuditHookEntry {
0051 struct _Py_AuditHookEntry *next;
0052 Py_AuditHookFunction hookCFunction;
0053 void *userData;
0054 } _Py_AuditHookEntry;
0055
0056
0057
0058
0059
0060
0061 typedef struct pyruntimestate {
0062
0063
0064
0065
0066 int _initialized;
0067
0068
0069 int preinitializing;
0070
0071
0072 int preinitialized;
0073
0074
0075 int core_initialized;
0076
0077
0078 int initialized;
0079
0080
0081
0082
0083
0084
0085 _Py_atomic_address _finalizing;
0086
0087 struct pyinterpreters {
0088 PyThread_type_lock mutex;
0089
0090 PyInterpreterState *head;
0091
0092
0093
0094 PyInterpreterState *main;
0095
0096
0097
0098
0099
0100
0101
0102
0103 int64_t next_id;
0104 } interpreters;
0105
0106 unsigned long main_thread;
0107
0108
0109
0110
0111
0112
0113
0114 struct _xidregistry xidregistry;
0115
0116 struct _pymem_allocators allocators;
0117 struct _obmalloc_global_state obmalloc;
0118 struct pyhash_runtime_state pyhash_state;
0119 struct _time_runtime_state time;
0120 struct _pythread_runtime_state threads;
0121 struct _signals_runtime_state signals;
0122
0123
0124 Py_tss_t autoTSSkey;
0125
0126
0127 Py_tss_t trashTSSkey;
0128
0129 PyWideStringList orig_argv;
0130
0131 struct _parser_runtime_state parser;
0132
0133 struct _atexit_runtime_state atexit;
0134
0135 struct _import_runtime_state imports;
0136 struct _ceval_runtime_state ceval;
0137 struct _gilstate_runtime_state gilstate;
0138 struct _getargs_runtime_state getargs;
0139 struct _fileutils_state fileutils;
0140 struct _faulthandler_runtime_state faulthandler;
0141 struct _tracemalloc_runtime_state tracemalloc;
0142
0143 PyPreConfig preconfig;
0144
0145
0146
0147 Py_OpenCodeHookFunction open_code_hook;
0148 void *open_code_userdata;
0149 struct {
0150 PyThread_type_lock mutex;
0151 _Py_AuditHookEntry *head;
0152 } audit_hooks;
0153
0154 struct _py_object_runtime_state object_state;
0155 struct _Py_float_runtime_state float_state;
0156 struct _Py_unicode_runtime_state unicode_state;
0157 struct _types_runtime_state types;
0158
0159
0160 struct _Py_static_objects static_objects;
0161 struct _Py_cached_objects cached_objects;
0162
0163
0164
0165 _Py_atomic_address _finalizing_id;
0166
0167
0168
0169 wchar_t *sys_path_0;
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186 PyInterpreterState _main_interpreter;
0187 } _PyRuntimeState;
0188
0189
0190
0191
0192 PyAPI_DATA(_PyRuntimeState) _PyRuntime;
0193
0194 PyAPI_FUNC(PyStatus) _PyRuntimeState_Init(_PyRuntimeState *runtime);
0195 PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *runtime);
0196
0197 #ifdef HAVE_FORK
0198 extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime);
0199 #endif
0200
0201
0202
0203 PyAPI_FUNC(PyStatus) _PyRuntime_Initialize(void);
0204
0205 PyAPI_FUNC(void) _PyRuntime_Finalize(void);
0206
0207
0208 static inline PyThreadState*
0209 _PyRuntimeState_GetFinalizing(_PyRuntimeState *runtime) {
0210 return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->_finalizing);
0211 }
0212
0213 static inline unsigned long
0214 _PyRuntimeState_GetFinalizingID(_PyRuntimeState *runtime) {
0215 return (unsigned long)_Py_atomic_load_relaxed(&runtime->_finalizing_id);
0216 }
0217
0218 static inline void
0219 _PyRuntimeState_SetFinalizing(_PyRuntimeState *runtime, PyThreadState *tstate) {
0220 _Py_atomic_store_relaxed(&runtime->_finalizing, (uintptr_t)tstate);
0221 if (tstate == NULL) {
0222 _Py_atomic_store_relaxed(&runtime->_finalizing_id, 0);
0223 }
0224 else {
0225
0226
0227 _Py_atomic_store_relaxed(&runtime->_finalizing_id,
0228 (uintptr_t)tstate->thread_id);
0229 }
0230 }
0231
0232 #ifdef __cplusplus
0233 }
0234 #endif
0235 #endif