[Python-3000] Accessing module state from extension types

Amaury Forgeot d'Arc amauryfa at gmail.com
Tue Oct 7 15:51:07 CEST 2008


Hello,

Extension modules have a new "md_state" member, I understand that it
is designed to hold the "static" state of the module.
IIUC, for example in _cpickle.c, the "PyObject *dispatch_table"
variable is a good candidate for such module state.
This would allow to play more nicely with multiple startups/shutdowns,
reloading of the module, or with different sub-interpreters.

This state is accessible through the PyModule_GetState() function.
This is fine for module functions (the module object is passed as the
first argument, even if we always name it "self"), but how does it
work with classes or class methods?
Classes do not contain a reference to their modules, they only have
access to the __name__, which is not the same thing at all, specially
in this case.

This is unfortunate for extension modules which try to be
object-oriented, and have very few functions (the _pickle module does
not have any BTW)
How is this supposed to work?

-- 
Amaury Forgeot d'Arc


More information about the Python-3000 mailing list