-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial free threaded bindings #4421
Merged
Merged
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2685691
add support in pyo3-build-config for free-threaded python
ngoldbaum e8613d5
update object.h bindings for free-threaded build
ngoldbaum eeac20c
Add PyMutex bindings
ngoldbaum 8eebe43
fix po3-ffi-check with free-threaded build
ngoldbaum 9e9d77e
error when building with limited api and Py_GIL_DISABLED
ngoldbaum 79dd1a7
Add CI job for free-threaded build
ngoldbaum 5aaa03a
fix issues building on older pythons
ngoldbaum f4219b3
ci config fixup
ngoldbaum 4ff9a62
fix clippy on gil-enabled 3.13 build
ngoldbaum 57e7e3d
Apply suggestions from code review
ngoldbaum a042e56
make PyMutex and PyObject refcounting fields atomics
ngoldbaum 7c493eb
add new field on PyConfig in 3.13 debug ABI
ngoldbaum da3e50c
warn and disable abi3 on gil-disabled build
ngoldbaum 77b4d96
fix conditional compilation for PyMutex usage
ngoldbaum 96dd13e
temporarily skip test that deadlocks
ngoldbaum dbcb9d2
remove Py_GIL_DISABLED from py_sys_config cfg options
ngoldbaum d9dac3c
only expose PyMutex in 3.13
ngoldbaum 9b70b07
make PyObject_HEAD_INIT a function
ngoldbaum 3e03dd1
intialize ob_ref_local to _Py_IMMORTAL_REFCNT_LOCAL in HEAD_INIT
ngoldbaum f695203
Fix clippy lint about static with interior mutability
ngoldbaum 848c793
add TODO comments about INCREF and DECREF in free-threaded build
ngoldbaum 6e66cb0
make the _bits field of PyMutex pub(crate)
ngoldbaum 126c97b
refactor so HEAD_INIT remains a constant
ngoldbaum 162a65e
ignore clippy lint about interior mutability
ngoldbaum 6103d26
revert unnecessary changes to pyo3-build-config
ngoldbaum 8a9ef2d
add changelog entries
ngoldbaum e1ddd01
use derive(Debug) for PyMutex
ngoldbaum 1a088ea
Add PhantomPinned field to PyMutex bindings
ngoldbaum 38bc492
Update pyo3-build-config/src/impl_.rs
ngoldbaum a85fa4c
Update pyo3-ffi/src/object.rs
ngoldbaum 60c26c4
fix build config again
ngoldbaum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,18 @@ | ||
use std::fmt; | ||
use std::sync::atomic::AtomicU8; | ||
|
||
#[repr(C)] | ||
pub struct PyMutex { | ||
ngoldbaum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_bits: AtomicU8, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at Rust's built-in mutex types, I think we'd want a constructor like: impl PyMutex {
pub const fn new() -> PyMutex {
PyMutex { _bits: AtomicU8::new(0) }
}
} |
||
|
||
impl fmt::Debug for PyMutex { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_struct("PyMutex").finish() | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a |
||
|
||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool to see this job running, thanks 🙏