Skip to content

Commit 51a20d4

Browse files
committed
Fix assertion failures on the GILful build.
There were assertions that required the world to be stopped, but since that isn't a thing on GILful builds, it caused failures. Protect those assertions with a macro.
1 parent 1e1301d commit 51a20d4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Python/pylifecycle.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,13 +2003,19 @@ resolve_final_tstate(_PyRuntimeState *runtime)
20032003
return main_tstate;
20042004
}
20052005

2006+
#ifdef Py_GIL_DISABLED
2007+
#define ASSERT_WORLD_STOPPED(interp) assert(interp->runtime->stoptheworld.world_stopped)
2008+
#else
2009+
#define ASSERT_WORLD_STOPPED(interp)
2010+
#endif
2011+
20062012
static int
20072013
interp_has_threads(PyInterpreterState *interp)
20082014
{
20092015
/* This needs to check for non-daemon threads only, otherwise we get stuck
20102016
* in an infinite loop. */
20112017
assert(interp != NULL);
2012-
assert(interp->runtime->stoptheworld.world_stopped);
2018+
ASSERT_WORLD_STOPPED(interp);
20132019
assert(interp->threads.head != NULL);
20142020
if (interp->threads.head->next == NULL) {
20152021
// No other threads active, easy way out.
@@ -2031,7 +2037,7 @@ static int
20312037
interp_has_pending_calls(PyInterpreterState *interp)
20322038
{
20332039
assert(interp != NULL);
2034-
assert(interp->runtime->stoptheworld.world_stopped);
2040+
ASSERT_WORLD_STOPPED(interp);
20352041
return interp->ceval.pending.npending != 0;
20362042
}
20372043

@@ -2040,7 +2046,7 @@ interp_has_atexit_callbacks(PyInterpreterState *interp)
20402046
{
20412047
assert(interp != NULL);
20422048
assert(interp->atexit.callbacks != NULL);
2043-
assert(interp->runtime->stoptheworld.world_stopped);
2049+
ASSERT_WORLD_STOPPED(interp);
20442050
assert(PyList_CheckExact(interp->atexit.callbacks));
20452051
return PyList_GET_SIZE(interp->atexit.callbacks) != 0;
20462052
}
@@ -2093,7 +2099,7 @@ make_pre_finalization_calls(PyThreadState *tstate)
20932099
_PyEval_StartTheWorldAll(interp->runtime);
20942100
PyMutex_Unlock(&interp->ceval.pending.mutex);
20952101
}
2096-
assert(interp->runtime->stoptheworld.world_stopped);
2102+
ASSERT_WORLD_STOPPED(interp);
20972103
}
20982104

20992105
static int
@@ -2130,7 +2136,7 @@ _Py_Finalize(_PyRuntimeState *runtime)
21302136
#endif
21312137

21322138
/* Ensure that remaining threads are detached */
2133-
assert(tstate->interp->runtime->stoptheworld.world_stopped);
2139+
ASSERT_WORLD_STOPPED(tstate->interp);
21342140

21352141
/* Remaining daemon threads will be trapped in PyThread_hang_thread
21362142
when they attempt to take the GIL (ex: PyEval_RestoreThread()). */

0 commit comments

Comments
 (0)