Skip to content

Commit

Permalink
gh-116515: Clear thread-local state before tstate_delete_common() (#1…
Browse files Browse the repository at this point in the history
…16517)

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".
  • Loading branch information
colesbury authored Mar 11, 2024
1 parent 05070f4 commit 9f983e0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9f983e0

Please sign in to comment.