Skip to content

Commit 572411b

Browse files
committed
gh-137992: Stop the world when calling PyRefTracer_SetTracer and PyRefTracer_GetTracer
1 parent 7685b8a commit 572411b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ensure that :c:func:`PyRefTracer_SetTracer` and
2+
:c:func:`PyRefTracer_GetTracer` sync with all existing threads when called
3+
to avoid races in the free threaded build. Patch by Pablo Galindo

Objects/object.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3286,17 +3286,22 @@ _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
32863286

32873287
int PyRefTracer_SetTracer(PyRefTracer tracer, void *data) {
32883288
_Py_AssertHoldsTstate();
3289+
_PyEval_StopTheWorldAll(&_PyRuntime);
32893290
_PyRuntime.ref_tracer.tracer_func = tracer;
32903291
_PyRuntime.ref_tracer.tracer_data = data;
3292+
_PyEval_StartTheWorldAll(&_PyRuntime);
32913293
return 0;
32923294
}
32933295

32943296
PyRefTracer PyRefTracer_GetTracer(void** data) {
32953297
_Py_AssertHoldsTstate();
3298+
_PyEval_StopTheWorldAll(&_PyRuntime);
32963299
if (data != NULL) {
32973300
*data = _PyRuntime.ref_tracer.tracer_data;
32983301
}
3299-
return _PyRuntime.ref_tracer.tracer_func;
3302+
PyRefTracer tracer = _PyRuntime.ref_tracer.tracer_func;
3303+
_PyEval_StartTheWorldAll(&_PyRuntime);
3304+
return tracer;
33003305
}
33013306

33023307

0 commit comments

Comments
 (0)