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?
The
py_capsuleandpy_capsule_fnmacros generate code that cache the pointer obtained from a capsule in astatic mutitem, with astd::sync::Oncein a secondstaticitem for thread-safety.Although the synchronization cost of
Onceis small, it seems unnecessary here since code touching this is always holding the GIL. Could this cache be implemented with a singlestaticitem of typecpython::GILProtected<std::cell::Cell<_>>instead?