@@ -217,8 +217,9 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
217217}
218218
219219static inline void
220- exit_thread_if_finalizing (_PyRuntimeState * runtime , PyThreadState * tstate )
220+ exit_thread_if_finalizing (PyThreadState * tstate )
221221{
222+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
222223 /* _Py_Finalizing is protected by the GIL */
223224 if (runtime -> finalizing != NULL && !_Py_CURRENTLY_FINALIZING (runtime , tstate )) {
224225 drop_gil (& runtime -> ceval , tstate );
@@ -236,7 +237,7 @@ PyEval_AcquireLock(void)
236237 Py_FatalError ("PyEval_AcquireLock: current thread state is NULL" );
237238 }
238239 take_gil (ceval , tstate );
239- exit_thread_if_finalizing (runtime , tstate );
240+ exit_thread_if_finalizing (tstate );
240241}
241242
242243void
@@ -257,14 +258,15 @@ PyEval_AcquireThread(PyThreadState *tstate)
257258 if (tstate == NULL ) {
258259 Py_FatalError ("PyEval_AcquireThread: NULL new thread state" );
259260 }
261+ assert (tstate -> interp != NULL );
260262
261- _PyRuntimeState * runtime = & _PyRuntime ;
263+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
262264 struct _ceval_runtime_state * ceval = & runtime -> ceval ;
263265
264266 /* Check someone has called PyEval_InitThreads() to create the lock */
265267 assert (gil_created (& ceval -> gil ));
266268 take_gil (ceval , tstate );
267- exit_thread_if_finalizing (runtime , tstate );
269+ exit_thread_if_finalizing (tstate );
268270 if (_PyThreadState_Swap (& runtime -> gilstate , tstate ) != NULL ) {
269271 Py_FatalError ("PyEval_AcquireThread: non-NULL old thread state" );
270272 }
@@ -276,8 +278,9 @@ PyEval_ReleaseThread(PyThreadState *tstate)
276278 if (tstate == NULL ) {
277279 Py_FatalError ("PyEval_ReleaseThread: NULL thread state" );
278280 }
281+ assert (tstate -> interp != NULL );
279282
280- _PyRuntimeState * runtime = & _PyRuntime ;
283+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
281284 PyThreadState * new_tstate = _PyThreadState_Swap (& runtime -> gilstate , NULL );
282285 if (new_tstate != tstate ) {
283286 Py_FatalError ("PyEval_ReleaseThread: wrong thread state" );
@@ -308,7 +311,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
308311 }
309312
310313 /* Destroy all threads except the current one */
311- _PyThreadState_DeleteExcept (runtime , current_tstate );
314+ _PyThreadState_DeleteExcept (current_tstate );
312315}
313316
314317/* This function is used to signal that async exceptions are waiting to be
@@ -337,17 +340,18 @@ PyEval_SaveThread(void)
337340void
338341PyEval_RestoreThread (PyThreadState * tstate )
339342{
340- _PyRuntimeState * runtime = & _PyRuntime ;
341- struct _ceval_runtime_state * ceval = & runtime -> ceval ;
342-
343343 if (tstate == NULL ) {
344344 Py_FatalError ("PyEval_RestoreThread: NULL tstate" );
345345 }
346+ assert (tstate -> interp != NULL );
347+
348+ _PyRuntimeState * runtime = tstate -> interp -> runtime ;
349+ struct _ceval_runtime_state * ceval = & runtime -> ceval ;
346350 assert (gil_created (& ceval -> gil ));
347351
348352 int err = errno ;
349353 take_gil (ceval , tstate );
350- exit_thread_if_finalizing (runtime , tstate );
354+ exit_thread_if_finalizing (tstate );
351355 errno = err ;
352356
353357 _PyThreadState_Swap (& runtime -> gilstate , tstate );
@@ -1141,7 +1145,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
11411145 take_gil (ceval , tstate );
11421146
11431147 /* Check if we should make a quick exit. */
1144- exit_thread_if_finalizing (runtime , tstate );
1148+ exit_thread_if_finalizing (tstate );
11451149
11461150 if (_PyThreadState_Swap (& runtime -> gilstate , tstate ) != NULL ) {
11471151 Py_FatalError ("ceval: orphan tstate" );
0 commit comments