Skip to content

Commit f62050d

Browse files
authored
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.
1 parent b090d06 commit f62050d

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a potential deadlock in :c:func:`PyUnicode_InternFromString` and other
2+
interning functions in the :term:`free-threaded build` when called from C++
3+
static local initializers.

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14722,7 +14722,7 @@ intern_common(PyInterpreterState *interp, PyObject *s /* stolen */,
1472214722
}
1472314723
#endif
1472414724

14725-
FT_MUTEX_LOCK(INTERN_MUTEX);
14725+
FT_MUTEX_LOCK_FLAGS(INTERN_MUTEX, _Py_LOCK_DONT_DETACH);
1472614726
PyObject *t;
1472714727
{
1472814728
int res = PyDict_SetDefaultRef(interned, s, s, &t);

0 commit comments

Comments
 (0)