Skip to content

Commit c5180d7

Browse files
authored
gh-137992: Stop the world when calling PyRefTracer_SetTracer (#137994)
1 parent 2d72493 commit c5180d7

File tree

2 files changed

+5
-0
lines changed

2 files changed

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

Objects/object.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,8 @@ _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
32873287

32883288
int PyRefTracer_SetTracer(PyRefTracer tracer, void *data) {
32893289
_Py_AssertHoldsTstate();
3290+
3291+
_PyEval_StopTheWorldAll(&_PyRuntime);
32903292
if (_PyRuntime.ref_tracer.tracer_func != NULL) {
32913293
_PyReftracerTrack(NULL, PyRefTracer_TRACKER_REMOVED);
32923294
if (PyErr_Occurred()) {
@@ -3295,6 +3297,7 @@ int PyRefTracer_SetTracer(PyRefTracer tracer, void *data) {
32953297
}
32963298
_PyRuntime.ref_tracer.tracer_func = tracer;
32973299
_PyRuntime.ref_tracer.tracer_data = data;
3300+
_PyEval_StartTheWorldAll(&_PyRuntime);
32983301
return 0;
32993302
}
33003303

0 commit comments

Comments
 (0)