Add fallback implementation of PyCriticalSection_BeginMutex for Python 3.13t#5981
Add fallback implementation of PyCriticalSection_BeginMutex for Python 3.13t#5981XuehaiPan wants to merge 16 commits intopybind:masterfrom
PyCriticalSection_BeginMutex for Python 3.13t#5981Conversation
include/pybind11/detail/internals.h
Outdated
| # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x030E00C1 // 3.14.0rc1 | ||
| PyCriticalSection_BeginMutex(&cs, &mutex.mutex); | ||
| # else | ||
| _PyCriticalSection_BeginMutex(_PyThreadState_GET(), &cs, &mutex.mutex); |
There was a problem hiding this comment.
I don't think this will compile on 3.13 without additional changes. _PyCriticalSection_BeginMutex is in an inline function in an internal-only header (pycore_critical_section.h).
I think we should use PyAPI_FUNC(void) _PyCriticalSection_BeginSlow(PyCriticalSection *c, PyMutex *m); instead. It's not inline, but you'll need to declare it above.
There was a problem hiding this comment.
Also, we'll still have the race condition with py::make_key_iterator in 3.13 due to the critical section implementation behaving differently in 3.13, but otherwise it should preserve compatibility.
There was a problem hiding this comment.
Also, we'll still have the race condition with
py::make_key_iteratorin 3.13 due to the critical section implementation behaving differently in 3.13, but otherwise it should preserve compatibility.
I think that's OK. We just want to limp through enough to make the pybind11 v3.0.2 release without breaking what worked with Python 3.13t before.
PyCriticalSection_BeginMutex for Python 3.13tPyCriticalSection_BeginMutex for Python 3.13t
`_PyCriticalSection_BeginSlow` is a private CPython function not exported on Linux. For Python < 3.14.0rc1, use direct `mutex.lock()`/`mutex.unlock()` instead of critical section APIs.
Description
Fix #5971 (comment)
Suggested changelog entry: