Skip to content

Commit 4baf023

Browse files
authored
Merge pull request #3616 from neachdainn/3615-gilprotected-pyvisit
Enable `GILProtected` access via `PyVisit`
2 parents 856c573 + 3249feb commit 4baf023

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

newsfragments/3616.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `traverse` method to `GILProtected`

src/sync.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Synchronization mechanisms based on the Python GIL.
2-
use crate::{types::PyString, types::PyType, Py, PyErr, Python};
2+
use crate::{types::PyString, types::PyType, Py, PyErr, PyVisit, Python};
33
use std::cell::UnsafeCell;
44

55
/// Value with concurrent access protected by the GIL.
@@ -37,6 +37,11 @@ impl<T> GILProtected<T> {
3737
pub fn get<'py>(&'py self, _py: Python<'py>) -> &'py T {
3838
&self.value
3939
}
40+
41+
/// Gain access to the inner value by giving proof that garbage collection is happening.
42+
pub fn traverse<'py>(&'py self, _visit: PyVisit<'py>) -> &'py T {
43+
&self.value
44+
}
4045
}
4146

4247
unsafe impl<T> Sync for GILProtected<T> where T: Send {}

0 commit comments

Comments
 (0)