# HG changeset patch # User Yuya Nishihara # Date 2019-09-16 22:59:25 # Node ID a1908eb08342402ed2ca79a351c0333612bf2237 # Parent 1c675c5fe5fe88b248c05b6c2f039f59320147fc rust-cpython: mark PySharedState as Sync so &'PySharedState can be Send The goal is to store &'static PySharedState in $leaked struct, which allows us to move the $leaked struct out of the macro. Currently, it depends on inner.$data_member(py), which can't be generalized. PySharedState is Sync because any mutation or read operation is synchronized by the Python GIL, py: Python<'a>, which should guarantee that &'PySharedState can be sent to another thread. diff --git a/rust/hg-cpython/src/ref_sharing.rs b/rust/hg-cpython/src/ref_sharing.rs --- a/rust/hg-cpython/src/ref_sharing.rs +++ b/rust/hg-cpython/src/ref_sharing.rs @@ -33,6 +33,10 @@ pub struct PySharedState { mutably_borrowed: Cell, } +// &PySharedState can be Send because any access to inner cells is +// synchronized by the GIL. +unsafe impl Sync for PySharedState {} + impl PySharedState { pub fn borrow_mut<'a, T>( &'a self,