Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/python3.12/internal/pycore_interp.h
$ cat -n /usr/include/python3.12/internal/pycore_interp.h 1 #ifndef Py_INTERNAL_INTERP_H 2 #define Py_INTERNAL_INTERP_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
12 13 #include "pycore_ast_state.h" // struct ast_state 14 #include "pycore_atexit.h" // struct atexit_state 15 #include "pycore_atomic.h" // _Py_atomic_address 16 #include "pycore_ceval_state.h" // struct _ceval_state 17 #include "pycore_code.h" // struct callable_cache 18 #include "pycore_context.h" // struct _Py_context_state 19 #include "pycore_dict_state.h" // struct _Py_dict_state 20 #include "pycore_dtoa.h" // struct _dtoa_state 21 #include "pycore_exceptions.h" // struct _Py_exc_state 22 #include "pycore_floatobject.h" // struct _Py_float_state 23 #include "pycore_function.h" // FUNC_MAX_WATCHERS 24 #include "pycore_genobject.h" // struct _Py_async_gen_state 25 #include "pycore_gc.h" // struct _gc_runtime_state 26 #include "pycore_global_objects.h" // struct _Py_interp_static_objects 27 #include "pycore_import.h" // struct _import_state 28 #include "pycore_instruments.h" // _PY_MONITORING_EVENTS 29 #include "pycore_list.h" // struct _Py_list_state 30 #include "pycore_object_state.h" // struct _py_object_state 31 #include "pycore_obmalloc.h" // struct obmalloc_state 32 #include "pycore_tuple.h" // struct _Py_tuple_state 33 #include "pycore_typeobject.h" // struct type_cache 34 #include "pycore_unicodeobject.h" // struct _Py_unicode_state 35 #include "pycore_warnings.h" // struct _warnings_runtime_state 36 37 38 struct _Py_long_state { 39 int max_str_digits; 40 }; 41 42 43 /* cross-interpreter data registry */ 44 45 /* For now we use a global registry of shareable classes. An 46 alternative would be to add a tp_* slot for a class's 47 crossinterpdatafunc. It would be simpler and more efficient. */ 48 49 struct _xidregitem; 50 51 struct _xidregitem { 52 struct _xidregitem *prev; 53 struct _xidregitem *next; 54 /* This can be a dangling pointer, but only if weakref is set. */ 55 PyTypeObject *cls; 56 /* This is NULL for builtin types. */ 57 PyObject *weakref; 58 size_t refcount; 59 crossinterpdatafunc getdata; 60 }; 61 62 struct _xidregistry { 63 PyThread_type_lock mutex; 64 struct _xidregitem *head; 65 }; 66 67 68 /* interpreter state */ 69 70 /* PyInterpreterState holds the global state for one of the runtime's 71 interpreters. Typically the initial (main) interpreter is the only one. 72 73 The PyInterpreterState typedef is in Include/pytypedefs.h. 74 */ 75 struct _is { 76 77 PyInterpreterState *next; 78 79 int64_t id; 80 int64_t id_refcount; 81 int requires_idref; 82 PyThread_type_lock id_mutex; 83 84 /* Has been initialized to a safe state. 85 86 In order to be effective, this must be set to 0 during or right 87 after allocation. */ 88 int _initialized; 89 int finalizing; 90 91 uint64_t monitoring_version; 92 uint64_t last_restart_version; 93 struct pythreads { 94 uint64_t next_unique_id; 95 /* The linked list of threads, newest first. */ 96 PyThreadState *head; 97 /* Used in Modules/_threadmodule.c. */ 98 long count; 99 /* Support for runtime thread stack size tuning. 100 A value of 0 means using the platform's default stack size 101 or the size specified by the THREAD_STACK_SIZE macro. */ 102 /* Used in Python/thread.c. */ 103 size_t stacksize; 104 } threads; 105 106 /* Reference to the _PyRuntime global variable. This field exists 107 to not have to pass runtime in addition to tstate to a function. 108 Get runtime from tstate: tstate->interp->runtime. */ 109 struct pyruntimestate *runtime; 110 111 /* Set by Py_EndInterpreter(). 112 113 Use _PyInterpreterState_GetFinalizing() 114 and _PyInterpreterState_SetFinalizing() 115 to access it, don't access it directly. */ 116 _Py_atomic_address _finalizing; 117 118 struct _gc_runtime_state gc; 119 120 /* The following fields are here to avoid allocation during init. 121 The data is exposed through PyInterpreterState pointer fields. 122 These fields should not be accessed directly outside of init. 123 124 All other PyInterpreterState pointer fields are populated when 125 needed and default to NULL. 126 127 For now there are some exceptions to that rule, which require 128 allocation during init. These will be addressed on a case-by-case 129 basis. Also see _PyRuntimeState regarding the various mutex fields. 130 */ 131 132 // Dictionary of the sys module 133 PyObject *sysdict; 134 135 // Dictionary of the builtins module 136 PyObject *builtins; 137 138 struct _ceval_state ceval; 139 140 struct _import_state imports; 141 142 /* The per-interpreter GIL, which might not be used. */ 143 struct _gil_runtime_state _gil; 144 145 /* ---------- IMPORTANT --------------------------- 146 The fields above this line are declared as early as 147 possible to facilitate out-of-process observability 148 tools. */ 149 150 PyObject *codec_search_path; 151 PyObject *codec_search_cache; 152 PyObject *codec_error_registry; 153 int codecs_initialized; 154 155 PyConfig config; 156 unsigned long feature_flags; 157 158 PyObject *dict; /* Stores per-interpreter state */ 159 160 PyObject *sysdict_copy; 161 PyObject *builtins_copy; 162 // Initialized to _PyEval_EvalFrameDefault(). 163 _PyFrameEvalFunction eval_frame; 164 165 PyFunction_WatchCallback func_watchers[FUNC_MAX_WATCHERS]; 166 // One bit is set for each non-NULL entry in func_watchers 167 uint8_t active_func_watchers; 168 169 Py_ssize_t co_extra_user_count; 170 freefunc co_extra_freefuncs[MAX_CO_EXTRA_USERS]; 171 172 #ifdef HAVE_FORK 173 PyObject *before_forkers; 174 PyObject *after_forkers_parent; 175 PyObject *after_forkers_child; 176 #endif 177 178 struct _warnings_runtime_state warnings; 179 struct atexit_state atexit; 180 181 struct _obmalloc_state obmalloc; 182 183 PyObject *audit_hooks; 184 PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS]; 185 PyCode_WatchCallback code_watchers[CODE_MAX_WATCHERS]; 186 // One bit is set for each non-NULL entry in code_watchers 187 uint8_t active_code_watchers; 188 189 struct _py_object_state object_state; 190 struct _Py_unicode_state unicode; 191 struct _Py_float_state float_state; 192 struct _Py_long_state long_state; 193 struct _dtoa_state dtoa; 194 struct _py_func_state func_state; 195 /* Using a cache is very effective since typically only a single slice is 196 created and then deleted again. */ 197 PySliceObject *slice_cache; 198 199 struct _Py_tuple_state tuple; 200 struct _Py_list_state list; 201 struct _Py_dict_state dict_state; 202 struct _Py_async_gen_state async_gen; 203 struct _Py_context_state context; 204 struct _Py_exc_state exc_state; 205 206 struct ast_state ast; 207 struct types_state types; 208 struct callable_cache callable_cache; 209 PyCodeObject *interpreter_trampoline; 210 211 _Py_GlobalMonitors monitors; 212 bool f_opcode_trace_set; 213 bool sys_profile_initialized; 214 bool sys_trace_initialized; 215 Py_ssize_t sys_profiling_threads; /* Count of threads with c_profilefunc set */ 216 Py_ssize_t sys_tracing_threads; /* Count of threads with c_tracefunc set */ 217 PyObject *monitoring_callables[PY_MONITORING_TOOL_IDS][_PY_MONITORING_EVENTS]; 218 PyObject *monitoring_tool_names[PY_MONITORING_TOOL_IDS]; 219 220 struct _Py_interp_cached_objects cached_objects; 221 struct _Py_interp_static_objects static_objects; 222 223 // XXX Remove this field once we have a tp_* slot. 224 struct _xidregistry xidregistry; 225 /* The thread currently executing in the __main__ module, if any. */ 226 PyThreadState *threads_main; 227 /* The ID of the OS thread in which we are finalizing. 228 We use _Py_atomic_address instead of adding a new _Py_atomic_ulong. */ 229 _Py_atomic_address _finalizing_id; 230 231 /* the initial PyInterpreterState.threads.head */ 232 PyThreadState _initial_thread; 233 }; 234 235 236 /* other API */ 237 238 extern void _PyInterpreterState_Clear(PyThreadState *tstate); 239 240 241 static inline PyThreadState* 242 _PyInterpreterState_GetFinalizing(PyInterpreterState *interp) { 243 return (PyThreadState*)_Py_atomic_load_relaxed(&interp->_finalizing); 244 } 245 246 static inline unsigned long 247 _PyInterpreterState_GetFinalizingID(PyInterpreterState *interp) { 248 return (unsigned long)_Py_atomic_load_relaxed(&interp->_finalizing_id); 249 } 250 251 static inline void 252 _PyInterpreterState_SetFinalizing(PyInterpreterState *interp, PyThreadState *tstate) { 253 _Py_atomic_store_relaxed(&interp->_finalizing, (uintptr_t)tstate); 254 if (tstate == NULL) { 255 _Py_atomic_store_relaxed(&interp->_finalizing_id, 0); 256 } 257 else { 258 // XXX Re-enable this assert once gh-109860 is fixed. 259 //assert(tstate->thread_id == PyThread_get_thread_ident()); 260 _Py_atomic_store_relaxed(&interp->_finalizing_id, 261 (uintptr_t)tstate->thread_id); 262 } 263 } 264 265 266 PyAPI_FUNC(PyInterpreterState*) _PyInterpreterState_LookUpID(int64_t); 267 268 PyAPI_FUNC(int) _PyInterpreterState_IDInitref(PyInterpreterState *); 269 PyAPI_FUNC(int) _PyInterpreterState_IDIncref(PyInterpreterState *); 270 PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *); 271 272 #ifdef __cplusplus 273 } 274 #endif 275 #endif /* !Py_INTERNAL_INTERP_H */
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™