Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "3"
members = [
"Modules/_base64", "Modules/cpython-build-helper", "Modules/cpython-rust-staticlib",
"Modules/cpython-api", "Modules/cpython-build-helper", "Modules/cpython-rust-staticlib",
"Modules/cpython-sys"
]

Expand Down
1 change: 0 additions & 1 deletion Modules/Setup
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ PYTHONPATH=$(COREPYTHONPATH)
#_codecs_tw cjkcodecs/_codecs_tw.c
#_multibytecodec cjkcodecs/multibytecodec.c
#unicodedata unicodedata.c
#_base64 _base64/Cargo.toml _base64/src/lib.rs lib_base64.a

# Modules with some UNIX dependencies

Expand Down
1 change: 0 additions & 1 deletion Modules/Setup.stdlib.in
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
############################################################################
# Rust modules
#
@MODULE__BASE64_TRUE@_base64 _base64/Cargo.toml _base64/src/lib.rs

############################################################################
# Modules with some UNIX dependencies
Expand Down
16 changes: 0 additions & 16 deletions Modules/_base64/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions Modules/_base64/build.rs

This file was deleted.

249 changes: 0 additions & 249 deletions Modules/_base64/src/lib.rs

This file was deleted.

16 changes: 16 additions & 0 deletions Modules/cpython-api/Cargo.toml
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"
Comment on lines +11 to +16

Copy link
Copy Markdown

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?

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Emma.

5 changes: 5 additions & 0 deletions Modules/cpython-api/src/lib.rs
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;
24 changes: 24 additions & 0 deletions Modules/cpython-api/src/object.rs
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>());
}
}
1 change: 0 additions & 1 deletion Modules/cpython-rust-staticlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2024"
rust-version.workspace = true

[dependencies]
_base64 ={ path = "../_base64" }

[lib]
name = "cpython_rust_staticlib"
Expand Down
2 changes: 1 addition & 1 deletion Modules/cpython-rust-staticlib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub use _base64::PyInit__base64;

Loading