Use GILProtected for capsule caching?
The py_capsule and py_capsule_fn macros generate code that cache the pointer obtained from a capsule in a static mut item, with a std::sync::Once in a second static item for thread-safety.
Although the synchronization cost of Once is small, it seems unnecessary here since code touching this is always holding the GIL. Could this cache be implemented with a single static item of type cpython::GILProtected<std::cell::Cell<_>> instead?
This is probably a question for @gracinet.
I’ve submitted https://github.com/dgrunwald/rust-cpython/pull/268. Cell turned out not to be enough, this uses OnceCell instead. The fact that no cache-related unsafe code is needed anymore reinforces my belief that this approach is sound.