bpo-34170: _PyCoreConfig_Read() leaves Py_IsolatedFlag unchanged (GH-8361)

* _PyCoreConfig_Read() no longer directly modifies Py_IsolatedFlag
  and Py_NoSiteFlag global configuration flags. The function now
  requires two pointers to integer, so these flags can be set later,
  to avoid side effets in _PyCoreConfig_Read().
* pathconfig_global_init() now leaves Py_IsolatedFlag and
  Py_NoSiteFlag unchanged.
* Fix pathconfig_global_init(): avoid computing the path
  configuration twice, use _PyCoreConfig_SetPathConfig().
This commit is contained in:
Victor Stinner 2018-07-21 03:54:20 +02:00 committed by GitHub
parent c884616390
commit f2626ce6d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 41 deletions

View file

@ -553,8 +553,7 @@ get_program_full_path(const _PyCoreConfig *core_config,
static int
read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path,
int *isolated, int *nosite)
read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path)
{
FILE *sp_file = _Py_wfopen(path, L"r");
if (sp_file == NULL) {
@ -563,8 +562,8 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path,
wcscpy_s(prefix, MAXPATHLEN+1, path);
reduce(prefix);
*isolated = 1;
*nosite = 1;
config->isolated = 1;
config->no_site_import = 1;
size_t bufsiz = MAXPATHLEN;
size_t prefixlen = wcslen(prefix);
@ -589,9 +588,10 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path,
}
if (strcmp(line, "import site") == 0) {
*nosite = 0;
config->no_site_import = 0;
continue;
} else if (strncmp(line, "import ", 7) == 0) {
}
else if (strncmp(line, "import ", 7) == 0) {
Py_FatalError("only 'import site' is supported in ._pth file");
}
@ -680,11 +680,7 @@ calculate_pth_file(_PyPathConfig *config, wchar_t *prefix)
return 0;
}
/* FIXME, bpo-32030: Global configuration variables should not be modified
here, _PyPathConfig_Init() is called early in Python initialization:
see pymain_cmdline(). */
return read_pth_file(config, prefix, spbuffer,
&Py_IsolatedFlag, &Py_NoSiteFlag);
return read_pth_file(config, prefix, spbuffer);
}