This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Robin.Schreiber
Recipients Robin.Schreiber
Date 2012-06-10.09:30:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1339320622.0.0.56459406352.issue15042@psf.upfronthosting.co.za>
In-reply-to
Content
PEP 3121 suggests a new way of Module-initialization, where the module state is being wrapped inside a dedicate struct, which can be accessed at runtime via the PyState_FindModule method. For code outside the Init-method, there is no other way to receive the module-state, as it has no reference to the object created by PyModule_Create.
PyState_FindModule requires, that the module-state has been attached to the interpreter-state beforehand. Inside an extension module code this is almost everywhere the case except inside the Init-method, because currently _PyState_AddModule is only called by the importer AFTER the extension module has been initialized successfully. As most of the macro definitions inside an extension module, which rely on data stored in the module state, have to receive the state via FindModule, they fail to work inside the modules Init-method.

This patch suggests an extension of PyState comprising two publicly available methods (PyState_AddModule, PyState_RemoveModule) that can be called from inside the Init-method, so that the module-state is attached to the interpreter state before further initialization of the module continues. As a result, PyState_FindModule will also work in this region of the extension module and the bespoken expanded macros will also work flawlessly when executed inside the Init code.

This patch is especially important for the future application of PEP 3121 together with PEP 384, as the newly created heap-types now reside inside the module-state. As type-objects are frequently used in macro-definitions which are also expanded within the Init-method of a module (or inside a function called from Init), the module state has to be received via FindModule. (The alternative would be nasty redefinitions of the specific macros, shortly before Init)
History
Date User Action Args
2012-06-10 09:30:22Robin.Schreibersetrecipients: + Robin.Schreiber
2012-06-10 09:30:22Robin.Schreibersetmessageid: <1339320622.0.0.56459406352.issue15042@psf.upfronthosting.co.za>
2012-06-10 09:30:21Robin.Schreiberlinkissue15042 messages
2012-06-10 09:30:20Robin.Schreibercreate