]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120321: Fix TSan reported races on gi_frame_state (gh-143128)
authorSam Gross <colesbury@gmail.com>
Wed, 24 Dec 2025 21:10:43 +0000 (16:10 -0500)
committerGitHub <noreply@github.com>
Wed, 24 Dec 2025 21:10:43 +0000 (16:10 -0500)
Objects/genobject.c
Python/frame.c

index 020af903a3f82839763331f468731160ba39fb74..d1fcda3d608320738b93231768c6ef2c281dcfe1 100644 (file)
@@ -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) {
index ce216797e47cda6a5c8d29c0d7d3721461a9df78..da8f9037e8287a2dc4d6bb0a5761996a0e3614a4 100644 (file)
@@ -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);