summaryrefslogtreecommitdiff
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-06-04 03:15:09 +0200
committerGitHub <noreply@github.com>2019-06-04 03:15:09 +0200
commit0fd2c300c2a85b3b227a907b2a39ef79fa86d850 (patch)
treeffe391ade17e6d581878f22016b065f7306f3fca /Python/ceval.c
parent9535aff9421f0a5639f6e4c4bb0f07a743ea8dba (diff)
downloadcpython-git-0fd2c300c2a85b3b227a907b2a39ef79fa86d850.tar.gz
Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" (GH-13795)
This reverts commit 396e0a8d9dc65453cb9d53500d0a620602656cfe.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 2590ce6575..7063647d58 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -238,9 +238,8 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
}
static inline void
-exit_thread_if_finalizing(PyThreadState *tstate)
+exit_thread_if_finalizing(_PyRuntimeState *runtime, PyThreadState *tstate)
{
- _PyRuntimeState *runtime = tstate->interp->runtime;
/* _Py_Finalizing is protected by the GIL */
if (runtime->finalizing != NULL && !_Py_CURRENTLY_FINALIZING(runtime, tstate)) {
drop_gil(&runtime->ceval, tstate);
@@ -287,7 +286,7 @@ PyEval_AcquireLock(void)
Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
}
take_gil(ceval, tstate);
- exit_thread_if_finalizing(tstate);
+ exit_thread_if_finalizing(runtime, tstate);
}
void
@@ -308,15 +307,14 @@ PyEval_AcquireThread(PyThreadState *tstate)
if (tstate == NULL) {
Py_FatalError("PyEval_AcquireThread: NULL new thread state");
}
- assert(tstate->interp != NULL);
- _PyRuntimeState *runtime = tstate->interp->runtime;
+ _PyRuntimeState *runtime = &_PyRuntime;
struct _ceval_runtime_state *ceval = &runtime->ceval;
/* Check someone has called PyEval_InitThreads() to create the lock */
assert(gil_created(&ceval->gil));
take_gil(ceval, tstate);
- exit_thread_if_finalizing(tstate);
+ exit_thread_if_finalizing(runtime, tstate);
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
Py_FatalError("PyEval_AcquireThread: non-NULL old thread state");
}
@@ -328,9 +326,8 @@ PyEval_ReleaseThread(PyThreadState *tstate)
if (tstate == NULL) {
Py_FatalError("PyEval_ReleaseThread: NULL thread state");
}
- assert(tstate->interp != NULL);
- _PyRuntimeState *runtime = tstate->interp->runtime;
+ _PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
if (new_tstate != tstate) {
Py_FatalError("PyEval_ReleaseThread: wrong thread state");
@@ -361,7 +358,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
}
/* Destroy all threads except the current one */
- _PyThreadState_DeleteExcept(current_tstate);
+ _PyThreadState_DeleteExcept(runtime, current_tstate);
}
/* This function is used to signal that async exceptions are waiting to be
@@ -390,18 +387,17 @@ PyEval_SaveThread(void)
void
PyEval_RestoreThread(PyThreadState *tstate)
{
+ _PyRuntimeState *runtime = &_PyRuntime;
+ struct _ceval_runtime_state *ceval = &runtime->ceval;
+
if (tstate == NULL) {
Py_FatalError("PyEval_RestoreThread: NULL tstate");
}
- assert(tstate->interp != NULL);
-
- _PyRuntimeState *runtime = tstate->interp->runtime;
- struct _ceval_runtime_state *ceval = &runtime->ceval;
assert(gil_created(&ceval->gil));
int err = errno;
take_gil(ceval, tstate);
- exit_thread_if_finalizing(tstate);
+ exit_thread_if_finalizing(runtime, tstate);
errno = err;
_PyThreadState_Swap(&runtime->gilstate, tstate);
@@ -1250,7 +1246,7 @@ main_loop:
take_gil(ceval, tstate);
/* Check if we should make a quick exit. */
- exit_thread_if_finalizing(tstate);
+ exit_thread_if_finalizing(runtime, tstate);
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
Py_FatalError("ceval: orphan tstate");