New submission from STINNER Victor <vstin...@python.org>:
Currently, when a module implements m_traverse(), m_clear() or m_free(), these methods can be called with md_state=NULL even if the module implements the "Multi-phase extension module initialization" API (PEP 489). I'm talking about these module methods: * tp_traverse: module_traverse() calls md_def->m_traverse() if m_traverse is not NULL * tp_clear: module_clear() calls md_def->m_clear() if m_clear is not NULL * tp_dealloc: module_dealloc() calls md_def->m_free() is m_free is not NULL Because of that, the implementation of these methods must check manually if md_state is NULL or not. I propose to change module_traverse(), module_clear() and module_dealloc() to not call m_traverse(), m_clear() and m_free() if md_state is NULL and m_size > 0. "m_size > 0" is an heuristic to check if the module implements the "Multi-phase extension module initialization" API (PEP 489). For example, the _pickle module doesn't fully implements the PEP 489: m_size > 0, but PyInit__pickle() uses PyModule_Create(). See bpo-32374 which documented that "m_traverse may be called with m_state=NULL" (GH-5140). ---------- components: Interpreter Core messages: 363145 nosy: vstinner priority: normal severity: normal status: open title: Multi-phase extension module (PEP 489): don't call m_traverse, m_clear nor m_free if md_state is NULL versions: Python 3.9 _______________________________________ 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