Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" … · python/cpython@0fd2c30
@@ -238,9 +238,8 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
238238}
239239240240static 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 */
245244if (runtime->finalizing != NULL && !_Py_CURRENTLY_FINALIZING(runtime, tstate)) {
246245drop_gil(&runtime->ceval, tstate);
@@ -287,7 +286,7 @@ PyEval_AcquireLock(void)
287286Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
288287 }
289288take_gil(ceval, tstate);
290-exit_thread_if_finalizing(tstate);
289+exit_thread_if_finalizing(runtime, tstate);
291290}
292291293292void
@@ -308,15 +307,14 @@ PyEval_AcquireThread(PyThreadState *tstate)
308307if (tstate == NULL) {
309308Py_FatalError("PyEval_AcquireThread: NULL new thread state");
310309 }
311-assert(tstate->interp != NULL);
312310313-_PyRuntimeState *runtime = tstate->interp->runtime;
311+_PyRuntimeState *runtime = &_PyRuntime;
314312struct _ceval_runtime_state *ceval = &runtime->ceval;
315313316314/* Check someone has called PyEval_InitThreads() to create the lock */
317315assert(gil_created(&ceval->gil));
318316take_gil(ceval, tstate);
319-exit_thread_if_finalizing(tstate);
317+exit_thread_if_finalizing(runtime, tstate);
320318if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
321319Py_FatalError("PyEval_AcquireThread: non-NULL old thread state");
322320 }
@@ -328,9 +326,8 @@ PyEval_ReleaseThread(PyThreadState *tstate)
328326if (tstate == NULL) {
329327Py_FatalError("PyEval_ReleaseThread: NULL thread state");
330328 }
331-assert(tstate->interp != NULL);
332329333-_PyRuntimeState *runtime = tstate->interp->runtime;
330+_PyRuntimeState *runtime = &_PyRuntime;
334331PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
335332if (new_tstate != tstate) {
336333Py_FatalError("PyEval_ReleaseThread: wrong thread state");
@@ -361,7 +358,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
361358 }
362359363360/* Destroy all threads except the current one */
364-_PyThreadState_DeleteExcept(current_tstate);
361+_PyThreadState_DeleteExcept(runtime, current_tstate);
365362}
366363367364/* 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+393393if (tstate == NULL) {
394394Py_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;
400396assert(gil_created(&ceval->gil));
401397402398int err = errno;
403399take_gil(ceval, tstate);
404-exit_thread_if_finalizing(tstate);
400+exit_thread_if_finalizing(runtime, tstate);
405401errno = err;
406402407403_PyThreadState_Swap(&runtime->gilstate, tstate);
@@ -1250,7 +1246,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
12501246take_gil(ceval, tstate);
1251124712521248/* Check if we should make a quick exit. */
1253-exit_thread_if_finalizing(tstate);
1249+exit_thread_if_finalizing(runtime, tstate);
1254125012551251if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
12561252Py_FatalError("ceval: orphan tstate");