summaryrefslogtreecommitdiffstats
path: root/Python/preconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/preconfig.c')
-rw-r--r--Python/preconfig.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/Python/preconfig.c b/Python/preconfig.c
index afa16cc..e7125cd 100644
--- a/Python/preconfig.c
+++ b/Python/preconfig.c
@@ -826,12 +826,10 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
_Py_SetLocaleFromEnv(LC_CTYPE);
}
- _PyPreCmdline cmdline = _PyPreCmdline_INIT;
- int init_utf8_mode = Py_UTF8Mode;
-#ifdef MS_WINDOWS
- int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag;
-#endif
+ PyPreConfig save_runtime_config;
+ preconfig_copy(&save_runtime_config, &_PyRuntime.preconfig);
+ _PyPreCmdline cmdline = _PyPreCmdline_INIT;
int locale_coerced = 0;
int loops = 0;
@@ -847,11 +845,9 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
}
/* bpo-34207: Py_DecodeLocale() and Py_EncodeLocale() depend
- on Py_UTF8Mode and Py_LegacyWindowsFSEncodingFlag. */
- Py_UTF8Mode = config->utf8_mode;
-#ifdef MS_WINDOWS
- Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding;
-#endif
+ on the utf8_mode and legacy_windows_fs_encoding members
+ of _PyRuntime.preconfig. */
+ preconfig_copy(&_PyRuntime.preconfig, config);
if (args) {
// Set command line arguments at each iteration. If they are bytes
@@ -914,14 +910,10 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args)
status = _PyStatus_OK();
done:
- if (init_ctype_locale != NULL) {
- setlocale(LC_CTYPE, init_ctype_locale);
- PyMem_RawFree(init_ctype_locale);
- }
- Py_UTF8Mode = init_utf8_mode ;
-#ifdef MS_WINDOWS
- Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding;
-#endif
+ // Revert side effects
+ setlocale(LC_CTYPE, init_ctype_locale);
+ PyMem_RawFree(init_ctype_locale);
+ preconfig_copy(&_PyRuntime.preconfig, &save_runtime_config);
_PyPreCmdline_Clear(&cmdline);
return status;
}