diff options
| author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-10-03 15:20:48 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-03 15:20:48 (GMT) |
| commit | f5198b09e16bca1886f8245fa88203d07d51ec11 (patch) | |
| tree | e2032653aee5b6e2df560f6a37eca5a957d1fb6f /Include/internal/pycore_pystate.h | |
| parent | 4227bfa8b273207a2b882f7d69c8ac49c3d2b57d (diff) | |
| download | cpython-f5198b09e16bca1886f8245fa88203d07d51ec11.zip cpython-f5198b09e16bca1886f8245fa88203d07d51ec11.tar.gz cpython-f5198b09e16bca1886f8245fa88203d07d51ec11.tar.bz2 | |
gh-109860: Use a New Thread State When Switching Interpreters, When Necessary (gh-110245)
In a few places we switch to another interpreter without knowing if it has a thread state associated with the current thread. For the main interpreter there wasn't much of a problem, but for subinterpreters we were *mostly* okay re-using the tstate created with the interpreter (located via PyInterpreterState_ThreadHead()). There was a good chance that tstate wasn't actually in use by another thread.
However, there are no guarantees of that. Furthermore, re-using an already used tstate is currently fragile. To address this, now we create a new thread state in each of those places and use it.
One consequence of this change is that PyInterpreterState_ThreadHead() may not return NULL (though that won't happen for the main interpreter).
Diffstat (limited to 'Include/internal/pycore_pystate.h')
| -rw-r--r-- | Include/internal/pycore_pystate.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index 6a36dba..5f8b576 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -48,6 +48,7 @@ _Py_IsMainInterpreterFinalizing(PyInterpreterState *interp) PyAPI_FUNC(int) _PyInterpreterState_SetRunningMain(PyInterpreterState *); PyAPI_FUNC(void) _PyInterpreterState_SetNotRunningMain(PyInterpreterState *); PyAPI_FUNC(int) _PyInterpreterState_IsRunningMain(PyInterpreterState *); +PyAPI_FUNC(int) _PyInterpreterState_FailIfRunningMain(PyInterpreterState *); static inline const PyConfig * @@ -139,7 +140,9 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) { // PyThreadState functions -extern PyThreadState * _PyThreadState_New(PyInterpreterState *interp); +extern PyThreadState * _PyThreadState_New( + PyInterpreterState *interp, + int whence); extern void _PyThreadState_Bind(PyThreadState *tstate); extern void _PyThreadState_DeleteExcept(PyThreadState *tstate); |
