Skip to content

Initial sketch of a Rust API for CPython#41

Draft
emmatyping wants to merge 1 commit into
3.x-rust-in-cpythonfrom
emmatyping/3.x-rust-api-proof-of-concept
Draft

Initial sketch of a Rust API for CPython#41
emmatyping wants to merge 1 commit into
3.x-rust-in-cpythonfrom
emmatyping/3.x-rust-api-proof-of-concept

Conversation

@emmatyping

Copy link
Copy Markdown

Opening in draft as I plan on iterating on this more, but if people want to take a look and provide feedback I think it is in a state where that would be useful.

This is a rough sketch of a Rust API for CPython. The overall design goals are

  1. Should be very similar to PyO3 API
  2. Threadstate should be passed explicitly to ensure safety
  3. Should feel familiar to C API users
  4. If a C API for something is missing, we can add new internal C APIs (e.g. an operation where we need to pass the threadstate explicitly where it is fetched implicitly from TLS)
  5. Should be minimal to what we need, we are not re-implementing all of PyO3

This is still a work in progress so things are still subject to change significantly.

I worked with Fable on this initial draft. I will probably iterate from this baseline over the next week.

This commit introduces a rough sketch of a Rust API for CPython. The overall design goals are
1. Should be very similar to PyO3 API
2. Threadstate should be passed explicitly to ensure safety
3. Should feel familiar to C API users
4. If a C API for something is missing, we can add new internal C APIs (e.g. an operation where we need to pass the threadstate explicitly where it is fetched implicitly from TLS)
5. Should be minimal to what we need, we are not re-implementing all of PyO3

This is still a work in progress so things are still subject to change significantly.
@@ -0,0 +1,273 @@
//! The single raw-call layer.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FWIW, I think its easy to misread this file as being syscalls (like OS-syscalls). I don't have a particular suggestion, but I think a different name might make more sense.

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.

Agreed, I will probably rename it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants