Skip to content

Commit 5153dc1

Browse files
committed
Copy the interpreter state pointer before overwriting it.
1 parent f795f6e commit 5153dc1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Python/pystate.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,16 +1399,17 @@ alloc_threadstate(void)
13991399
static void
14001400
free_threadstate(_PyThreadStateImpl *tstate)
14011401
{
1402+
PyInterpreterState *interp = tstate->base.interp;
14021403
// The initial thread state of the interpreter is allocated
14031404
// as part of the interpreter state so should not be freed.
1404-
if (tstate == &tstate->base.interp->_initial_thread) {
1405+
if (tstate == &interp->_initial_thread) {
14051406
// Restore to _PyThreadState_INIT.
14061407
memcpy(tstate,
14071408
&initial._main_interpreter._initial_thread,
14081409
sizeof(*tstate));
1409-
_Py_atomic_store_int_relaxed(
1410-
&tstate->base.interp->threads.used_initial,
1411-
0);
1410+
_Py_atomic_store_int(
1411+
&interp->threads.used_initial,
1412+
0);
14121413
}
14131414
else {
14141415
PyMem_RawFree(tstate);
@@ -1549,7 +1550,6 @@ new_threadstate(PyInterpreterState *interp, int whence)
15491550
if (set_initial == 1) {
15501551
// The initial thread state is not in use, and we successfully
15511552
// claimed it!
1552-
assert(old_head == NULL);
15531553
assert(_Py_atomic_load_int_relaxed(&interp->threads.used_initial) == 1);
15541554
used_newtstate = 0;
15551555
tstate = &interp->_initial_thread;

0 commit comments

Comments
 (0)