]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164) (gh-153814)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 16 Jul 2026 18:59:43 +0000 (20:59 +0200)
committerGitHub <noreply@github.com>
Thu, 16 Jul 2026 18:59:43 +0000 (11:59 -0700)
Avoids potential deadlocks with C++ static local initialization in
extensions that call PyUnicode_InternFromString during one-time
initialization.

(cherry picked from commit f62050d65743f0c895f7e6d665936c4e86aa39d5)

Co-authored-by: Sam Gross <colesbury@gmail.com>
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 18523c2dfde77e974df5255caffec9b41a6ac4dd..c3a1beee0c8a5e7bd674076493390e7248d4e9a4 100644 (file)
@@ -14344,7 +14344,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);