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

Move PyTypeInfo::AsRefTarget onto new trait HasPyGilBoundRef #2956

Closed
wants to merge 1 commit into from

Conversation

davidhewitt
Copy link
Member

NB This is a breaking change, would be part of 0.19, not any 0.18.x patch release. Despite this, I would generally assume users don't ever refer to this directly, so I don't expect much impact downstream.

This PR moves PyTypeInfo::AsRefTarget onto its own trait. There's a couple of reasons for this:

  • PyIterator, PySequence and PyMapping can implement the new trait (they can't implement PyTypeInfo). This removes the need for them to provide special-cased methods.
  • While looking at rebooting experimental: owned objects API #1308, I found that this is the only item in PyTypeInfo which the experimental types cannot implement. So if we break this up, I think it will simplify that implementation.

(Maybe we can wait until I push the rebooted #1308 proposal, to see whether we actually like it enough to try to adopt it.)

/// # Safety
/// `Py<T>` will hand out references to `Self::AsRefTarget`. This _must_ have the
/// same layout as `*mut ffi::PyObject`.
pub unsafe trait HasPyGilBoundRef {
Copy link
Member

Choose a reason for hiding this comment

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

IMO the name could use some work. I don't have a name that is obviously good, but what about something like AsGilBorrow?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing. I think we can sit on this and think for a bit. I'm a bit lost for a good name too. StorableInPy?

Copy link
Member

@adamreichold adamreichold Feb 22, 2023

Choose a reason for hiding this comment

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

Just to add completely different colour for the bikeshed: PyHeapType meaning that can be stored on the Python heap (i.e. in Py<T>) and thereby shared references must be bound to the GIL (as it protects access to the heap).

Comment on lines +45 to +46
/// `Py<T>` will hand out references to `Self::AsRefTarget`. This _must_ have the
/// same layout as `*mut ffi::PyObject`.
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the layout part guaranteed by PyNativeType? Unless "this" refers to Self rather than the target.

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 think so. Probably still worth repeating this constraint here?

Copy link
Member

Choose a reason for hiding this comment

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

Sure 👍

@davidhewitt
Copy link
Member Author

It looks like we don't need this / will remove it with #3382 so I'll close this.

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.

3 participants