]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120321: Fix TSan reported race in gen_clear_frame (gh-142995)
authorSam Gross <colesbury@gmail.com>
Fri, 19 Dec 2025 22:33:49 +0000 (17:33 -0500)
committerGitHub <noreply@github.com>
Fri, 19 Dec 2025 22:33:49 +0000 (17:33 -0500)
TSan treats compare-exchanges that fail as if they are writes
so there is a false positive with the read of gi_frame_state in
gen_close.

Objects/genobject.c

index 508d215a0cfe64a00f1511b2a4d75801a123a2c6..1e59d89f5ce85fe337035806dd7cb0098a4dcdb0 100644 (file)
@@ -153,7 +153,7 @@ _PyGen_Finalize(PyObject *self)
 static void
 gen_clear_frame(PyGenObject *gen)
 {
-    assert(gen->gi_frame_state == FRAME_CLEARED);
+    assert(FT_ATOMIC_LOAD_INT8_RELAXED(gen->gi_frame_state) == FRAME_CLEARED);
     _PyInterpreterFrame *frame = &gen->gi_iframe;
     frame->previous = NULL;
     _PyFrame_ClearExceptCode(frame);