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

ffi: prevent segfault with datetime bindings #1563

Merged
merged 1 commit into from
Apr 18, 2021

Conversation

davidhewitt
Copy link
Member

This fixes a segfault achievable entirely in safe Rust:

fn main() {
    assert!(pyo3::ffi::PyDateTimeAPI.DateType == std::ptr::null_mut())
}

The Deref implementation for PyDateTimeAPI can call Python APIs, but before this PR it didn't check whether the GIL is actually held.

Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +441 to +445
/// this is implemented as a wrapper which implements [`Deref`] to access a reference to a
/// [`PyDateTime_CAPI`] object.
///
/// In the [`Deref`] implementation, if the underlying object has not yet been initialized, the GIL
/// will automatically be acquired and [`PyDateTime_IMPORT()`] called.
Copy link
Member

Choose a reason for hiding this comment

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

Are these correctly linked?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I checked in the docs locally🚀

@davidhewitt davidhewitt merged commit 6bfca27 into PyO3:main Apr 18, 2021
@davidhewitt davidhewitt deleted the safer-datetime-ffi branch April 19, 2021 06:51
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