summaryrefslogtreecommitdiffstats
path: root/Python/coreconfig.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-03-20 02:11:38 (GMT)
committerGitHub <noreply@github.com>2019-03-20 02:11:38 (GMT)
commit4a1468e593c4b67d8c78b78070fff9e18ec5d790 (patch)
tree7de298ea80db9b20aa7be4a86300df1baff9d39a /Python/coreconfig.c
parentf29084d611a6ca504c99a0967371374febf0ccc3 (diff)
downloadcpython-4a1468e593c4b67d8c78b78070fff9e18ec5d790.zip
cpython-4a1468e593c4b67d8c78b78070fff9e18ec5d790.tar.gz
cpython-4a1468e593c4b67d8c78b78070fff9e18ec5d790.tar.bz2
bpo-36356: Fix _PyCoreConfig_Read() (GH-12454)
Don't override parameters which are already set by the user.
Diffstat (limited to 'Python/coreconfig.c')
-rw-r--r--Python/coreconfig.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index de2058c..e1d883c 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -961,13 +961,15 @@ config_read_env_vars(_PyCoreConfig *config)
config->malloc_stats = 1;
}
- wchar_t *path;
- int res = _PyCoreConfig_GetEnvDup(config, &path,
- L"PYTHONPATH", "PYTHONPATH");
- if (res < 0) {
- return DECODE_LOCALE_ERR("PYTHONPATH", res);
+ if (config->module_search_path_env == NULL) {
+ wchar_t *path;
+ int res = _PyCoreConfig_GetEnvDup(config, &path,
+ L"PYTHONPATH", "PYTHONPATH");
+ if (res < 0) {
+ return DECODE_LOCALE_ERR("PYTHONPATH", res);
+ }
+ config->module_search_path_env = path;
}
- config->module_search_path_env = path;
if (config->use_hash_seed < 0) {
_PyInitError err = config_init_hash_seed(config);
@@ -1689,18 +1691,20 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
}
if (c == 'c') {
- /* -c is the last option; following arguments
- that look like options are left for the
- command to interpret. */
- size_t len = wcslen(_PyOS_optarg) + 1 + 1;
- wchar_t *command = PyMem_RawMalloc(sizeof(wchar_t) * len);
- if (command == NULL) {
- return _Py_INIT_NO_MEMORY();
+ if (config->run_command == NULL) {
+ /* -c is the last option; following arguments
+ that look like options are left for the
+ command to interpret. */
+ size_t len = wcslen(_PyOS_optarg) + 1 + 1;
+ wchar_t *command = PyMem_RawMalloc(sizeof(wchar_t) * len);
+ if (command == NULL) {
+ return _Py_INIT_NO_MEMORY();
+ }
+ memcpy(command, _PyOS_optarg, (len - 2) * sizeof(wchar_t));
+ command[len - 2] = '\n';
+ command[len - 1] = 0;
+ config->run_command = command;
}
- memcpy(command, _PyOS_optarg, (len - 2) * sizeof(wchar_t));
- command[len - 2] = '\n';
- command[len - 1] = 0;
- config->run_command = command;
break;
}
@@ -1708,9 +1712,11 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
/* -m is the last option; following arguments
that look like options are left for the
module to interpret. */
- config->run_module = _PyMem_RawWcsdup(_PyOS_optarg);
if (config->run_module == NULL) {
- return _Py_INIT_NO_MEMORY();
+ config->run_module = _PyMem_RawWcsdup(_PyOS_optarg);
+ if (config->run_module == NULL) {
+ return _Py_INIT_NO_MEMORY();
+ }
}
break;
}
@@ -1825,7 +1831,8 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
if (config->run_command == NULL && config->run_module == NULL
&& _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]);
if (config->run_filename == NULL) {
@@ -2032,9 +2039,11 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
_PyCoreConfig_GetGlobalConfig(config);
- err = config_init_program(config, cmdline);
- if (_Py_INIT_FAILED(err)) {
- return err;
+ if (config->program == NULL) {
+ err = config_init_program(config, cmdline);
+ if (_Py_INIT_FAILED(err)) {
+ return err;
+ }
}
err = config_parse_cmdline(config, cmdline, &need_usage);