STINNER Victor <vstin...@python.org> added the comment:

There are different kinds of extension modules:

(1) no module state (m_size <= 0): **not affected** by this change. Example: 
_asyncio which implements m_free() to clear global variables and free lists.

(2) Have a module state but PyInit_xxx() calls PyModule_Create(): 
PyModule_Create() always allocates md_state. I understand that such extension 
module is **not affected** by this change.

(3) Multi-phase extension: PyInit_xxx() function calls PyModuleDef_Init(). Such 
extension module **is affected** if m_traverse, m_clear or m_free() is not 
NULL. Example: atexit module implements m_traverse, m_clear and m_free.


PyModuleObject structure contains Python objects like md_dict (dict), md_name 
(str) or md_weaklist (list):

* module_traverse() always traverses md_dict: m_traverse() is no needed for 
that.
* module_clear() always clears md_dict: m_clear() is no needed for that.
* module_dealloc() always deallocates md_dict, md_name and md_weaklist: 
m_free() is no needed for that. 
* md_name is a string, it cannot be involved in a reference cycle.


I don't think that it's possible to extend PyModuleObject structure (as done by 
PyListObject for PyObject) to add other Python objects: md_state is designed 
for that. PyModule_Create() allocates exactly sizeof(PyModuleObject) bytes.


If an extension module has a module state, stores Python objects *outside* this 
state and uses m_traverse, m_clear and m_free to handle these objects: the GC 
will no longer be able to handle these objects before the module is executed 
with this change. If such extension module exists, I consider that it's ok to 
only handle objects stored outside the module state once the module is 
executed. The window between <the module is created> and <the module is 
executed> is very short.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39824>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to