Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
I propose addingPyType_GetModuleByDef() to the limited C API version 3.13. The function was added to Python 3.9, the function is now well tested. We could add it way earlier to the limited C API.
cc@encukou
ThePyType_GetModuleByDef() function is needed to access themodule state in C function which don't get a module as first parameter, but only an instance of a heap type. Heap types should be created withPyType_FromModuleAndSpec(module, spec, bases) to store the module in the type.PyType_GetModuleByDef(type) gives the module and thenPyModule_GetState() gives the moulde state.
Examples of functions which don't get amodule argument:
- Class methods
- Most slots, examples:
tp_new,tp_richcompare,tp_iternext, etc. PyGetSetDefgetter and setter functions
WithoutPyType_GetModuleByDef(), many static types cannot be converted to heap types.
The following stdlib extensions usePyType_GetModuleByDef()
Modules/_asynciomodule.cModules/_bz2module.cModules/_collectionsmodule.cModules/_csv.cModules/_decimal/_decimal.cModules/_elementtree.cModules/_functoolsmodule.cModules/_io/_iomodule.hModules/_pickle.cModules/_queuemodule.cModules/_randommodule.cModules/_sqlite/module.hModules/_ssl.cModules/_ssl.hModules/_struct.cModules/_testmultiphase.cModules/_threadmodule.cModules/_xxinterpchannelsmodule.cModules/_zoneinfo.cModules/arraymodule.cModules/cjkcodecs/multibytecodec.cModules/clinic/_testmultiphase.c.hModules/itertoolsmodule.cModules/socketmodule.cPython/Python-tokenize.c