Skip to content

Commit 594a463

Browse files
authored
gh-120321: Fix TSan reported races on gi_frame_state (gh-143128)
1 parent 305aff0 commit 594a463

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Objects/genobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ gen_set_exception(PyObject *typ, PyObject *val, PyObject *tb)
559559
static PyObject *
560560
gen_throw_current_exception(PyGenObject *gen)
561561
{
562-
assert(gen->gi_frame_state == FRAME_EXECUTING);
562+
assert(FT_ATOMIC_LOAD_INT8_RELAXED(gen->gi_frame_state) == FRAME_EXECUTING);
563563

564564
PyObject *result;
565565
if (gen_send_ex2(gen, Py_None, &result, 1) == PYGEN_RETURN) {

Python/frame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame)
109109
/* It is the responsibility of the owning generator/coroutine
110110
* to have cleared the enclosing generator, if any. */
111111
assert(frame->owner != FRAME_OWNED_BY_GENERATOR ||
112-
_PyGen_GetGeneratorFromFrame(frame)->gi_frame_state == FRAME_CLEARED);
112+
FT_ATOMIC_LOAD_INT8_RELAXED(_PyGen_GetGeneratorFromFrame(frame)->gi_frame_state) == FRAME_CLEARED);
113113
// GH-99729: Clearing this frame can expose the stack (via finalizers). It's
114114
// crucial that this frame has been unlinked, and is no longer visible:
115115
assert(_PyThreadState_GET()->current_frame != frame);

0 commit comments

Comments
 (0)