]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116515: Clear thread-local state before tstate_delete_common() (#116517)
authorSam Gross <colesbury@gmail.com>
Mon, 11 Mar 2024 19:14:20 +0000 (15:14 -0400)
committerGitHub <noreply@github.com>
Mon, 11 Mar 2024 19:14:20 +0000 (15:14 -0400)
This moves `current_fast_clear()` up so that the current thread state is
`NULL` while running `tstate_delete_common()`.

This doesn't fix any bugs, but it means that we are more consistent that
`_PyThreadState_GET() != NULL` means that the thread is "attached".

Python/pystate.c

index 1418d034ca2fe92a9e81b0ec281ac17a59482a7b..635616c5648c1800fa989132045eb702af26ccc9 100644 (file)
@@ -1609,6 +1609,7 @@ tstate_delete_common(PyThreadState *tstate)
 {
     assert(tstate->_status.cleared && !tstate->_status.finalized);
     assert(tstate->state != _Py_THREAD_ATTACHED);
+    tstate_verify_not_active(tstate);
 
     PyInterpreterState *interp = tstate->interp;
     if (interp == NULL) {
@@ -1687,8 +1688,8 @@ _PyThreadState_DeleteCurrent(PyThreadState *tstate)
     _Py_qsbr_detach(((_PyThreadStateImpl *)tstate)->qsbr);
 #endif
     tstate_set_detached(tstate, _Py_THREAD_DETACHED);
-    tstate_delete_common(tstate);
     current_fast_clear(tstate->interp->runtime);
+    tstate_delete_common(tstate);
     _PyEval_ReleaseLock(tstate->interp, NULL);
     free_threadstate((_PyThreadStateImpl *)tstate);
 }