On Wed, Jan 5, 2022 at 8:32 AM Petr Viktorin <encukou@gmail.com> wrote:
In bpo-42100, I added the private function _PyType_GetModuleByDef, which allows module state access from slot methods (like tp_init or nb_add), the main thing missing from PEP 573 (Module State Access from C Extension Methods). The method is now used in 10 stdlib modules, without known issues.
Since it was has optimized (thanks, Victor!), I haven't seen complaints about performance issues. Sadly, it has a loop so it's much slower than using C statics, but it's OK for many use cases.
I haven't found a better way to get per-module state for isolated modules (and the stable ABI).
So, I'd like to drop the leading underscore, and add PyType_GetModuleByDef directly to the limited API.
The function itself can be implemented using only limited API, though it's a bit tricky to do so correctly (and our implementation uses private speedups), so it's better if extension authors can use it as a pre-made building block.
The fact that it can be implemented with only limited API means that adding it should not add big burden for long-term maintenance in CPython, nor for alternate implementations of the C-API.
Is anyone against? Does anyone feel this should be discussed more widely than on capi-sig?
I don't have an opinion, but the point of having SIGs to to minimize having to get more people involved in technical discussion that only apply to a subset of folks. If people feel this SIG is not known widely enough then we can post on python-dev about its existence, but otherwise this list should be good enough for a discussion.