Skip to content
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

Improve ffi example and make const PyMethodDef::zeroed #2583

Merged
merged 2 commits into from
Aug 23, 2022

Conversation

mejrs
Copy link
Member

@mejrs mejrs commented Aug 22, 2022

Rendered:
image
image
image

@@ -94,6 +94,19 @@ pub struct PyMethodDef {
pub ml_doc: *const c_char,
}

impl PyMethodDef {
pub const fn zeroed() -> PyMethodDef {
Copy link
Member Author

Choose a reason for hiding this comment

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

I found it quite annoying to make a terminating PyMethodDef in a static, this would make it easier. I'm all for a better idea :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah seems ok to me, it would be nice if std::mem::zeroed was const, but here we are 🙂

//! .as_ptr()
//! .cast::<c_char>(),
//! m_size: 0,
//! m_methods: unsafe { METHODS.as_mut_ptr().cast() },
Copy link
Member

Choose a reason for hiding this comment

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

👍 I'm hoping that #2367 can enable us to also use this member in #[pymodule].

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, definitely makes the ffi calls clearer and emphasises how much PyO3 can help 😄

@davidhewitt davidhewitt merged commit 554bc84 into PyO3:main Aug 23, 2022
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