-
Notifications
You must be signed in to change notification settings - Fork 805
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
Remove the BoundObject
impl for &Bound
, use Borrowed
instead
#4487
Merged
davidhewitt
merged 2 commits into
PyO3:main
from
ChayimFriedman2:remove-impl-boundobject-for-ref-bound
Aug 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Remove the `BoundObject` impl for `&Bound`, use `Borrowed` instead. For rationale see https://github.com/PyO3/pyo3/issues/4467. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ use std::ops::Deref; | |
use std::ptr::NonNull; | ||
|
||
/// Owned or borrowed gil-bound Python smart pointer | ||
/// | ||
/// This is implemented for [`Bound`] and [`Borrowed`]. | ||
pub trait BoundObject<'py, T>: bound_object_sealed::Sealed { | ||
/// Type erased version of `Self` | ||
type Any: BoundObject<'py, PyAny>; | ||
|
@@ -32,11 +34,15 @@ pub trait BoundObject<'py, T>: bound_object_sealed::Sealed { | |
} | ||
|
||
mod bound_object_sealed { | ||
pub trait Sealed {} | ||
/// # Safety | ||
/// | ||
/// Type must be layout-compatible with `*mut ffi::PyObject`. | ||
pub unsafe trait Sealed {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep I'm happy with the |
||
|
||
impl<'py, T> Sealed for super::Bound<'py, T> {} | ||
impl<'a, 'py, T> Sealed for &'a super::Bound<'py, T> {} | ||
impl<'a, 'py, T> Sealed for super::Borrowed<'a, 'py, T> {} | ||
// SAFETY: `Bound` is layout-compatible with `*mut ffi::PyObject`. | ||
unsafe impl<'py, T> Sealed for super::Bound<'py, T> {} | ||
// SAFETY: `Borrowed` is layout-compatible with `*mut ffi::PyObject`. | ||
unsafe impl<'a, 'py, T> Sealed for super::Borrowed<'a, 'py, T> {} | ||
} | ||
|
||
/// A GIL-attached equivalent to [`Py<T>`]. | ||
|
@@ -614,30 +620,6 @@ impl<'py, T> BoundObject<'py, T> for Bound<'py, T> { | |
} | ||
} | ||
|
||
impl<'a, 'py, T> BoundObject<'py, T> for &'a Bound<'py, T> { | ||
type Any = &'a Bound<'py, PyAny>; | ||
|
||
fn as_borrowed(&self) -> Borrowed<'a, 'py, T> { | ||
Bound::as_borrowed(self) | ||
} | ||
|
||
fn into_bound(self) -> Bound<'py, T> { | ||
self.clone() | ||
} | ||
|
||
fn into_any(self) -> Self::Any { | ||
self.as_any() | ||
} | ||
|
||
fn into_ptr(self) -> *mut ffi::PyObject { | ||
self.clone().into_ptr() | ||
} | ||
|
||
fn unbind(self) -> Py<T> { | ||
self.clone().unbind() | ||
} | ||
} | ||
|
||
/// A borrowed equivalent to `Bound`. | ||
/// | ||
/// The advantage of this over `&Bound` is that it avoids the need to have a pointer-to-pointer, as Bound | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this as
BoundObject
is new in this release; users will never see this change.