From: Sam Gross Date: Wed, 24 Dec 2025 21:10:43 +0000 (-0500) Subject: gh-120321: Fix TSan reported races on gi_frame_state (gh-143128) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=594a4631c3afd4139b6783f15034a92878c8eff1;p=thirdparty%2FPython%2Fcpython.git gh-120321: Fix TSan reported races on gi_frame_state (gh-143128) --- diff --git a/Objects/genobject.c b/Objects/genobject.c index 020af903a3f8..d1fcda3d6083 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -559,7 +559,7 @@ failed_throw: static PyObject * gen_throw_current_exception(PyGenObject *gen) { - assert(gen->gi_frame_state == FRAME_EXECUTING); + assert(FT_ATOMIC_LOAD_INT8_RELAXED(gen->gi_frame_state) == FRAME_EXECUTING); PyObject *result; if (gen_send_ex2(gen, Py_None, &result, 1) == PYGEN_RETURN) { diff --git a/Python/frame.c b/Python/frame.c index ce216797e47c..da8f9037e828 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -109,7 +109,7 @@ _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame) /* It is the responsibility of the owning generator/coroutine * to have cleared the enclosing generator, if any. */ assert(frame->owner != FRAME_OWNED_BY_GENERATOR || - _PyGen_GetGeneratorFromFrame(frame)->gi_frame_state == FRAME_CLEARED); + FT_ATOMIC_LOAD_INT8_RELAXED(_PyGen_GetGeneratorFromFrame(frame)->gi_frame_state) == FRAME_CLEARED); // GH-99729: Clearing this frame can expose the stack (via finalizers). It's // crucial that this frame has been unlinked, and is no longer visible: assert(_PyThreadState_GET()->current_frame != frame);