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

This commit is contained in:
Adam Reichold 2023-05-01 20:55:48 +02:00
parent f9cb5e5cb0
commit 63a9093510
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> {
/// 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()
}
}
@ -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()
}
}