From: Sam Gross Date: Thu, 16 Jul 2026 17:37:00 +0000 (-0700) Subject: gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f62050d65743f0c895f7e6d665936c4e86aa39d5;p=thirdparty%2FPython%2Fcpython.git gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164) Avoids potential deadlocks with C++ static local initialization in extensions that call PyUnicode_InternFromString during one-time initialization. --- 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 index 000000000000..b4c443ecee07 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-29-15-10-59.gh-issue-149162.BPPyrq.rst @@ -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. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 47cb7684eab8..6562546ae2f9 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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);