Commit 4a1468e5 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-36356: Fix _PyCoreConfig_Read() (GH-12454)

Don't override parameters which are already set by the user.
parent f29084d6
...@@ -961,6 +961,7 @@ config_read_env_vars(_PyCoreConfig *config) ...@@ -961,6 +961,7 @@ config_read_env_vars(_PyCoreConfig *config)
config->malloc_stats = 1; config->malloc_stats = 1;
} }
if (config->module_search_path_env == NULL) {
wchar_t *path; wchar_t *path;
int res = _PyCoreConfig_GetEnvDup(config, &path, int res = _PyCoreConfig_GetEnvDup(config, &path,
L"PYTHONPATH", "PYTHONPATH"); L"PYTHONPATH", "PYTHONPATH");
...@@ -968,6 +969,7 @@ config_read_env_vars(_PyCoreConfig *config) ...@@ -968,6 +969,7 @@ config_read_env_vars(_PyCoreConfig *config)
return DECODE_LOCALE_ERR("PYTHONPATH", res); return DECODE_LOCALE_ERR("PYTHONPATH", res);
} }
config->module_search_path_env = path; config->module_search_path_env = path;
}
if (config->use_hash_seed < 0) { if (config->use_hash_seed < 0) {
_PyInitError err = config_init_hash_seed(config); _PyInitError err = config_init_hash_seed(config);
...@@ -1689,6 +1691,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, ...@@ -1689,6 +1691,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
} }
if (c == 'c') { if (c == 'c') {
if (config->run_command == NULL) {
/* -c is the last option; following arguments /* -c is the last option; following arguments
that look like options are left for the that look like options are left for the
command to interpret. */ command to interpret. */
...@@ -1701,6 +1704,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, ...@@ -1701,6 +1704,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
command[len - 2] = '\n'; command[len - 2] = '\n';
command[len - 1] = 0; command[len - 1] = 0;
config->run_command = command; config->run_command = command;
}
break; break;
} }
...@@ -1708,10 +1712,12 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, ...@@ -1708,10 +1712,12 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
/* -m is the last option; following arguments /* -m is the last option; following arguments
that look like options are left for the that look like options are left for the
module to interpret. */ module to interpret. */
if (config->run_module == NULL) {
config->run_module = _PyMem_RawWcsdup(_PyOS_optarg); config->run_module = _PyMem_RawWcsdup(_PyOS_optarg);
if (config->run_module == NULL) { if (config->run_module == NULL) {
return _Py_INIT_NO_MEMORY(); return _Py_INIT_NO_MEMORY();
} }
}
break; break;
} }
...@@ -1825,7 +1831,8 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, ...@@ -1825,7 +1831,8 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
if (config->run_command == NULL && config->run_module == NULL if (config->run_command == NULL && config->run_module == NULL
&& _PyOS_optind < cmdline->argv.length && _PyOS_optind < cmdline->argv.length
&& wcscmp(cmdline->argv.items[_PyOS_optind], L"-") != 0) && wcscmp(cmdline->argv.items[_PyOS_optind], L"-") != 0
&& config->run_filename == NULL)
{ {
config->run_filename = _PyMem_RawWcsdup(cmdline->argv.items[_PyOS_optind]); config->run_filename = _PyMem_RawWcsdup(cmdline->argv.items[_PyOS_optind]);
if (config->run_filename == NULL) { if (config->run_filename == NULL) {
...@@ -2032,10 +2039,12 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline, ...@@ -2032,10 +2039,12 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
_PyCoreConfig_GetGlobalConfig(config); _PyCoreConfig_GetGlobalConfig(config);
if (config->program == NULL) {
err = config_init_program(config, cmdline); err = config_init_program(config, cmdline);
if (_Py_INIT_FAILED(err)) { if (_Py_INIT_FAILED(err)) {
return err; return err;
} }
}
err = config_parse_cmdline(config, cmdline, &need_usage); err = config_parse_cmdline(config, cmdline, &need_usage);
if (_Py_INIT_FAILED(err)) { if (_Py_INIT_FAILED(err)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment