Skip to content

Commit

Permalink
Merge #3131
Browse files Browse the repository at this point in the history
3131: Extend lifetime of GIL token associated with PyRef(Mut). r=mejrs a=adamreichold



Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
  • Loading branch information
bors[bot] and adamreichold authored May 4, 2023
2 parents 6356acb + 63a9093 commit 22e77b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
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`.
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`.
pub fn py(&self) -> Python<'_> {
unsafe { Python::assume_gil_acquired() }
pub fn py(&self) -> Python<'p> {
self.inner.py()
}
}

Expand Down

0 comments on commit 22e77b0

Please sign in to comment.