@@ -11,6 +11,7 @@ extern "C" {
11
11
#include "pycore_gil.h" /* struct _gil_runtime_state */
12
12
#include "pycore_pymem.h" /* struct _gc_runtime_state */
13
13
#include "pycore_warnings.h" /* struct _warnings_runtime_state */
14
+ #include "pycore_runtime.h" /* PyRuntimestate */
14
15
15
16
16
17
/* ceval state */
@@ -32,15 +33,6 @@ struct _pending_calls {
32
33
int last ;
33
34
};
34
35
35
- struct _ceval_runtime_state {
36
- int recursion_limit ;
37
- /* Request for dropping the GIL */
38
- _Py_atomic_int gil_drop_request ;
39
- /* Request for checking signals. */
40
- _Py_atomic_int signals_pending ;
41
- struct _gil_runtime_state gil ;
42
- };
43
-
44
36
struct _ceval_state {
45
37
/* Records whether tracing is on for any thread. Counts the number
46
38
of threads for which tstate->c_tracefunc is non-NULL, so if the
@@ -176,118 +168,6 @@ struct _xidregitem {
176
168
struct _xidregitem * next ;
177
169
};
178
170
179
- /* runtime audit hook state */
180
-
181
- typedef struct _Py_AuditHookEntry {
182
- struct _Py_AuditHookEntry * next ;
183
- Py_AuditHookFunction hookCFunction ;
184
- void * userData ;
185
- } _Py_AuditHookEntry ;
186
-
187
- /* GIL state */
188
-
189
- struct _gilstate_runtime_state {
190
- int check_enabled ;
191
- /* Assuming the current thread holds the GIL, this is the
192
- PyThreadState for the current thread. */
193
- _Py_atomic_address tstate_current ;
194
- /* The single PyInterpreterState used by this process'
195
- GILState implementation
196
- */
197
- /* TODO: Given interp_main, it may be possible to kill this ref */
198
- PyInterpreterState * autoInterpreterState ;
199
- Py_tss_t autoTSSkey ;
200
- };
201
-
202
- /* Issue #26558: Flag to disable PyGILState_Check().
203
- If set to non-zero, PyGILState_Check() always return 1. */
204
- #define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled
205
-
206
-
207
- /* Full Python runtime state */
208
-
209
- typedef struct pyruntimestate {
210
- /* Is running Py_PreInitialize()? */
211
- int preinitializing ;
212
-
213
- /* Is Python preinitialized? Set to 1 by Py_PreInitialize() */
214
- int preinitialized ;
215
-
216
- /* Is Python core initialized? Set to 1 by _Py_InitializeCore() */
217
- int core_initialized ;
218
-
219
- /* Is Python fully initialized? Set to 1 by Py_Initialize() */
220
- int initialized ;
221
-
222
- /* Set by Py_FinalizeEx(). Only reset to NULL if Py_Initialize()
223
- is called again.
224
-
225
- Use _PyRuntimeState_GetFinalizing() and _PyRuntimeState_SetFinalizing()
226
- to access it, don't access it directly. */
227
- _Py_atomic_address _finalizing ;
228
-
229
- struct pyinterpreters {
230
- PyThread_type_lock mutex ;
231
- PyInterpreterState * head ;
232
- PyInterpreterState * main ;
233
- /* _next_interp_id is an auto-numbered sequence of small
234
- integers. It gets initialized in _PyInterpreterState_Init(),
235
- which is called in Py_Initialize(), and used in
236
- PyInterpreterState_New(). A negative interpreter ID
237
- indicates an error occurred. The main interpreter will
238
- always have an ID of 0. Overflow results in a RuntimeError.
239
- If that becomes a problem later then we can adjust, e.g. by
240
- using a Python int. */
241
- int64_t next_id ;
242
- } interpreters ;
243
- // XXX Remove this field once we have a tp_* slot.
244
- struct _xidregistry {
245
- PyThread_type_lock mutex ;
246
- struct _xidregitem * head ;
247
- } xidregistry ;
248
-
249
- unsigned long main_thread ;
250
-
251
- #define NEXITFUNCS 32
252
- void (* exitfuncs [NEXITFUNCS ])(void );
253
- int nexitfuncs ;
254
-
255
- struct _ceval_runtime_state ceval ;
256
- struct _gilstate_runtime_state gilstate ;
257
-
258
- PyPreConfig preconfig ;
259
-
260
- Py_OpenCodeHookFunction open_code_hook ;
261
- void * open_code_userdata ;
262
- _Py_AuditHookEntry * audit_hook_head ;
263
-
264
- // XXX Consolidate globals found via the check-c-globals script.
265
- } _PyRuntimeState ;
266
-
267
- #define _PyRuntimeState_INIT \
268
- {.preinitialized = 0, .core_initialized = 0, .initialized = 0}
269
- /* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */
270
-
271
- PyAPI_DATA (_PyRuntimeState ) _PyRuntime ;
272
- PyAPI_FUNC (PyStatus ) _PyRuntimeState_Init (_PyRuntimeState * runtime );
273
- PyAPI_FUNC (void ) _PyRuntimeState_Fini (_PyRuntimeState * runtime );
274
- PyAPI_FUNC (void ) _PyRuntimeState_ReInitThreads (_PyRuntimeState * runtime );
275
-
276
- /* Initialize _PyRuntimeState.
277
- Return NULL on success, or return an error message on failure. */
278
- PyAPI_FUNC (PyStatus ) _PyRuntime_Initialize (void );
279
-
280
- PyAPI_FUNC (void ) _PyRuntime_Finalize (void );
281
-
282
- static inline PyThreadState *
283
- _PyRuntimeState_GetFinalizing (_PyRuntimeState * runtime ) {
284
- return (PyThreadState * )_Py_atomic_load_relaxed (& runtime -> _finalizing );
285
- }
286
-
287
- static inline void
288
- _PyRuntimeState_SetFinalizing (_PyRuntimeState * runtime , PyThreadState * tstate ) {
289
- _Py_atomic_store_relaxed (& runtime -> _finalizing , (uintptr_t )tstate );
290
- }
291
171
292
172
/* Check if the current thread is the main thread.
293
173
Use _Py_IsMainInterpreter() to check if it's the main interpreter. */
0 commit comments