gh-137992: Stop the world when calling PyRefTracer_SetTracer (#137994)

This commit is contained in:
Pablo Galindo Salgado 2025-09-15 11:39:41 +01:00 committed by GitHub
parent 2d724939d7
commit c5180d74e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View file

@ -0,0 +1,2 @@
Ensure that :c:func:`PyRefTracer_SetTracer` sync with all existing threads when called
to avoid races in the free threaded build. Patch by Pablo Galindo

View file

@ -3287,6 +3287,8 @@ _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
int PyRefTracer_SetTracer(PyRefTracer tracer, void *data) {
_Py_AssertHoldsTstate();
_PyEval_StopTheWorldAll(&_PyRuntime);
if (_PyRuntime.ref_tracer.tracer_func != NULL) {
_PyReftracerTrack(NULL, PyRefTracer_TRACKER_REMOVED);
if (PyErr_Occurred()) {
@ -3295,6 +3297,7 @@ int PyRefTracer_SetTracer(PyRefTracer tracer, void *data) {
}
_PyRuntime.ref_tracer.tracer_func = tracer;
_PyRuntime.ref_tracer.tracer_data = data;
_PyEval_StartTheWorldAll(&_PyRuntime);
return 0;
}