-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial free threaded bindings (#4421)
* add support in pyo3-build-config for free-threaded python * update object.h bindings for free-threaded build * Add PyMutex bindings * fix po3-ffi-check with free-threaded build * error when building with limited api and Py_GIL_DISABLED * Add CI job for free-threaded build * fix issues building on older pythons * ci config fixup * fix clippy on gil-enabled 3.13 build * Apply suggestions from code review Co-authored-by: David Hewitt <[email protected]> * make PyMutex and PyObject refcounting fields atomics * add new field on PyConfig in 3.13 debug ABI * warn and disable abi3 on gil-disabled build * fix conditional compilation for PyMutex usage * temporarily skip test that deadlocks * remove Py_GIL_DISABLED from py_sys_config cfg options * only expose PyMutex in 3.13 * make PyObject_HEAD_INIT a function * intialize ob_ref_local to _Py_IMMORTAL_REFCNT_LOCAL in HEAD_INIT * Fix clippy lint about static with interior mutability * add TODO comments about INCREF and DECREF in free-threaded build * make the _bits field of PyMutex pub(crate) * refactor so HEAD_INIT remains a constant * ignore clippy lint about interior mutability * revert unnecessary changes to pyo3-build-config * add changelog entries * use derive(Debug) for PyMutex * Add PhantomPinned field to PyMutex bindings * Update pyo3-build-config/src/impl_.rs Co-authored-by: David Hewitt <[email protected]> * Update pyo3-ffi/src/object.rs Co-authored-by: David Hewitt <[email protected]> * fix build config again --------- Co-authored-by: David Hewitt <[email protected]>
- Loading branch information
1 parent
7b2cf24
commit f474810
Showing
14 changed files
with
182 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -489,6 +489,35 @@ jobs: | |
echo PYO3_CONFIG_FILE=$PYO3_CONFIG_FILE >> $GITHUB_ENV | ||
- run: python3 -m nox -s test | ||
|
||
test-free-threaded: | ||
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }} | ||
needs: [fmt] | ||
runs-on: ubuntu-latest | ||
env: | ||
UNSAFE_PYO3_BUILD_FREE_THREADED: 1 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: Swatinem/rust-cache@v2 | ||
with: | ||
save-if: ${{ github.event_name != 'merge_group' }} | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
components: rust-src | ||
# TODO: replace with setup-python when there is support | ||
- uses: deadsnakes/[email protected] | ||
with: | ||
python-version: '3.13-dev' | ||
nogil: true | ||
- run: python3 -m sysconfig | ||
- run: python3 -m pip install --upgrade pip && pip install nox | ||
- run: nox -s ffi-check | ||
- name: Run default nox sessions that should pass | ||
run: nox -s clippy docs rustfmt ruff | ||
- name: Run PyO3 tests with free-threaded Python (can fail) | ||
# TODO fix the test crashes so we can unset this | ||
continue-on-error: true | ||
run: nox -s test | ||
|
||
test-version-limits: | ||
needs: [fmt] | ||
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }} | ||
|
@@ -627,6 +656,7 @@ jobs: | |
- coverage | ||
- emscripten | ||
- test-debug | ||
- test-free-threaded | ||
- test-version-limits | ||
- check-feature-powerset | ||
- test-cross-compilation | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Added bindings for PyMutex. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Updated FFI bindings for free-threaded CPython 3.13 ABI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use std::marker::PhantomPinned; | ||
use std::sync::atomic::AtomicU8; | ||
|
||
#[repr(transparent)] | ||
#[derive(Debug)] | ||
pub struct PyMutex { | ||
pub(crate) _bits: AtomicU8, | ||
pub(crate) _pin: PhantomPinned, | ||
} | ||
|
||
extern "C" { | ||
pub fn PyMutex_Lock(m: *mut PyMutex); | ||
pub fn PyMutex_UnLock(m: *mut PyMutex); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters