diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-11-25 02:17:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-25 02:17:57 (GMT) |
commit | 9316ee4da2dcc217351418fc4dbe9205995689e0 (patch) | |
tree | 6c292be4738bdc93ff647113bba6a4cb664da352 /Python | |
parent | 706cb3162e15271ecfeba15909ed48a3a437009f (diff) | |
download | cpython-9316ee4da2dcc217351418fc4dbe9205995689e0.zip cpython-9316ee4da2dcc217351418fc4dbe9205995689e0.tar.gz cpython-9316ee4da2dcc217351418fc4dbe9205995689e0.tar.bz2 |
bpo-32030: Add _PyPathConfig_Init() (#4551)
* Add _PyPathConfig_Init() and _PyPathConfig_Fini()
* Remove _Py_GetPathWithConfig()
* _PyPathConfig_Init() returns _PyInitError to allow to handle errors
properly
* Add pathconfig_clear()
* Windows calculate_path_impl(): replace Py_FatalError() with
_PyInitError
* Py_FinalizeEx() now calls _PyPathConfig_Fini() to release memory
* Fix _Py_InitializeMainInterpreter() regression: don't initialize
path config if _disable_importlib is false
* PyPathConfig now uses dynamically allocated memory
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pylifecycle.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 714be37..868ac84 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -866,11 +866,6 @@ _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->config); - if (interp->core_config._disable_importlib) { /* Special mode for freeze_importlib: run with no import system * @@ -880,11 +875,20 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config) _PyRuntime.initialized = 1; return _Py_INIT_OK(); } + /* TODO: Report exceptions rather than fatal errors below here */ if (_PyTime_Init() < 0) return _Py_INIT_ERR("can't initialize time"); + /* GetPath may initialize state that _PySys_EndInit locks + in, and so has to be called first. */ + err = _PyPathConfig_Init(&interp->config); + if (_Py_INIT_FAILED(err)) { + return err; + } + wchar_t *sys_path = Py_GetPath(); + /* Finish setting up the sys module and import system */ PySys_SetPath(sys_path); if (_PySys_EndInit(interp->sysdict) < 0) @@ -1261,6 +1265,9 @@ Py_FinalizeEx(void) #endif call_ll_exitfuncs(); + + _PyPathConfig_Fini(); + _PyRuntime_Finalize(); return status; } @@ -1290,6 +1297,7 @@ new_interpreter(PyThreadState **tstate_p) PyInterpreterState *interp; PyThreadState *tstate, *save_tstate; PyObject *bimod, *sysmod; + _PyInitError err; if (!_PyRuntime.initialized) { return _Py_INIT_ERR("Py_Initialize must be called first"); @@ -1325,10 +1333,13 @@ new_interpreter(PyThreadState **tstate_p) interp->config = main_interp->config; } - /* XXX The following is lax in error checking */ - - wchar_t *sys_path = _Py_GetPathWithConfig(&interp->config); + err = _PyPathConfig_Init(&interp->config); + if (_Py_INIT_FAILED(err)) { + return err; + } + wchar_t *sys_path = Py_GetPath(); + /* XXX The following is lax in error checking */ PyObject *modules = PyDict_New(); if (modules == NULL) { return _Py_INIT_ERR("can't make modules dictionary"); @@ -1359,7 +1370,6 @@ new_interpreter(PyThreadState **tstate_p) if (bimod != NULL && sysmod != NULL) { PyObject *pstderr; - _PyInitError err; /* Set up a preliminary stderr printer until we have enough infrastructure for the io module in place. */ |