Skip to content

Commit 962bc0d

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

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,16 +3286,20 @@ _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
}
3302+
_PyEval_StartTheWorldAll(&_PyRuntime);
32993303
return _PyRuntime.ref_tracer.tracer_func;
33003304
}
33013305

0 commit comments

Comments
 (0)