diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-04-18 12:39:32 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.ru> | 2022-04-18 12:39:32 +0300 |
commit | d4be68e361f4258cf0848fc70018dfe37a2acc24 (patch) | |
tree | 153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Python/preconfig.c | |
parent | 260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff) | |
download | ydb-d4be68e361f4258cf0848fc70018dfe37a2acc24.tar.gz |
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Python/preconfig.c')
-rw-r--r-- | contrib/tools/python3/src/Python/preconfig.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/contrib/tools/python3/src/Python/preconfig.c b/contrib/tools/python3/src/Python/preconfig.c index 262738fa57..ae1cc3f90f 100644 --- a/contrib/tools/python3/src/Python/preconfig.c +++ b/contrib/tools/python3/src/Python/preconfig.c @@ -19,11 +19,6 @@ preconfig_copy(PyPreConfig *config, const PyPreConfig *config2); /* --- File system encoding/errors -------------------------------- */ -/* The filesystem encoding is chosen by config_init_fs_encoding(), - see also initfsencoding(). - - Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors - are encoded to UTF-8. */ const char *Py_FileSystemDefaultEncoding = NULL; int Py_HasFileSystemDefaultEncoding = 0; const char *Py_FileSystemDefaultEncodeErrors = NULL; @@ -44,7 +39,10 @@ _Py_ClearFileSystemEncoding(void) /* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors - global configuration variables. */ + global configuration variables to PyConfig.filesystem_encoding and + PyConfig.filesystem_errors (encoded to UTF-8). + + Function called by _PyUnicode_InitEncodings(). */ int _Py_SetFileSystemEncoding(const char *encoding, const char *errors) { @@ -171,6 +169,7 @@ _PyPreCmdline_SetConfig(const _PyPreCmdline *cmdline, PyConfig *config) COPY_ATTR(isolated); COPY_ATTR(use_environment); COPY_ATTR(dev_mode); + COPY_ATTR(warn_default_encoding); return _PyStatus_OK(); #undef COPY_ATTR @@ -259,9 +258,17 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, const PyPreConfig *preconfig) cmdline->dev_mode = 0; } + // warn_default_encoding + if (_Py_get_xoption(&cmdline->xoptions, L"warn_default_encoding") + || _Py_GetEnv(cmdline->use_environment, "PYTHONWARNDEFAULTENCODING")) + { + cmdline->warn_default_encoding = 1; + } + assert(cmdline->use_environment >= 0); assert(cmdline->isolated >= 0); assert(cmdline->dev_mode >= 0); + assert(cmdline->warn_default_encoding >= 0); return _PyStatus_OK(); } @@ -291,7 +298,17 @@ _PyPreConfig_InitCompatConfig(PyPreConfig *config) config->coerce_c_locale_warn = 0; config->dev_mode = -1; +#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS + /* bpo-40512: pymalloc is not compatible with subinterpreters, + force usage of libc malloc() which is thread-safe. */ +#ifdef Py_DEBUG + config->allocator = PYMEM_ALLOCATOR_MALLOC_DEBUG; +#else + config->allocator = PYMEM_ALLOCATOR_MALLOC; +#endif +#else config->allocator = PYMEM_ALLOCATOR_NOT_SET; +#endif #ifdef MS_WINDOWS config->legacy_windows_fs_encoding = -1; #endif @@ -819,13 +836,6 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args) int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag; #endif - if (args) { - status = _PyPreCmdline_SetArgv(&cmdline, args); - if (_PyStatus_EXCEPTION(status)) { - goto done; - } - } - int locale_coerced = 0; int loops = 0; @@ -836,7 +846,7 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args) loops++; if (loops == 3) { status = _PyStatus_ERR("Encoding changed twice while " - "reading the configuration"); + "reading the configuration"); goto done; } @@ -847,6 +857,15 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args) Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding; #endif + if (args) { + // Set command line arguments at each iteration. If they are bytes + // strings, they are decoded from the new encoding. + status = _PyPreCmdline_SetArgv(&cmdline, args); + if (_PyStatus_EXCEPTION(status)) { + goto done; + } + } + status = preconfig_read(config, &cmdline); if (_PyStatus_EXCEPTION(status)) { goto done; @@ -886,7 +905,7 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args) } /* Reset the configuration before reading again the configuration, - just keep UTF-8 Mode value. */ + just keep UTF-8 Mode and coerce C locale value. */ int new_utf8_mode = config->utf8_mode; int new_coerce_c_locale = config->coerce_c_locale; preconfig_copy(config, &save_config); |