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

fix case of gil-refs feature breaking create_exception! macro #4589

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

davidhewitt
Copy link
Member

Note: this is a patch fix for 0.22.4, the PR is targeting that branch, not main.

Fixes #4562

The bug is that the macros to set up all the traits for native types expand to use #[cfg(feature = "gil-refs")] inside the expanded code, which doesn't work properly in downstream crates.

The solution is to split the macro definitions so that they have gil-refs and non-gil-refs versions.

I verified this works manually; I couldn't think of a good testing strategy for the bug in question besides making yet another test crate. For a patch fix it didn't seem worth it.

@davidhewitt davidhewitt mentioned this pull request Oct 2, 2024
Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +188 to +202
impl<$($generics,)*> ::std::convert::AsRef<$crate::PyAny> for $name {
#[inline]
fn as_ref(&self) -> &$crate::PyAny {
&self.0
}
}

impl<$($generics,)*> ::std::ops::Deref for $name {
type Target = $crate::PyAny;

#[inline]
fn deref(&self) -> &$crate::PyAny {
&self.0
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these any useful without gil-refs?

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 don't think so, in general I think it's helpful to not have the structure of the type objects be constrained by AsRef / Deref.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I see what you mean, I've duplicated too much here. Will fix later!

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually we still have AsRef / Deref here in this macro on main, maybe we could remove later (i.e. in 0.23 or later) but I think we have to leave these here in this PR for the patch fix. AsPyPointer (just below) should be removed though, I pushed that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, removing them from main makes sense. I don't think these can ever be used now, because there is no way to construct a literal PyAny (or similar)

@davidhewitt davidhewitt merged commit b01f99a into PyO3:release-0.22.4 Oct 4, 2024
4 of 5 checks passed
@davidhewitt davidhewitt deleted the gil-refs-macros branch October 4, 2024 09:10
davidhewitt added a commit that referenced this pull request Oct 12, 2024
* fix case of gil-refs feature breaking `create_exception!` macro

* remove `AsPyPointer` on non-gil-refs
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