summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c60
1 files changed, 27 insertions, 33 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 584aa55..c88e945 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -599,12 +599,9 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
{
assert(core_config != NULL);
- PyInterpreterState *interp;
- PyThreadState *tstate;
- PyObject *bimod, *sysmod, *pstderr;
- _PyInitError err;
+ _PyCoreConfig_SetGlobalConfig(core_config);
- err = _PyRuntime_Initialize();
+ _PyInitError err = _PyRuntime_Initialize();
if (_Py_INIT_FAILED(err)) {
return err;
}
@@ -646,17 +643,12 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
return err;
}
- if (!core_config->use_hash_seed || core_config->hash_seed) {
- /* Random or non-zero hash seed */
- Py_HashRandomizationFlag = 1;
- }
-
err = _PyInterpreterState_Enable(&_PyRuntime);
if (_Py_INIT_FAILED(err)) {
return err;
}
- interp = PyInterpreterState_New();
+ PyInterpreterState *interp = PyInterpreterState_New();
if (interp == NULL) {
return _Py_INIT_ERR("can't make main interpreter");
}
@@ -664,8 +656,9 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) {
return _Py_INIT_ERR("failed to copy core config");
}
+ core_config = &interp->core_config;
- tstate = PyThreadState_New(interp);
+ PyThreadState *tstate = PyThreadState_New(interp);
if (tstate == NULL)
return _Py_INIT_ERR("can't make first thread");
(void) PyThreadState_Swap(tstate);
@@ -699,6 +692,7 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
return _Py_INIT_ERR("can't make modules dictionary");
interp->modules = modules;
+ PyObject *sysmod;
err = _PySys_BeginInit(&sysmod);
if (_Py_INIT_FAILED(err)) {
return err;
@@ -720,7 +714,7 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
if (_PyStructSequence_Init() < 0)
return _Py_INIT_ERR("can't initialize structseq");
- bimod = _PyBuiltin_Init();
+ PyObject *bimod = _PyBuiltin_Init();
if (bimod == NULL)
return _Py_INIT_ERR("can't initialize builtins modules");
_PyImport_FixupBuiltin(bimod, "builtins", modules);
@@ -734,7 +728,7 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
/* Set up a preliminary stderr printer until we have enough
infrastructure for the io module in place. */
- pstderr = PyFile_NewStdPrinter(fileno(stderr));
+ PyObject *pstderr = PyFile_NewStdPrinter(fileno(stderr));
if (pstderr == NULL)
return _Py_INIT_ERR("can't set preliminary stderr");
_PySys_SetObjectId(&PyId_stderr, pstderr);
@@ -759,7 +753,7 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
if (!_PyContext_Init())
return _Py_INIT_ERR("can't init context");
- if (!core_config->_disable_importlib) {
+ if (core_config->_install_importlib) {
err = _PyCoreConfig_SetPathConfig(core_config);
if (_Py_INIT_FAILED(err)) {
return err;
@@ -767,7 +761,7 @@ _Py_InitializeCore(const _PyCoreConfig *core_config)
}
/* This call sets up builtin and frozen import support */
- if (!interp->core_config._disable_importlib) {
+ if (core_config->_install_importlib) {
err = initimport(interp, sysmod);
if (_Py_INIT_FAILED(err)) {
return err;
@@ -809,21 +803,20 @@ _Py_ReconfigureMainInterpreter(PyInterpreterState *interp,
_PyInitError
_Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
{
- PyInterpreterState *interp;
- PyThreadState *tstate;
- _PyInitError err;
-
if (!_PyRuntime.core_initialized) {
return _Py_INIT_ERR("runtime core not initialized");
}
/* Get current thread state and interpreter pointer */
- tstate = PyThreadState_GET();
- if (!tstate)
+ PyThreadState *tstate = PyThreadState_GET();
+ if (!tstate) {
return _Py_INIT_ERR("failed to read thread state");
- interp = tstate->interp;
- if (!interp)
+ }
+ PyInterpreterState *interp = tstate->interp;
+ if (!interp) {
return _Py_INIT_ERR("failed to get interpreter");
+ }
+ _PyCoreConfig *core_config = &interp->core_config;
/* Now finish configuring the main interpreter */
if (_PyMainInterpreterConfig_Copy(&interp->config, config) < 0) {
@@ -834,7 +827,7 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
return _Py_ReconfigureMainInterpreter(interp, config);
}
- if (interp->core_config._disable_importlib) {
+ if (!core_config->_install_importlib) {
/* Special mode for freeze_importlib: run with no import system
*
* This means anything which needs support from extension modules
@@ -852,13 +845,13 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
return _Py_INIT_ERR("can't finish initializing sys");
}
- err = initexternalimport(interp);
+ _PyInitError err = initexternalimport(interp);
if (_Py_INIT_FAILED(err)) {
return err;
}
/* initialize the faulthandler module */
- err = _PyFaulthandler_Init(interp->core_config.faulthandler);
+ err = _PyFaulthandler_Init(core_config->faulthandler);
if (_Py_INIT_FAILED(err)) {
return err;
}
@@ -875,8 +868,9 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
}
}
- if (_PyTraceMalloc_Init(interp->core_config.tracemalloc) < 0)
+ if (_PyTraceMalloc_Init(core_config->tracemalloc) < 0) {
return _Py_INIT_ERR("can't initialize tracemalloc");
+ }
err = add_main_module(interp);
if (_Py_INIT_FAILED(err)) {
@@ -902,7 +896,7 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
_PyRuntime.initialized = 1;
- if (!Py_NoSiteFlag) {
+ if (core_config->site_import) {
err = initsite(); /* Module site */
if (_Py_INIT_FAILED(err)) {
return err;
@@ -924,11 +918,10 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
_PyCoreConfig config = _PyCoreConfig_INIT;
_PyInitError err;
- config.ignore_environment = Py_IgnoreEnvironmentFlag;
- config._disable_importlib = !install_importlib;
+ config._install_importlib = install_importlib;
config.install_signal_handlers = install_sigs;
- err = _PyCoreConfig_Read(&config, &Py_IsolatedFlag, &Py_NoSiteFlag);
+ err = _PyCoreConfig_Read(&config);
if (_Py_INIT_FAILED(err)) {
goto done;
}
@@ -1320,6 +1313,7 @@ new_interpreter(PyThreadState **tstate_p)
if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) {
return _Py_INIT_ERR("failed to copy core config");
}
+ core_config = &interp->core_config;
if (_PyMainInterpreterConfig_Copy(&interp->config, config) < 0) {
return _Py_INIT_ERR("failed to copy main interpreter config");
}
@@ -1395,7 +1389,7 @@ new_interpreter(PyThreadState **tstate_p)
return err;
}
- if (!Py_NoSiteFlag) {
+ if (core_config->site_import) {
err = initsite();
if (_Py_INIT_FAILED(err)) {
return err;