aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-12-02 10:11:32 +0100
committerGitHub <noreply@github.com>2017-12-02 10:11:32 +0100
commitaf5a895073c24637c094772b27526b94a12ec897 (patch)
tree2960347bdeb6d0ba50746d5d36630d13630f1bb9 /Modules/getpath.c
parentbpo-32030: Fix config_get_program_name() on macOS (#4669) (diff)
downloadcpython-af5a895073c24637c094772b27526b94a12ec897.tar.gz
cpython-af5a895073c24637c094772b27526b94a12ec897.tar.bz2
cpython-af5a895073c24637c094772b27526b94a12ec897.zip
bpo-32030: _PyPathConfig_Init() sets home and program_name (#4673)
_PyPathConfig_Init() now also initialize home and program_name: * Rename existing _PyPathConfig_Init() to _PyPathConfig_Calculate(). Add a new _PyPathConfig_Init() function in pathconfig.c which handles the _Py_path_config variable and call _PyPathConfig_Calculate(). * Add home and program_name fields to _PyPathConfig.home * _PyPathConfig_Init() now initialize home and program_name from main_config * Py_SetProgramName(), Py_SetPythonHome() and Py_GetPythonHome() now calls Py_FatalError() on failure, instead of silently ignoring failures. * config_init_home() now gets directly _Py_path_config.home to only get the value set by Py_SetPythonHome(), or NULL if Py_SetPythonHome() was not called. * config_get_program_name() now gets directly _Py_path_config.program_name to only get the value set by Py_SetProgramName(), or NULL if Py_SetProgramName() was not called. * pymain_init_python() doesn't call Py_SetProgramName() anymore, _PyPathConfig_Init() now always sets the program name * Call _PyMainInterpreterConfig_Read() in pymain_parse_cmdline_envvars_impl() to control the memory allocator * C API documentation: it's no more safe to call Py_GetProgramName() before Py_Initialize().
Diffstat (limited to 'Modules/getpath.c')
-rw-r--r--Modules/getpath.c17
1 files changed, 3 insertions, 14 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 8554dbe2a2c..fc2b5442ce2 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -1008,16 +1008,10 @@ calculate_path_impl(const _PyMainInterpreterConfig *main_config,
}
-/* Initialize paths for Py_GetPath(), Py_GetPrefix(), Py_GetExecPrefix()
- and Py_GetProgramFullPath() */
_PyInitError
-_PyPathConfig_Init(const _PyMainInterpreterConfig *main_config)
+_PyPathConfig_Calculate(_PyPathConfig *config,
+ const _PyMainInterpreterConfig *main_config)
{
- if (_Py_path_config.module_search_path) {
- /* Already initialized */
- return _Py_INIT_OK();
- }
-
PyCalculatePath calculate;
memset(&calculate, 0, sizeof(calculate));
@@ -1026,16 +1020,11 @@ _PyPathConfig_Init(const _PyMainInterpreterConfig *main_config)
goto done;
}
- _PyPathConfig new_path_config;
- memset(&new_path_config, 0, sizeof(new_path_config));
-
- err = calculate_path_impl(main_config, &calculate, &new_path_config);
+ err = calculate_path_impl(main_config, &calculate, config);
if (_Py_INIT_FAILED(err)) {
- _PyPathConfig_Clear(&new_path_config);
goto done;
}
- _Py_path_config = new_path_config;
err = _Py_INIT_OK();
done: