diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-11-23 00:12:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 00:12:09 +0100 |
commit | d4341109746aa15e1909e63b30b93b6133ffe401 (patch) | |
tree | 8982cc677ace3953484d4e4e34c8b154d0b9fb35 /Python/pylifecycle.c | |
parent | 82656276caf4cb889193572d2d14dbc5f3d2bdff (diff) | |
download | cpython-git-d4341109746aa15e1909e63b30b93b6133ffe401.tar.gz |
bpo-32030: Add _PyCoreConfig.module_search_path_env (#4504)
Changes:
* Py_Main() initializes _PyCoreConfig.module_search_path_env from
the PYTHONPATH environment variable.
* PyInterpreterState_New() now initializes core_config and config
fields
* Compute sys.path a little bit ealier in
_Py_InitializeMainInterpreter() and new_interpreter()
* Add _Py_GetPathWithConfig() private function.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 36fcf61c33..9eeac9d33b 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -48,8 +48,6 @@ _Py_IDENTIFIER(threading); extern "C" { #endif -extern wchar_t *Py_GetPath(void); - extern grammar _PyParser_Grammar; /* From graminit.c */ /* Forward */ @@ -842,6 +840,11 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config) /* Now finish configuring the main interpreter */ interp->config = *config; + /* GetPath may initialize state that _PySys_EndInit locks + in, and so has to be called first. */ + /* TODO: Call Py_GetPath() in Py_ReadConfig, rather than here */ + wchar_t *sys_path = _Py_GetPathWithConfig(&interp->core_config); + if (interp->core_config._disable_importlib) { /* Special mode for freeze_importlib: run with no import system * @@ -857,10 +860,7 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config) return _Py_INIT_ERR("can't initialize time"); /* Finish setting up the sys module and import system */ - /* GetPath may initialize state that _PySys_EndInit locks - in, and so has to be called first. */ - /* TODO: Call Py_GetPath() in Py_ReadConfig, rather than here */ - PySys_SetPath(Py_GetPath()); + PySys_SetPath(sys_path); if (_PySys_EndInit(interp->sysdict) < 0) return _Py_INIT_ERR("can't finish initializing sys"); @@ -1301,6 +1301,8 @@ new_interpreter(PyThreadState **tstate_p) /* XXX The following is lax in error checking */ + wchar_t *sys_path = _Py_GetPathWithConfig(&interp->core_config); + PyObject *modules = PyDict_New(); if (modules == NULL) { return _Py_INIT_ERR("can't make modules dictionary"); @@ -1314,7 +1316,7 @@ new_interpreter(PyThreadState **tstate_p) goto handle_error; Py_INCREF(interp->sysdict); PyDict_SetItemString(interp->sysdict, "modules", modules); - PySys_SetPath(Py_GetPath()); + PySys_SetPath(sys_path); _PySys_EndInit(interp->sysdict); } |