File indexing completed on 2025-01-18 10:06:45
0001 #ifndef Py_INTERNAL_INTERP_H
0002 #define Py_INTERNAL_INTERP_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 <stdbool.h>
0012
0013 #include "pycore_ast_state.h" // struct ast_state
0014 #include "pycore_atexit.h" // struct atexit_state
0015 #include "pycore_atomic.h" // _Py_atomic_address
0016 #include "pycore_ceval_state.h" // struct _ceval_state
0017 #include "pycore_code.h" // struct callable_cache
0018 #include "pycore_context.h" // struct _Py_context_state
0019 #include "pycore_dict_state.h" // struct _Py_dict_state
0020 #include "pycore_dtoa.h" // struct _dtoa_state
0021 #include "pycore_exceptions.h" // struct _Py_exc_state
0022 #include "pycore_floatobject.h" // struct _Py_float_state
0023 #include "pycore_function.h" // FUNC_MAX_WATCHERS
0024 #include "pycore_genobject.h" // struct _Py_async_gen_state
0025 #include "pycore_gc.h" // struct _gc_runtime_state
0026 #include "pycore_global_objects.h" // struct _Py_interp_static_objects
0027 #include "pycore_import.h" // struct _import_state
0028 #include "pycore_instruments.h" // _PY_MONITORING_EVENTS
0029 #include "pycore_list.h" // struct _Py_list_state
0030 #include "pycore_object_state.h" // struct _py_object_state
0031 #include "pycore_obmalloc.h" // struct obmalloc_state
0032 #include "pycore_tuple.h" // struct _Py_tuple_state
0033 #include "pycore_typeobject.h" // struct type_cache
0034 #include "pycore_unicodeobject.h" // struct _Py_unicode_state
0035 #include "pycore_warnings.h" // struct _warnings_runtime_state
0036
0037
0038 struct _Py_long_state {
0039 int max_str_digits;
0040 };
0041
0042
0043
0044
0045
0046
0047
0048
0049 struct _xidregitem;
0050
0051 struct _xidregitem {
0052 struct _xidregitem *prev;
0053 struct _xidregitem *next;
0054
0055 PyTypeObject *cls;
0056
0057 PyObject *weakref;
0058 size_t refcount;
0059 crossinterpdatafunc getdata;
0060 };
0061
0062 struct _xidregistry {
0063 PyThread_type_lock mutex;
0064 struct _xidregitem *head;
0065 };
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 struct _is {
0076
0077 PyInterpreterState *next;
0078
0079 int64_t id;
0080 int64_t id_refcount;
0081 int requires_idref;
0082 PyThread_type_lock id_mutex;
0083
0084
0085
0086
0087
0088 int _initialized;
0089 int finalizing;
0090
0091 uint64_t monitoring_version;
0092 uint64_t last_restart_version;
0093 struct pythreads {
0094 uint64_t next_unique_id;
0095
0096 PyThreadState *head;
0097
0098 long count;
0099
0100
0101
0102
0103 size_t stacksize;
0104 } threads;
0105
0106
0107
0108
0109 struct pyruntimestate *runtime;
0110
0111
0112
0113
0114
0115
0116 _Py_atomic_address _finalizing;
0117
0118 struct _gc_runtime_state gc;
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 PyObject *sysdict;
0134
0135
0136 PyObject *builtins;
0137
0138 struct _ceval_state ceval;
0139
0140 struct _import_state imports;
0141
0142
0143 struct _gil_runtime_state _gil;
0144
0145
0146
0147
0148
0149
0150 PyObject *codec_search_path;
0151 PyObject *codec_search_cache;
0152 PyObject *codec_error_registry;
0153 int codecs_initialized;
0154
0155 PyConfig config;
0156 unsigned long feature_flags;
0157
0158 PyObject *dict;
0159
0160 PyObject *sysdict_copy;
0161 PyObject *builtins_copy;
0162
0163 _PyFrameEvalFunction eval_frame;
0164
0165 PyFunction_WatchCallback func_watchers[FUNC_MAX_WATCHERS];
0166
0167 uint8_t active_func_watchers;
0168
0169 Py_ssize_t co_extra_user_count;
0170 freefunc co_extra_freefuncs[MAX_CO_EXTRA_USERS];
0171
0172 #ifdef HAVE_FORK
0173 PyObject *before_forkers;
0174 PyObject *after_forkers_parent;
0175 PyObject *after_forkers_child;
0176 #endif
0177
0178 struct _warnings_runtime_state warnings;
0179 struct atexit_state atexit;
0180
0181 struct _obmalloc_state obmalloc;
0182
0183 PyObject *audit_hooks;
0184 PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS];
0185 PyCode_WatchCallback code_watchers[CODE_MAX_WATCHERS];
0186
0187 uint8_t active_code_watchers;
0188
0189 struct _py_object_state object_state;
0190 struct _Py_unicode_state unicode;
0191 struct _Py_float_state float_state;
0192 struct _Py_long_state long_state;
0193 struct _dtoa_state dtoa;
0194 struct _py_func_state func_state;
0195
0196
0197 PySliceObject *slice_cache;
0198
0199 struct _Py_tuple_state tuple;
0200 struct _Py_list_state list;
0201 struct _Py_dict_state dict_state;
0202 struct _Py_async_gen_state async_gen;
0203 struct _Py_context_state context;
0204 struct _Py_exc_state exc_state;
0205
0206 struct ast_state ast;
0207 struct types_state types;
0208 struct callable_cache callable_cache;
0209 PyCodeObject *interpreter_trampoline;
0210
0211 _Py_GlobalMonitors monitors;
0212 bool f_opcode_trace_set;
0213 bool sys_profile_initialized;
0214 bool sys_trace_initialized;
0215 Py_ssize_t sys_profiling_threads;
0216 Py_ssize_t sys_tracing_threads;
0217 PyObject *monitoring_callables[PY_MONITORING_TOOL_IDS][_PY_MONITORING_EVENTS];
0218 PyObject *monitoring_tool_names[PY_MONITORING_TOOL_IDS];
0219
0220 struct _Py_interp_cached_objects cached_objects;
0221 struct _Py_interp_static_objects static_objects;
0222
0223
0224 struct _xidregistry xidregistry;
0225
0226 PyThreadState *threads_main;
0227
0228
0229 _Py_atomic_address _finalizing_id;
0230
0231
0232 PyThreadState _initial_thread;
0233 };
0234
0235
0236
0237
0238 extern void _PyInterpreterState_Clear(PyThreadState *tstate);
0239
0240
0241 static inline PyThreadState*
0242 _PyInterpreterState_GetFinalizing(PyInterpreterState *interp) {
0243 return (PyThreadState*)_Py_atomic_load_relaxed(&interp->_finalizing);
0244 }
0245
0246 static inline unsigned long
0247 _PyInterpreterState_GetFinalizingID(PyInterpreterState *interp) {
0248 return (unsigned long)_Py_atomic_load_relaxed(&interp->_finalizing_id);
0249 }
0250
0251 static inline void
0252 _PyInterpreterState_SetFinalizing(PyInterpreterState *interp, PyThreadState *tstate) {
0253 _Py_atomic_store_relaxed(&interp->_finalizing, (uintptr_t)tstate);
0254 if (tstate == NULL) {
0255 _Py_atomic_store_relaxed(&interp->_finalizing_id, 0);
0256 }
0257 else {
0258
0259
0260 _Py_atomic_store_relaxed(&interp->_finalizing_id,
0261 (uintptr_t)tstate->thread_id);
0262 }
0263 }
0264
0265
0266 PyAPI_FUNC(PyInterpreterState*) _PyInterpreterState_LookUpID(int64_t);
0267
0268 PyAPI_FUNC(int) _PyInterpreterState_IDInitref(PyInterpreterState *);
0269 PyAPI_FUNC(int) _PyInterpreterState_IDIncref(PyInterpreterState *);
0270 PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
0271
0272 #ifdef __cplusplus
0273 }
0274 #endif
0275 #endif