summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-08-29 17:32:47 (GMT)
committerGitHub <noreply@github.com>2018-08-29 17:32:47 (GMT)
commitc5989cd87659acbfd4d19dc00dbe99c3a0fc9bd2 (patch)
tree9bd325d65e1cee9696fb98998db0bdb2a2e21b41 /Python
parent70fead25e503a742ad4c919b151b9b2b5facee36 (diff)
downloadcpython-c5989cd87659acbfd4d19dc00dbe99c3a0fc9bd2.zip
cpython-c5989cd87659acbfd4d19dc00dbe99c3a0fc9bd2.tar.gz
cpython-c5989cd87659acbfd4d19dc00dbe99c3a0fc9bd2.tar.bz2
bpo-34523: Py_DecodeLocale() use UTF-8 on Windows (GH-8998)
Py_DecodeLocale() and Py_EncodeLocale() now use the UTF-8 encoding on Windows if Py_LegacyWindowsFSEncodingFlag is zero. pymain_read_conf() now sets Py_LegacyWindowsFSEncodingFlag in its loop, but restore its value at exit.
Diffstat (limited to 'Python')
-rw-r--r--Python/fileutils.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index e756c26..9a3c334 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -499,9 +499,13 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen,
return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason,
surrogateescape);
#else
- if (Py_UTF8Mode == 1) {
- return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason,
- surrogateescape);
+ int use_utf8 = (Py_UTF8Mode == 1);
+#ifdef MS_WINDOWS
+ use_utf8 |= !Py_LegacyWindowsFSEncodingFlag;
+#endif
+ if (use_utf8) {
+ return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen,
+ reason, surrogateescape);
}
#ifdef USE_FORCE_ASCII
@@ -661,7 +665,11 @@ encode_locale_ex(const wchar_t *text, char **str, size_t *error_pos,
return _Py_EncodeUTF8Ex(text, str, error_pos, reason,
raw_malloc, surrogateescape);
#else /* __APPLE__ */
- if (Py_UTF8Mode == 1) {
+ int use_utf8 = (Py_UTF8Mode == 1);
+#ifdef MS_WINDOWS
+ use_utf8 |= !Py_LegacyWindowsFSEncodingFlag;
+#endif
+ if (use_utf8) {
return _Py_EncodeUTF8Ex(text, str, error_pos, reason,
raw_malloc, surrogateescape);
}