From 7f3a4b967cfb1596a3fda6c34f900f8586b16700 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 11 Nov 2022 17:06:05 -0700 Subject: 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 --- Python/sysmodule.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 5de684e7195..1090b124fea 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -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; } -- cgit v1.2.3