@@ -217,8 +217,9 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
217
217
}
218
218
219
219
static inline void
220
- exit_thread_if_finalizing (_PyRuntimeState * runtime , PyThreadState * tstate )
220
+ exit_thread_if_finalizing (PyThreadState * tstate )
221
221
{
222
+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
222
223
/* _Py_Finalizing is protected by the GIL */
223
224
if (runtime -> finalizing != NULL && !_Py_CURRENTLY_FINALIZING (runtime , tstate )) {
224
225
drop_gil (& runtime -> ceval , tstate );
@@ -236,7 +237,7 @@ PyEval_AcquireLock(void)
236
237
Py_FatalError ("PyEval_AcquireLock: current thread state is NULL" );
237
238
}
238
239
take_gil (ceval , tstate );
239
- exit_thread_if_finalizing (runtime , tstate );
240
+ exit_thread_if_finalizing (tstate );
240
241
}
241
242
242
243
void
@@ -257,14 +258,15 @@ PyEval_AcquireThread(PyThreadState *tstate)
257
258
if (tstate == NULL ) {
258
259
Py_FatalError ("PyEval_AcquireThread: NULL new thread state" );
259
260
}
261
+ assert (tstate -> interp != NULL );
260
262
261
- _PyRuntimeState * runtime = & _PyRuntime ;
263
+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
262
264
struct _ceval_runtime_state * ceval = & runtime -> ceval ;
263
265
264
266
/* Check someone has called PyEval_InitThreads() to create the lock */
265
267
assert (gil_created (& ceval -> gil ));
266
268
take_gil (ceval , tstate );
267
- exit_thread_if_finalizing (runtime , tstate );
269
+ exit_thread_if_finalizing (tstate );
268
270
if (_PyThreadState_Swap (& runtime -> gilstate , tstate ) != NULL ) {
269
271
Py_FatalError ("PyEval_AcquireThread: non-NULL old thread state" );
270
272
}
@@ -276,8 +278,9 @@ PyEval_ReleaseThread(PyThreadState *tstate)
276
278
if (tstate == NULL ) {
277
279
Py_FatalError ("PyEval_ReleaseThread: NULL thread state" );
278
280
}
281
+ assert (tstate -> interp != NULL );
279
282
280
- _PyRuntimeState * runtime = & _PyRuntime ;
283
+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
281
284
PyThreadState * new_tstate = _PyThreadState_Swap (& runtime -> gilstate , NULL );
282
285
if (new_tstate != tstate ) {
283
286
Py_FatalError ("PyEval_ReleaseThread: wrong thread state" );
@@ -308,7 +311,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
308
311
}
309
312
310
313
/* Destroy all threads except the current one */
311
- _PyThreadState_DeleteExcept (runtime , current_tstate );
314
+ _PyThreadState_DeleteExcept (current_tstate );
312
315
}
313
316
314
317
/* This function is used to signal that async exceptions are waiting to be
@@ -337,17 +340,18 @@ PyEval_SaveThread(void)
337
340
void
338
341
PyEval_RestoreThread (PyThreadState * tstate )
339
342
{
340
- _PyRuntimeState * runtime = & _PyRuntime ;
341
- struct _ceval_runtime_state * ceval = & runtime -> ceval ;
342
-
343
343
if (tstate == NULL ) {
344
344
Py_FatalError ("PyEval_RestoreThread: NULL tstate" );
345
345
}
346
+ assert (tstate -> interp != NULL );
347
+
348
+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
349
+ struct _ceval_runtime_state * ceval = & runtime -> ceval ;
346
350
assert (gil_created (& ceval -> gil ));
347
351
348
352
int err = errno ;
349
353
take_gil (ceval , tstate );
350
- exit_thread_if_finalizing (runtime , tstate );
354
+ exit_thread_if_finalizing (tstate );
351
355
errno = err ;
352
356
353
357
_PyThreadState_Swap (& runtime -> gilstate , tstate );
@@ -1141,7 +1145,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
1141
1145
take_gil (ceval , tstate );
1142
1146
1143
1147
/* Check if we should make a quick exit. */
1144
- exit_thread_if_finalizing (runtime , tstate );
1148
+ exit_thread_if_finalizing (tstate );
1145
1149
1146
1150
if (_PyThreadState_Swap (& runtime -> gilstate , tstate ) != NULL ) {
1147
1151
Py_FatalError ("ceval: orphan tstate" );
0 commit comments