]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164)
authorSam Gross <colesbury@gmail.com>
Thu, 16 Jul 2026 17:37:00 +0000 (10:37 -0700)
committerGitHub <noreply@github.com>
Thu, 16 Jul 2026 17:37:00 +0000 (10:37 -0700)
Avoids potential deadlocks with C++ static local initialization in
extensions that call PyUnicode_InternFromString during one-time
initialization.

Misc/NEWS.d/next/Core_and_Builtins/2026-04-29-15-10-59.gh-issue-149162.BPPyrq.rst [new file with mode: 0644]
Objects/unicodeobject.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-29-15-10-59.gh-issue-149162.BPPyrq.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-29-15-10-59.gh-issue-149162.BPPyrq.rst
new file mode 100644 (file)
index 0000000..b4c443e
--- /dev/null
@@ -0,0 +1,3 @@
+Fix a potential deadlock in :c:func:`PyUnicode_InternFromString` and other
+interning functions in the :term:`free-threaded build` when called from C++
+static local initializers.
index 47cb7684eab85feae5ea78ce8d455b8473f6e8c1..6562546ae2f9ccb81fcefc7d058be9c28618b68c 100644 (file)
@@ -14722,7 +14722,7 @@ intern_common(PyInterpreterState *interp, PyObject *s /* stolen */,
     }
 #endif
 
-    FT_MUTEX_LOCK(INTERN_MUTEX);
+    FT_MUTEX_LOCK_FLAGS(INTERN_MUTEX, _Py_LOCK_DONT_DETACH);
     PyObject *t;
     {
         int res = PyDict_SetDefaultRef(interned, s, s, &t);