summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-08 09:50:46 (GMT)
committerGitHub <noreply@github.com>2023-09-08 09:50:46 (GMT)
commitf63d37877ad166041489a968233b57540f8456e8 (patch)
treed4c6bb8c8478a3d0e3760b11e7e24a143012ba6e /Modules
parentb0edf3b98e4b3e68a13776e034b9dd86ad7e529d (diff)
downloadcpython-f63d37877ad166041489a968233b57540f8456e8.zip
cpython-f63d37877ad166041489a968233b57540f8456e8.tar.gz
cpython-f63d37877ad166041489a968233b57540f8456e8.tar.bz2
gh-104690: thread_run() checks for tstate dangling pointer (#109056)
thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_threadmodule.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 49f34fc..05bb497 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -1074,9 +1074,12 @@ static void
thread_run(void *boot_raw)
{
struct bootstate *boot = (struct bootstate *) boot_raw;
- PyThreadState *tstate;
+ PyThreadState *tstate = boot->tstate;
+
+ // gh-104690: If Python is being finalized and PyInterpreterState_Delete()
+ // was called, tstate becomes a dangling pointer.
+ assert(_PyThreadState_CheckConsistency(tstate));
- tstate = boot->tstate;
_PyThreadState_Bind(tstate);
PyEval_AcquireThread(tstate);
tstate->interp->threads.count++;