Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/python3.12/internal/pycore_runtime.h
$ cat -n /usr/include/python3.12/internal/pycore_runtime.h 1 #ifndef Py_INTERNAL_RUNTIME_H 2 #define Py_INTERNAL_RUNTIME_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_atexit.h" // struct atexit_runtime_state 12 #include "pycore_atomic.h" /* _Py_atomic_address */ 13 #include "pycore_ceval_state.h" // struct _ceval_runtime_state 14 #include "pycore_floatobject.h" // struct _Py_float_runtime_state 15 #include "pycore_faulthandler.h" // struct _faulthandler_runtime_state 16 #include "pycore_global_objects.h" // struct _Py_global_objects 17 #include "pycore_import.h" // struct _import_runtime_state 18 #include "pycore_interp.h" // PyInterpreterState 19 #include "pycore_object_state.h" // struct _py_object_runtime_state 20 #include "pycore_parser.h" // struct _parser_runtime_state 21 #include "pycore_pymem.h" // struct _pymem_allocators 22 #include "pycore_pyhash.h" // struct pyhash_runtime_state 23 #include "pycore_pythread.h" // struct _pythread_runtime_state 24 #include "pycore_signal.h" // struct _signals_runtime_state 25 #include "pycore_time.h" // struct _time_runtime_state 26 #include "pycore_tracemalloc.h" // struct _tracemalloc_runtime_state 27 #include "pycore_typeobject.h" // struct types_runtime_state 28 #include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids 29 30 struct _getargs_runtime_state { 31 PyThread_type_lock mutex; 32 struct _PyArg_Parser *static_parsers; 33 }; 34 35 /* GIL state */ 36 37 struct _gilstate_runtime_state { 38 /* bpo-26558: Flag to disable PyGILState_Check(). 39 If set to non-zero, PyGILState_Check() always return 1. */ 40 int check_enabled; 41 /* The single PyInterpreterState used by this process' 42 GILState implementation 43 */ 44 /* TODO: Given interp_main, it may be possible to kill this ref */ 45 PyInterpreterState *autoInterpreterState; 46 }; 47 48 /* Runtime audit hook state */ 49 50 typedef struct _Py_AuditHookEntry { 51 struct _Py_AuditHookEntry *next; 52 Py_AuditHookFunction hookCFunction; 53 void *userData; 54 } _Py_AuditHookEntry; 55 56 /* Full Python runtime state */ 57 58 /* _PyRuntimeState holds the global state for the CPython runtime. 59 That data is exposed in the internal API as a static variable (_PyRuntime). 60 */ 61 typedef struct pyruntimestate { 62 /* Has been initialized to a safe state. 63 64 In order to be effective, this must be set to 0 during or right 65 after allocation. */ 66 int _initialized; 67 68 /* Is running Py_PreInitialize()? */ 69 int preinitializing; 70 71 /* Is Python preinitialized? Set to 1 by Py_PreInitialize() */ 72 int preinitialized; 73 74 /* Is Python core initialized? Set to 1 by _Py_InitializeCore() */ 75 int core_initialized; 76 77 /* Is Python fully initialized? Set to 1 by Py_Initialize() */ 78 int initialized; 79 80 /* Set by Py_FinalizeEx(). Only reset to NULL if Py_Initialize() 81 is called again. 82 83 Use _PyRuntimeState_GetFinalizing() and _PyRuntimeState_SetFinalizing() 84 to access it, don't access it directly. */ 85 _Py_atomic_address _finalizing; 86 87 struct pyinterpreters { 88 PyThread_type_lock mutex; 89 /* The linked list of interpreters, newest first. */ 90 PyInterpreterState *head; 91 /* The runtime's initial interpreter, which has a special role 92 in the operation of the runtime. It is also often the only 93 interpreter. */ 94 PyInterpreterState *main; 95 /* next_id is an auto-numbered sequence of small 96 integers. It gets initialized in _PyInterpreterState_Enable(), 97 which is called in Py_Initialize(), and used in 98 PyInterpreterState_New(). A negative interpreter ID 99 indicates an error occurred. The main interpreter will 100 always have an ID of 0. Overflow results in a RuntimeError. 101 If that becomes a problem later then we can adjust, e.g. by 102 using a Python int. */ 103 int64_t next_id; 104 } interpreters; 105 106 unsigned long main_thread; 107 108 /* ---------- IMPORTANT --------------------------- 109 The fields above this line are declared as early as 110 possible to facilitate out-of-process observability 111 tools. */ 112 113 // XXX Remove this field once we have a tp_* slot. 114 struct _xidregistry xidregistry; 115 116 struct _pymem_allocators allocators; 117 struct _obmalloc_global_state obmalloc; 118 struct pyhash_runtime_state pyhash_state; 119 struct _time_runtime_state time; 120 struct _pythread_runtime_state threads; 121 struct _signals_runtime_state signals; 122 123 /* Used for the thread state bound to the current thread. */ 124 Py_tss_t autoTSSkey; 125 126 /* Used instead of PyThreadState.trash when there is not current tstate. */ 127 Py_tss_t trashTSSkey; 128 129 PyWideStringList orig_argv; 130 131 struct _parser_runtime_state parser; 132 133 struct _atexit_runtime_state atexit; 134 135 struct _import_runtime_state imports; 136 struct _ceval_runtime_state ceval; 137 struct _gilstate_runtime_state gilstate; 138 struct _getargs_runtime_state getargs; 139 struct _fileutils_state fileutils; 140 struct _faulthandler_runtime_state faulthandler; 141 struct _tracemalloc_runtime_state tracemalloc; 142 143 PyPreConfig preconfig; 144 145 // Audit values must be preserved when Py_Initialize()/Py_Finalize() 146 // is called multiple times. 147 Py_OpenCodeHookFunction open_code_hook; 148 void *open_code_userdata; 149 struct { 150 PyThread_type_lock mutex; 151 _Py_AuditHookEntry *head; 152 } audit_hooks; 153 154 struct _py_object_runtime_state object_state; 155 struct _Py_float_runtime_state float_state; 156 struct _Py_unicode_runtime_state unicode_state; 157 struct _types_runtime_state types; 158 159 /* All the objects that are shared by the runtime's interpreters. */ 160 struct _Py_static_objects static_objects; 161 struct _Py_cached_objects cached_objects; 162 163 /* The ID of the OS thread in which we are finalizing. 164 We use _Py_atomic_address instead of adding a new _Py_atomic_ulong. */ 165 _Py_atomic_address _finalizing_id; 166 /* The value to use for sys.path[0] in new subinterpreters. 167 Normally this would be part of the PyConfig struct. However, 168 we cannot add it there in 3.12 since that's an ABI change. */ 169 wchar_t *sys_path_0; 170 171 /* The following fields are here to avoid allocation during init. 172 The data is exposed through _PyRuntimeState pointer fields. 173 These fields should not be accessed directly outside of init. 174 175 All other _PyRuntimeState pointer fields are populated when 176 needed and default to NULL. 177 178 For now there are some exceptions to that rule, which require 179 allocation during init. These will be addressed on a case-by-case 180 basis. Most notably, we don't pre-allocated the several mutex 181 (PyThread_type_lock) fields, because on Windows we only ever get 182 a pointer type. 183 */ 184 185 /* PyInterpreterState.interpreters.main */ 186 PyInterpreterState _main_interpreter; 187 } _PyRuntimeState; 188 189 190 /* other API */ 191 192 PyAPI_DATA(_PyRuntimeState) _PyRuntime; 193 194 PyAPI_FUNC(PyStatus) _PyRuntimeState_Init(_PyRuntimeState *runtime); 195 PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *runtime); 196 197 #ifdef HAVE_FORK 198 extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime); 199 #endif 200 201 /* Initialize _PyRuntimeState. 202 Return NULL on success, or return an error message on failure. */ 203 PyAPI_FUNC(PyStatus) _PyRuntime_Initialize(void); 204 205 PyAPI_FUNC(void) _PyRuntime_Finalize(void); 206 207 208 static inline PyThreadState* 209 _PyRuntimeState_GetFinalizing(_PyRuntimeState *runtime) { 210 return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->_finalizing); 211 } 212 213 static inline unsigned long 214 _PyRuntimeState_GetFinalizingID(_PyRuntimeState *runtime) { 215 return (unsigned long)_Py_atomic_load_relaxed(&runtime->_finalizing_id); 216 } 217 218 static inline void 219 _PyRuntimeState_SetFinalizing(_PyRuntimeState *runtime, PyThreadState *tstate) { 220 _Py_atomic_store_relaxed(&runtime->_finalizing, (uintptr_t)tstate); 221 if (tstate == NULL) { 222 _Py_atomic_store_relaxed(&runtime->_finalizing_id, 0); 223 } 224 else { 225 // XXX Re-enable this assert once gh-109860 is fixed. 226 //assert(tstate->thread_id == PyThread_get_thread_ident()); 227 _Py_atomic_store_relaxed(&runtime->_finalizing_id, 228 (uintptr_t)tstate->thread_id); 229 } 230 } 231 232 #ifdef __cplusplus 233 } 234 #endif 235 #endif /* !Py_INTERNAL_RUNTIME_H */
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™