gh-81057: Move PyImport_Inittab to _PyRuntimeState (gh-99402)

We actually don't move PyImport_Inittab.  Instead, we make a copy that we keep on _PyRuntimeState and use only that after Py_Initialize().  We also prevent folks from modifying PyImport_Inittab (the best we can) after that point.

https://github.com/python/cpython/issues/81057
This commit is contained in:
Eric Snow 2022-11-11 17:06:05 -07:00 committed by GitHub
parent 67807cfc87
commit 7f3a4b967c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 80 additions and 8 deletions

View file

@ -2252,8 +2252,9 @@ list_builtin_module_names(void)
if (list == NULL) {
return NULL;
}
for (Py_ssize_t i = 0; PyImport_Inittab[i].name != NULL; i++) {
PyObject *name = PyUnicode_FromString(PyImport_Inittab[i].name);
struct _inittab *inittab = _PyRuntime.imports.inittab;
for (Py_ssize_t i = 0; inittab[i].name != NULL; i++) {
PyObject *name = PyUnicode_FromString(inittab[i].name);
if (name == NULL) {
goto error;
}