gh-140550: Initial implementation of PEP 793 – PyModExport (GH-140556)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
Petr Viktorin 2025-11-05 12:31:42 +01:00 committed by GitHub
parent f2bce51b98
commit 589a03a8ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 1494 additions and 236 deletions

View file

@ -5764,11 +5764,11 @@ PyType_GetModuleState(PyTypeObject *type)
}
/* Get the module of the first superclass where the module has the
* given PyModuleDef.
/* Return borrowed ref to the module of the first superclass where the module
* has the given token.
*/
PyObject *
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
static PyObject *
borrow_module_by_token(PyTypeObject *type, const void *token)
{
assert(PyType_Check(type));
@ -5780,7 +5780,7 @@ PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
else {
PyHeapTypeObject *ht = (PyHeapTypeObject*)type;
PyObject *module = ht->ht_module;
if (module && _PyModule_GetDef(module) == def) {
if (module && _PyModule_GetToken(module) == token) {
return module;
}
}
@ -5808,7 +5808,7 @@ PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
PyHeapTypeObject *ht = (PyHeapTypeObject*)super;
PyObject *module = ht->ht_module;
if (module && _PyModule_GetDef(module) == def) {
if (module && _PyModule_GetToken(module) == token) {
res = module;
break;
}
@ -5826,6 +5826,18 @@ PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
return NULL;
}
PyObject *
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
{
return borrow_module_by_token(type, def);
}
PyObject *
PyType_GetModuleByToken(PyTypeObject *type, const void *token)
{
return Py_XNewRef(borrow_module_by_token(type, token));
}
static PyTypeObject *
get_base_by_token_recursive(PyObject *bases, void *token)