Add fallback implementation of PyCriticalSection_BeginMutex for Python 3.13t (#5981)

* Add failback implementation of `PyCriticalSection_BeginMutex` for Python 3.13t

* Add comment for Python version

* Use `_PyCriticalSection_BeginSlow`

* Add forward declaration

* Fix forward declaration

* Remove always true condition `defined(PY_VERSION_HEX)`

* Detect musllinux

* Add manylinux test

* Use direct mutex locking 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.

* Empty commit to trigger CI

* Empty commit to trigger CI

* Empty commit to trigger CI

* Run apt update before apt install

* Remove unnecessary prefix

* Add manylinux test with Python 3.13t

* Simplify pycritical_section with std::unique_lock fallback for Python < 3.14

* Fix potential deadlock in make_iterator_impl for Python 3.13t

Refactor pycritical_section into a unified class with internal version
checks instead of using a type alias fallback. Skip locking in
make_iterator_impl for Python < 3.14.0rc1 to avoid deadlock during
type registration, as pycritical_section cannot release the mutex
during Python callbacks without PyCriticalSection_BeginMutex.

* Add reference for xfail message
This commit is contained in:
Xuehai Pan
2026-02-10 13:14:07 +08:00
committed by GitHub
parent 5f2c678916
commit 3ae5a173c5
6 changed files with 52 additions and 5 deletions

View File

@@ -237,11 +237,23 @@ jobs:
manylinux:
name: Manylinux on 🐍 3.14t
name: Manylinux on 🐍 ${{ matrix.python-version }} (${{ matrix.container }})
if: github.event.pull_request.draft == false
strategy:
fail-fast: false
matrix:
include:
- container: quay.io/pypa/manylinux_2_28_x86_64:latest
python-version: '3.13t'
- container: quay.io/pypa/musllinux_1_2_x86_64:latest
python-version: '3.13t'
- container: quay.io/pypa/manylinux_2_28_x86_64:latest
python-version: '3.14t'
- container: quay.io/pypa/musllinux_1_2_x86_64:latest
python-version: '3.14t'
runs-on: ubuntu-latest
timeout-minutes: 40
container: quay.io/pypa/musllinux_1_2_x86_64:latest
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@v6
with:
@@ -254,7 +266,7 @@ jobs:
run: uv tool install ninja
- name: Configure via preset
run: cmake --preset venv -DPYBIND11_CREATE_WITH_UV=python3.14t
run: cmake --preset venv -DPYBIND11_CREATE_WITH_UV="${{ matrix.python-version }}"
- name: Build C++11
run: cmake --build --preset venv

View File

@@ -44,7 +44,7 @@ jobs:
- name: Setup Boost (Linux)
if: runner.os == 'Linux'
run: sudo apt-get install libboost-dev
run: sudo apt-get update && sudo apt-get install -y libboost-dev
- name: Setup Boost (macOS)
if: runner.os == 'macOS'