New submission from Christian Heimes <li...@cheimes.de>:
PyType_GetModule() may return wrong or unexpected result when a type has the feature flag Py_TPFLAGS_BASETYPE. The base type flag permits subclassing of an extension class. The function will return NULL when a type is subclasses in Python space or a different module object when the type is subclasses and initialized in a differen C extension module. All subclassable types must use _PyType_GetModuleByDef() to safely access module and module state struct. It's easy to miss the problem. I missed it when I ported some of my code to heap types and multiphase init. I propose to either a guard to PyType_GetModule() to prevent misuse of the function or to add a variant of the function that prevents misuse. ---------- components: Interpreter Core messages: 381475 nosy: christian.heimes, corona10, petr.viktorin, vstinner priority: normal severity: normal stage: needs patch status: open title: PyType_GetModule() should warn/fail when type has Py_TPFLAGS_BASETYPE type: behavior versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42418> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com