3131: Extend lifetime of GIL token associated with PyRef(Mut). r=mejrs a=adamreichold



Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
This commit is contained in:
bors[bot] 2023-05-04 11:46:09 +00:00 committed by GitHub
commit 22e77b0213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -0,0 +1 @@
Extend the lifetime of the GIL token returned by `PyRef::py` and `PyRefMut::py` to match the underlying borrow.

View File

@ -583,8 +583,8 @@ pub struct PyRef<'p, T: PyClass> {
impl<'p, T: PyClass> PyRef<'p, T> { impl<'p, T: PyClass> PyRef<'p, T> {
/// Returns a `Python` token that is bound to the lifetime of the `PyRef`. /// Returns a `Python` token that is bound to the lifetime of the `PyRef`.
pub fn py(&self) -> Python<'_> { pub fn py(&self) -> Python<'p> {
unsafe { Python::assume_gil_acquired() } self.inner.py()
} }
} }
@ -706,8 +706,8 @@ pub struct PyRefMut<'p, T: PyClass<Frozen = False>> {
impl<'p, T: PyClass<Frozen = False>> PyRefMut<'p, T> { impl<'p, T: PyClass<Frozen = False>> PyRefMut<'p, T> {
/// Returns a `Python` token that is bound to the lifetime of the `PyRefMut`. /// Returns a `Python` token that is bound to the lifetime of the `PyRefMut`.
pub fn py(&self) -> Python<'_> { pub fn py(&self) -> Python<'p> {
unsafe { Python::assume_gil_acquired() } self.inner.py()
} }
} }