Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable GILProtected access via PyVisit #3616

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/3616.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `traverse` method to `GILProtected`
7 changes: 6 additions & 1 deletion src/sync.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -37,6 +37,11 @@ impl<T> GILProtected<T> {
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<T> Sync for GILProtected<T> where T: Send {}
Expand Down