gh-138794: Communicate to PyRefTracer when they are being replaced (#138797)

This commit is contained in:
Pablo Galindo Salgado
2025-09-15 11:12:09 +01:00
committed by GitHub
parent baf7470515
commit f01181b595
5 changed files with 54 additions and 9 deletions

View File

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