diff --git a/newsfragments/3616.added.md b/newsfragments/3616.added.md new file mode 100644 index 00000000..532dc6e5 --- /dev/null +++ b/newsfragments/3616.added.md @@ -0,0 +1 @@ +Add `traverse` method to `GILProtected` diff --git a/src/sync.rs b/src/sync.rs index 8500413e..91a83106 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,5 +1,5 @@ //! Synchronization mechanisms based on the Python GIL. -use crate::{types::PyString, types::PyType, Py, PyErr, Python}; +use crate::{types::PyString, types::PyType, Py, PyErr, PyVisit, Python}; use std::cell::UnsafeCell; /// Value with concurrent access protected by the GIL. @@ -37,6 +37,11 @@ impl GILProtected { pub fn get<'py>(&'py self, _py: Python<'py>) -> &'py T { &self.value } + + /// Gain access to the inner value by giving proof that garbage collection is happening. + pub fn traverse<'py>(&'py self, _visit: PyVisit<'py>) -> &'py T { + &self.value + } } unsafe impl Sync for GILProtected where T: Send {}