Skip to content

Commit 8375a8d

Browse files
Clean up _PyThreadState_Swap() a little.
1 parent 2e90122 commit 8375a8d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Python/pystate.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,16 +1704,14 @@ PyThreadState *
17041704
_PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts)
17051705
{
17061706
PyThreadState *oldts = current_fast_get(runtime);
1707-
// XXX tstate_is_bound(oldts)
1707+
1708+
current_fast_clear(runtime);
1709+
17081710
if (oldts != NULL) {
1709-
// XXX assert(oldts == NULL || tstate_is_alive(oldts));
1711+
// XXX assert(tstate_is_alive(oldts) && tstate_is_bound(oldts));
17101712
tstate_deactivate(oldts);
17111713
}
1712-
1713-
if (newts == NULL) {
1714-
current_fast_clear(runtime);
1715-
}
1716-
else {
1714+
if (newts != NULL) {
17171715
assert(tstate_is_alive(newts) && tstate_is_bound(newts));
17181716
current_fast_set(runtime, newts);
17191717
tstate_activate(newts);
@@ -1731,8 +1729,10 @@ _PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts)
17311729
*/
17321730
int err = errno;
17331731
PyThreadState *check = gilstate_tss_get(runtime);
1734-
if (check && check->interp == newts->interp && check != newts) {
1735-
Py_FatalError("Invalid thread state for this thread");
1732+
if (check != newts) {
1733+
if (check && check->interp == newts->interp) {
1734+
Py_FatalError("Invalid thread state for this thread");
1735+
}
17361736
}
17371737
errno = err;
17381738
}

0 commit comments

Comments
 (0)