https://github.com/python/cpython/commit/38c3f112c383d1f61a3e2d2d4ff589a5ca570944 commit: 38c3f112c383d1f61a3e2d2d4ff589a5ca570944 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: nascheme <[email protected]> date: 2026-07-16T11:59:43-07:00 summary:
[3.15] gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164) (gh-153814) 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 <[email protected]> files: A Misc/NEWS.d/next/Core_and_Builtins/2026-04-29-15-10-59.gh-issue-149162.BPPyrq.rst M 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 index 00000000000000..b4c443ecee07ad --- /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 18523c2dfde77e..c3a1beee0c8a5e 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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); _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
