aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-05-05 19:56:48 +0200
committerGitHub <noreply@github.com>2020-05-05 19:56:48 +0200
commite838a9324c1719bb917ca81ede8d766b5cb551f4 (patch)
treecc080055a371795862bf113ae248137587989e31 /Python/ceval.c
parentbpo-40521: Disable free lists in subinterpreters (GH-19937) (diff)
downloadcpython-e838a9324c1719bb917ca81ede8d766b5cb551f4.tar.gz
cpython-e838a9324c1719bb917ca81ede8d766b5cb551f4.tar.bz2
cpython-e838a9324c1719bb917ca81ede8d766b5cb551f4.zip
bpo-40522: _PyThreadState_Swap() sets autoTSSkey (GH-19939)
In the experimental isolated subinterpreters build mode, _PyThreadState_GET() gets the autoTSSkey variable and _PyThreadState_Swap() sets the autoTSSkey variable. * Add _PyThreadState_GetTSS() * _PyRuntimeState_GetThreadState() and _PyThreadState_GET() return _PyThreadState_GetTSS() * PyEval_SaveThread() sets the autoTSSkey variable to current Python thread state rather than NULL. * eval_frame_handle_pending() doesn't check that _PyThreadState_Swap() result is NULL. * _PyThreadState_Swap() gets the current Python thread state with _PyThreadState_GetTSS() rather than _PyRuntimeGILState_GetThreadState(). * PyGILState_Ensure() no longer checks _PyEval_ThreadsInitialized() since it cannot access the current interpreter.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 0c08a76f7d..b5854d3446 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -380,9 +380,13 @@ PyEval_AcquireThread(PyThreadState *tstate)
take_gil(tstate);
struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ (void)_PyThreadState_Swap(gilstate, tstate);
+#else
if (_PyThreadState_Swap(gilstate, tstate) != NULL) {
Py_FatalError("non-NULL old thread state");
}
+#endif
}
void
@@ -443,7 +447,12 @@ PyThreadState *
PyEval_SaveThread(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ PyThreadState *old_tstate = _PyThreadState_GET();
+ PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, old_tstate);
+#else
PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
+#endif
ensure_tstate_not_null(__func__, tstate);
struct _ceval_runtime_state *ceval = &runtime->ceval;
@@ -866,9 +875,13 @@ eval_frame_handle_pending(PyThreadState *tstate)
take_gil(tstate);
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ (void)_PyThreadState_Swap(&runtime->gilstate, tstate);
+#else
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
Py_FatalError("orphan tstate");
}
+#endif
}
/* Check for asynchronous exception. */