Repository navigation
Scaffolding for cpython-api crate #63
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
Open
cjames23
wants to merge
4
commits into
Rust-for-CPython:3.x-rust-in-cpython
Choose a base branch
from
pythonomenology:cpython-api-scaffold
base: 3.x-rust-in-cpython
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−575
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
250b77a
feat: initial scaffolding for cpython-api crate
cjames23 5e7dff1
Add scaffolding for cpython-api crate.
cjames23 16293d6
Remove _Base64 and c_api for now until we are ready for it.
cjames23 ce37614
Update Tools/build/generate_stdlib_module_names.py
cjames23 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,16 @@ | ||
| [package] | ||
| name = "cpython-api" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| rust-version.workspace = true | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| cpython-sys = { path = "../cpython-sys" } | ||
|
|
||
| [lints.rust] | ||
| unsafe_op_in_unsafe_fn = "deny" | ||
|
|
||
| [lints.clippy] | ||
| undocumented_unsafe_blocks = "deny" | ||
| missing_safety_doc = "deny" | ||
This file contains hidden or 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,5 @@ | ||
| //! Safe Rust API for in-tree CPython extension modules. | ||
|
|
||
| mod object; | ||
|
|
||
| pub use object::PyAny; |
This file contains hidden or 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,24 @@ | ||
| use std::cell::UnsafeCell; | ||
|
|
||
| use cpython_sys::PyObject; | ||
|
|
||
| #[repr(transparent)] | ||
| pub struct PyAny(UnsafeCell<PyObject>); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::mem::{align_of, size_of}; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn layout_matches_pyobject() { | ||
| assert_eq!(size_of::<PyAny>(), size_of::<PyObject>()); | ||
| assert_eq!(align_of::<PyAny>(), align_of::<PyObject>()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn pointer_layout_matches_pyobject() { | ||
| assert_eq!(size_of::<*mut PyAny>(), size_of::<*mut PyObject>()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| pub use _base64::PyInit__base64; | ||
|
|
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.
Do we want the same policy across all Rust crates: unsafe operations must be explicit, unsafe blocks documented, and unsafe public APIs must explain their safety requirements?
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.
Yes, I think so, with the possible exception of cpython-sys since that is all bindings.
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.
I agree with Emma.