summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-11-20 01:27:56 (GMT)
committerGitHub <noreply@github.com>2019-11-20 01:27:56 (GMT)
commit01b1cc12e7c6a3d6a3d27ba7c731687d57aae92a (patch)
tree1d1afefdc486c063853678d126975fe2d019059f /Python/ceval.c
parenteb1cbbff1cd8214836a492502e75e463ade6f673 (diff)
downloadcpython-01b1cc12e7c6a3d6a3d27ba7c731687d57aae92a.zip
cpython-01b1cc12e7c6a3d6a3d27ba7c731687d57aae92a.tar.gz
cpython-01b1cc12e7c6a3d6a3d27ba7c731687d57aae92a.tar.bz2
bpo-36710: Add PyInterpreterState.runtime field (GH-17270)
Add PyInterpreterState.runtime field: reference to the _PyRuntime global variable. This field exists to not have to pass runtime in addition to tstate to a function. Get runtime from tstate: tstate->interp->runtime. Remove "_PyRuntimeState *runtime" parameter from functions already taking a "PyThreadState *tstate" parameter. _PyGC_Init() first parameter becomes "PyThreadState *tstate".
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 9f4b436..ee13fd1 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -191,7 +191,8 @@ static size_t opcache_global_misses = 0;
int
PyEval_ThreadsInitialized(void)
{
- return gil_created(&_PyRuntime.ceval.gil);
+ _PyRuntimeState *runtime = &_PyRuntime;
+ return gil_created(&runtime->ceval.gil);
}
void
@@ -235,8 +236,9 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
}
static inline void
-exit_thread_if_finalizing(_PyRuntimeState *runtime, PyThreadState *tstate)
+exit_thread_if_finalizing(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);
@@ -283,7 +285,7 @@ PyEval_AcquireLock(void)
Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
}
take_gil(ceval, tstate);
- exit_thread_if_finalizing(runtime, tstate);
+ exit_thread_if_finalizing(tstate);
}
void
@@ -305,13 +307,13 @@ PyEval_AcquireThread(PyThreadState *tstate)
Py_FatalError("PyEval_AcquireThread: NULL new thread state");
}
- _PyRuntimeState *runtime = &_PyRuntime;
+ _PyRuntimeState *runtime = tstate->interp->runtime;
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(runtime, tstate);
+ exit_thread_if_finalizing(tstate);
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
Py_FatalError("PyEval_AcquireThread: non-NULL old thread state");
}
@@ -324,7 +326,7 @@ PyEval_ReleaseThread(PyThreadState *tstate)
Py_FatalError("PyEval_ReleaseThread: NULL thread state");
}
- _PyRuntimeState *runtime = &_PyRuntime;
+ _PyRuntimeState *runtime = tstate->interp->runtime;
PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
if (new_tstate != tstate) {
Py_FatalError("PyEval_ReleaseThread: wrong thread state");
@@ -384,7 +386,7 @@ PyEval_SaveThread(void)
void
PyEval_RestoreThread(PyThreadState *tstate)
{
- _PyRuntimeState *runtime = &_PyRuntime;
+ _PyRuntimeState *runtime = tstate->interp->runtime;
struct _ceval_runtime_state *ceval = &runtime->ceval;
if (tstate == NULL) {
@@ -394,7 +396,7 @@ PyEval_RestoreThread(PyThreadState *tstate)
int err = errno;
take_gil(ceval, tstate);
- exit_thread_if_finalizing(runtime, tstate);
+ exit_thread_if_finalizing(tstate);
errno = err;
_PyThreadState_Swap(&runtime->gilstate, tstate);
@@ -649,7 +651,8 @@ _PyEval_Initialize(struct _ceval_runtime_state *state)
int
Py_GetRecursionLimit(void)
{
- return _PyRuntime.ceval.recursion_limit;
+ struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;
+ return ceval->recursion_limit;
}
void
@@ -668,7 +671,7 @@ Py_SetRecursionLimit(int new_limit)
int
_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
{
- _PyRuntimeState *runtime = &_PyRuntime;
+ _PyRuntimeState *runtime = tstate->interp->runtime;
int recursion_limit = runtime->ceval.recursion_limit;
#ifdef USE_STACKCHECK
@@ -1245,7 +1248,7 @@ main_loop:
take_gil(ceval, tstate);
/* Check if we should make a quick exit. */
- exit_thread_if_finalizing(runtime, tstate);
+ exit_thread_if_finalizing(tstate);
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
Py_FatalError("ceval: orphan tstate");
@@ -4806,7 +4809,8 @@ _PyEval_GetAsyncGenFinalizer(void)
static PyFrameObject *
_PyEval_GetFrame(PyThreadState *tstate)
{
- return _PyRuntime.gilstate.getframe(tstate);
+ _PyRuntimeState *runtime = tstate->interp->runtime;
+ return runtime->gilstate.getframe(tstate);
}
PyFrameObject *