https://github.com/python/cpython/commit/594a4631c3afd4139b6783f15034a92878c8eff1
commit: 594a4631c3afd4139b6783f15034a92878c8eff1
branch: main
author: Sam Gross <[email protected]>
committer: colesbury <[email protected]>
date: 2025-12-24T16:10:43-05:00
summary:

gh-120321: Fix TSan reported races on gi_frame_state (gh-143128)

files:
M Objects/genobject.c
M Python/frame.c

diff --git a/Objects/genobject.c b/Objects/genobject.c
index 020af903a3f828..d1fcda3d608320 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -559,7 +559,7 @@ gen_set_exception(PyObject *typ, PyObject *val, PyObject 
*tb)
 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 ce216797e47cda..da8f9037e8287a 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);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to