]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-150858: fix data race while changing `__qualname__` of a type object(#150859)
authorThomas Kowalski <thom.kowa@gmail.com>
Thu, 11 Jun 2026 15:07:36 +0000 (17:07 +0200)
committerGitHub <noreply@github.com>
Thu, 11 Jun 2026 15:07:36 +0000 (15:07 +0000)
Misc/NEWS.d/next/Core_and_Builtins/2026-06-03-16-27-00.gh-issue-150858.j2dSkD.rst [new file with mode: 0644]
Objects/typeobject.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-03-16-27-00.gh-issue-150858.j2dSkD.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-03-16-27-00.gh-issue-150858.j2dSkD.rst
new file mode 100644 (file)
index 0000000..dcb932b
--- /dev/null
@@ -0,0 +1 @@
+Fix a data race while changing ``__qualname__`` of a type concurrently on free-threaded builds.
index e0464fe6475cfd2ff96a151020de809490f74c93..de5bb5f1f2a0df0e574dba514b05c86514fa79a7 100644 (file)
@@ -1594,7 +1594,12 @@ type_set_qualname(PyObject *tp, PyObject *value, void *context)
     }
 
     et = (PyHeapTypeObject*)type;
-    Py_SETREF(et->ht_qualname, Py_NewRef(value));
+    PyInterpreterState *interp = _PyInterpreterState_GET();
+    _PyEval_StopTheWorld(interp);
+    PyObject *old_qualname = et->ht_qualname;
+    et->ht_qualname = Py_NewRef(value);
+    _PyEval_StartTheWorld(interp);
+    Py_DECREF(old_qualname);
     return 0;
 }