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

Extend lifetime of GIL token associated with PyRef(Mut). #3131

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/3131.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Extend the lifetime of the GIL token returned by `PyRef::py` and `PyRefMut::py` to match the underlying borrow.
8 changes: 4 additions & 4 deletions src/pycell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ pub struct PyRef<'p, T: PyClass> {

impl<'p, T: PyClass> PyRef<'p, T> {
/// Returns a `Python` token that is bound to the lifetime of the `PyRef`.
adamreichold marked this conversation as resolved.
Show resolved Hide resolved
pub fn py(&self) -> Python<'_> {
unsafe { Python::assume_gil_acquired() }
pub fn py(&self) -> Python<'p> {
self.inner.py()
}
}

Expand Down Expand Up @@ -706,8 +706,8 @@ pub struct PyRefMut<'p, T: PyClass<Frozen = False>> {

impl<'p, T: PyClass<Frozen = False>> PyRefMut<'p, T> {
/// Returns a `Python` token that is bound to the lifetime of the `PyRefMut`.
adamreichold marked this conversation as resolved.
Show resolved Hide resolved
pub fn py(&self) -> Python<'_> {
unsafe { Python::assume_gil_acquired() }
pub fn py(&self) -> Python<'p> {
self.inner.py()
}
}

Expand Down