bpo-22257: Small changes for PEP 432. (#1728)
PEP 432 specifies a number of large changes to interpreter startup code, including exposing a cleaner C-API. The major changes depend on a number of smaller changes. This patch includes all those smaller changes.
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 90f8551..03601ea 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -291,6 +291,9 @@
/* Install importlib as the implementation of import */
value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod);
+ if (value != NULL)
+ value = PyObject_CallMethod(importlib,
+ "_install_external_importers", "");
if (value == NULL) {
PyErr_Print();
Py_FatalError("Py_Initialize: importlib install failed");
@@ -331,8 +334,8 @@
Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p);
if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0')
Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p);
- /* The variable is only tested for existence here; _PyRandom_Init will
- check its value further. */
+ /* The variable is only tested for existence here;
+ _Py_HashRandomization_Init will check its value further. */
if ((p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0')
Py_HashRandomizationFlag = add_flag(Py_HashRandomizationFlag, p);
#ifdef MS_WINDOWS
@@ -342,7 +345,7 @@
Py_LegacyWindowsStdioFlag = add_flag(Py_LegacyWindowsStdioFlag, p);
#endif
- _PyRandom_Init();
+ _Py_HashRandomization_Init();
_PyInterpreterState_Init();
interp = PyInterpreterState_New();
@@ -402,13 +405,15 @@
/* initialize builtin exceptions */
_PyExc_Init(bimod);
- sysmod = _PySys_Init();
+ sysmod = _PySys_BeginInit();
if (sysmod == NULL)
Py_FatalError("Py_Initialize: can't initialize sys");
interp->sysdict = PyModule_GetDict(sysmod);
if (interp->sysdict == NULL)
Py_FatalError("Py_Initialize: can't initialize sys dict");
Py_INCREF(interp->sysdict);
+ if (_PySys_EndInit(interp->sysdict) < 0)
+ Py_FatalError("Py_Initialize: can't initialize sys");
_PyImport_FixupBuiltin(sysmod, "sys");
PySys_SetPath(Py_GetPath());
PyDict_SetItemString(interp->sysdict, "modules",
@@ -694,7 +699,7 @@
PyDict_Fini();
PySlice_Fini();
_PyGC_Fini();
- _PyRandom_Fini();
+ _Py_HashRandomization_Fini();
_PyArg_Fini();
PyAsyncGen_Fini();