]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-137992: Stop the world when calling PyRefTracer_SetTracer (#137994)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Mon, 15 Sep 2025 10:39:41 +0000 (11:39 +0100)
committerGitHub <noreply@github.com>
Mon, 15 Sep 2025 10:39:41 +0000 (10:39 +0000)
Misc/NEWS.d/next/Core_and_Builtins/2025-08-20-14-17-47.gh-issue-137992.fcL3SK.rst [new file with mode: 0644]
Objects/object.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-08-20-14-17-47.gh-issue-137992.fcL3SK.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-20-14-17-47.gh-issue-137992.fcL3SK.rst
new file mode 100644 (file)
index 0000000..068f041
--- /dev/null
@@ -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
index 2c07c2e9841b0d4d662ccef7f806865040b06ba3..c9bcc0c7b09e639d61825dc63dd78a47f986e4f6 100644 (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;
 }