]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154044: Fix data race on descriptor __qualname__ in free-threading build (#154691)
authorTimofei Ivankov <128279579+deadlovelll@users.noreply.github.com>
Tue, 4 Aug 2026 09:24:02 +0000 (12:24 +0300)
committerGitHub <noreply@github.com>
Tue, 4 Aug 2026 09:24:02 +0000 (14:54 +0530)
Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-12-44-13.gh-issue-154044.GBa2wP.rst [new file with mode: 0644]
Objects/descrobject.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-12-44-13.gh-issue-154044.GBa2wP.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-12-44-13.gh-issue-154044.GBa2wP.rst
new file mode 100644 (file)
index 0000000..7338ae0
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a data race on a descriptor's ``__qualname__`` cache in the
+:term:`free-threaded build`.
index 568d978d27d12f944112282f27d8502dcf307ada..8ceef6489881679f4f5ff61d62b6e7013c3c297a 100644 (file)
@@ -621,9 +621,17 @@ static PyObject *
 descr_get_qualname(PyObject *self, void *Py_UNUSED(ignored))
 {
     PyDescrObject *descr = (PyDescrObject *)self;
-    if (descr->d_qualname == NULL)
-        descr->d_qualname = calculate_qualname(descr);
-    return Py_XNewRef(descr->d_qualname);
+    PyObject *qualname;
+    Py_BEGIN_CRITICAL_SECTION(self);
+    if (descr->d_qualname == NULL) {
+        PyObject *new_qualname = calculate_qualname(descr);
+        if (new_qualname != NULL) {
+            Py_XSETREF(descr->d_qualname, new_qualname);
+        }
+    }
+    qualname = Py_XNewRef(descr->d_qualname);
+    Py_END_CRITICAL_SECTION();
+    return qualname;
 }
 
 static PyObject *