]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164) (gh-153815)
authorNeil Schemenauer <nas-github@arctrix.com>
Thu, 16 Jul 2026 18:59:10 +0000 (11:59 -0700)
committerGitHub <noreply@github.com>
Thu, 16 Jul 2026 18:59:10 +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 e249473cd79e3b10ba6807a30c63b0d2950472f3..6bd9e7d607cc4143a5ba11b1bc8e952a387c5097 100644 (file)
@@ -113,7 +113,9 @@ NOTE: In the interpreter's initialization phase, some globals are currently
 #endif
 
 #ifdef Py_GIL_DISABLED
-#  define LOCK_INTERNED(interp) PyMutex_Lock(&_Py_INTERP_CACHED_OBJECT(interp, interned_mutex))
+#  define LOCK_INTERNED(interp) \
+    PyMutex_LockFlags(&_Py_INTERP_CACHED_OBJECT(interp, interned_mutex), \
+                      _Py_LOCK_DONT_DETACH)
 #  define UNLOCK_INTERNED(interp) PyMutex_Unlock(&_Py_INTERP_CACHED_OBJECT(interp, interned_mutex))
 #else
 #  define LOCK_INTERNED(interp)