@@ -238,9 +238,8 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
238238}
239239
240240static inline void
241- exit_thread_if_finalizing (PyThreadState * tstate )
241+ exit_thread_if_finalizing (_PyRuntimeState * runtime , PyThreadState * tstate )
242242{
243- _PyRuntimeState * runtime = tstate -> interp -> runtime ;
244243 /* _Py_Finalizing is protected by the GIL */
245244 if (runtime -> finalizing != NULL && !_Py_CURRENTLY_FINALIZING (runtime , tstate )) {
246245 drop_gil (& runtime -> ceval , tstate );
@@ -287,7 +286,7 @@ PyEval_AcquireLock(void)
287286 Py_FatalError ("PyEval_AcquireLock: current thread state is NULL" );
288287 }
289288 take_gil (ceval , tstate );
290- exit_thread_if_finalizing (tstate );
289+ exit_thread_if_finalizing (runtime , tstate );
291290}
292291
293292void
@@ -308,15 +307,14 @@ PyEval_AcquireThread(PyThreadState *tstate)
308307 if (tstate == NULL ) {
309308 Py_FatalError ("PyEval_AcquireThread: NULL new thread state" );
310309 }
311- assert (tstate -> interp != NULL );
312310
313- _PyRuntimeState * runtime = tstate -> interp -> runtime ;
311+ _PyRuntimeState * runtime = & _PyRuntime ;
314312 struct _ceval_runtime_state * ceval = & runtime -> ceval ;
315313
316314 /* Check someone has called PyEval_InitThreads() to create the lock */
317315 assert (gil_created (& ceval -> gil ));
318316 take_gil (ceval , tstate );
319- exit_thread_if_finalizing (tstate );
317+ exit_thread_if_finalizing (runtime , tstate );
320318 if (_PyThreadState_Swap (& runtime -> gilstate , tstate ) != NULL ) {
321319 Py_FatalError ("PyEval_AcquireThread: non-NULL old thread state" );
322320 }
@@ -328,9 +326,8 @@ PyEval_ReleaseThread(PyThreadState *tstate)
328326 if (tstate == NULL ) {
329327 Py_FatalError ("PyEval_ReleaseThread: NULL thread state" );
330328 }
331- assert (tstate -> interp != NULL );
332329
333- _PyRuntimeState * runtime = tstate -> interp -> runtime ;
330+ _PyRuntimeState * runtime = & _PyRuntime ;
334331 PyThreadState * new_tstate = _PyThreadState_Swap (& runtime -> gilstate , NULL );
335332 if (new_tstate != tstate ) {
336333 Py_FatalError ("PyEval_ReleaseThread: wrong thread state" );
@@ -361,7 +358,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
361358 }
362359
363360 /* Destroy all threads except the current one */
364- _PyThreadState_DeleteExcept (current_tstate );
361+ _PyThreadState_DeleteExcept (runtime , current_tstate );
365362}
366363
367364/* This function is used to signal that async exceptions are waiting to be
@@ -390,18 +387,17 @@ PyEval_SaveThread(void)
390387void
391388PyEval_RestoreThread (PyThreadState * tstate )
392389{
390+ _PyRuntimeState * runtime = & _PyRuntime ;
391+ struct _ceval_runtime_state * ceval = & runtime -> ceval ;
392+
393393 if (tstate == NULL ) {
394394 Py_FatalError ("PyEval_RestoreThread: NULL tstate" );
395395 }
396- assert (tstate -> interp != NULL );
397-
398- _PyRuntimeState * runtime = tstate -> interp -> runtime ;
399- struct _ceval_runtime_state * ceval = & runtime -> ceval ;
400396 assert (gil_created (& ceval -> gil ));
401397
402398 int err = errno ;
403399 take_gil (ceval , tstate );
404- exit_thread_if_finalizing (tstate );
400+ exit_thread_if_finalizing (runtime , tstate );
405401 errno = err ;
406402
407403 _PyThreadState_Swap (& runtime -> gilstate , tstate );
@@ -1250,7 +1246,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
12501246 take_gil (ceval , tstate );
12511247
12521248 /* Check if we should make a quick exit. */
1253- exit_thread_if_finalizing (tstate );
1249+ exit_thread_if_finalizing (runtime , tstate );
12541250
12551251 if (_PyThreadState_Swap (& runtime -> gilstate , tstate ) != NULL ) {
12561252 Py_FatalError ("ceval: orphan tstate" );
0 commit comments