diff options
author | pxinwr <peixing.xin@windriver.com> | 2019-03-04 09:02:06 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2019-03-04 09:02:06 (GMT) |
commit | f4b0a1c0da80318e0a4f4c70d2722f01ce3512dd (patch) | |
tree | f10e50c695bdeea8a9aeb06b59ace1d5540af53f | |
parent | 8bc401a55ce5dfcdd225c20786ba8e221a0bf29b (diff) | |
download | cpython-f4b0a1c0da80318e0a4f4c70d2722f01ce3512dd.zip cpython-f4b0a1c0da80318e0a4f4c70d2722f01ce3512dd.tar.gz cpython-f4b0a1c0da80318e0a4f4c70d2722f01ce3512dd.tar.bz2 |
bpo-31904: Add encoding support for VxWorks RTOS (GH-12051)
Use UTF-8 as the system encoding on VxWorks.
The main reason are:
1. The locale is frequently misconfigured.
2. Missing some functions to deal with locale in VxWorks C library.
-rw-r--r-- | Doc/c-api/sys.rst | 4 | ||||
-rw-r--r-- | Doc/c-api/unicode.rst | 8 | ||||
-rw-r--r-- | Doc/library/sys.rst | 8 | ||||
-rw-r--r-- | Include/cpython/coreconfig.h | 4 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2019-02-26-17-34-49.bpo-31904.R4KSj6.rst | 1 | ||||
-rw-r--r-- | Python/coreconfig.c | 2 | ||||
-rw-r--r-- | Python/fileutils.c | 6 |
7 files changed, 19 insertions, 14 deletions
diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst index 0eee35a..c8ea783 100644 --- a/Doc/c-api/sys.rst +++ b/Doc/c-api/sys.rst @@ -108,7 +108,7 @@ Operating System Utilities Encoding, highest priority to lowest priority: - * ``UTF-8`` on macOS and Android; + * ``UTF-8`` on macOS, Android, and VxWorks; * ``UTF-8`` on Windows if :c:data:`Py_LegacyWindowsFSEncodingFlag` is zero; * ``UTF-8`` if the Python UTF-8 mode is enabled; * ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``, @@ -154,7 +154,7 @@ Operating System Utilities Encoding, highest priority to lowest priority: - * ``UTF-8`` on macOS and Android; + * ``UTF-8`` on macOS, Android, and VxWorks; * ``UTF-8`` on Windows if :c:data:`Py_LegacyWindowsFSEncodingFlag` is zero; * ``UTF-8`` if the Python UTF-8 mode is enabled; * ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``, diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 39c067d..97c5ebc 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -760,8 +760,8 @@ system. Py_ssize_t len, \ const char *errors) - Decode a string from UTF-8 on Android, or from the current locale encoding - on other platforms. The supported + Decode a string from UTF-8 on Android and VxWorks, or from the current + locale encoding on other platforms. The supported error handlers are ``"strict"`` and ``"surrogateescape"`` (:pep:`383`). The decoder uses ``"strict"`` error handler if *errors* is ``NULL``. *str* must end with a null character but @@ -796,8 +796,8 @@ system. .. c:function:: PyObject* PyUnicode_EncodeLocale(PyObject *unicode, const char *errors) - Encode a Unicode object to UTF-8 on Android, or to the current locale - encoding on other platforms. The + Encode a Unicode object to UTF-8 on Android and VxWorks, or to the current + locale encoding on other platforms. The supported error handlers are ``"strict"`` and ``"surrogateescape"`` (:pep:`383`). The encoder uses ``"strict"`` error handler if *errors* is ``NULL``. Return a :class:`bytes` object. *unicode* cannot diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 018f0c9..0fa5bd4 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -524,13 +524,17 @@ always available. * In the UTF-8 mode, the encoding is ``utf-8`` on any platform. - * On Mac OS X, the encoding is ``'utf-8'``. + * On macOS, the encoding is ``'utf-8'``. * On Unix, the encoding is the locale encoding. * On Windows, the encoding may be ``'utf-8'`` or ``'mbcs'``, depending on user configuration. + * On Android, the encoding is ``'utf-8'``. + + * On VxWorks, the encoding is ``'utf-8'``. + .. versionchanged:: 3.2 :func:`getfilesystemencoding` result cannot be ``None`` anymore. @@ -1023,7 +1027,7 @@ always available. Linux ``'linux'`` Windows ``'win32'`` Windows/Cygwin ``'cygwin'`` - Mac OS X ``'darwin'`` + macOS ``'darwin'`` ================ =========================== .. versionchanged:: 3.3 diff --git a/Include/cpython/coreconfig.h b/Include/cpython/coreconfig.h index e3ebf73..8ad3b23 100644 --- a/Include/cpython/coreconfig.h +++ b/Include/cpython/coreconfig.h @@ -90,8 +90,8 @@ typedef struct { * The UTF-8 Mode uses UTF-8/surrogateescape; * If Python forces the usage of the ASCII encoding (ex: C locale or POSIX locale on FreeBSD or HP-UX), use ASCII/surrogateescape; - * locale encoding: ANSI code page on Windows, UTF-8 on Android, - LC_CTYPE locale encoding on other platforms; + * locale encoding: ANSI code page on Windows, UTF-8 on Android and + VxWorks, LC_CTYPE locale encoding on other platforms; * On Windows, "surrogateescape" error handler; * "surrogateescape" error handler if the LC_CTYPE locale is "C" or "POSIX"; * "surrogateescape" error handler if the LC_CTYPE locale has been coerced diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-02-26-17-34-49.bpo-31904.R4KSj6.rst b/Misc/NEWS.d/next/Core and Builtins/2019-02-26-17-34-49.bpo-31904.R4KSj6.rst new file mode 100644 index 0000000..2951495 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-02-26-17-34-49.bpo-31904.R4KSj6.rst @@ -0,0 +1 @@ +Use UTF-8 as the system encoding on VxWorks. diff --git a/Python/coreconfig.c b/Python/coreconfig.c index e1bf8b5..c3eccb3 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -1280,7 +1280,7 @@ get_locale_encoding(char **locale_encoding) #ifdef MS_WINDOWS char encoding[20]; PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP()); -#elif defined(__ANDROID__) +#elif defined(__ANDROID__) || defined(__VXWORKS__) const char *encoding = "UTF-8"; #else const char *encoding = nl_langinfo(CODESET); diff --git a/Python/fileutils.c b/Python/fileutils.c index 366bd00..75e015a 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -536,7 +536,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen, int current_locale, _Py_error_handler errors) { if (current_locale) { -#ifdef __ANDROID__ +#if defined(__ANDROID__) || defined(__VXWORKS__) return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason, errors); #else @@ -544,7 +544,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen, #endif } -#if defined(__APPLE__) || defined(__ANDROID__) +#if defined(__APPLE__) || defined(__ANDROID__) || defined(__VXWORKS__) return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason, errors); #else @@ -569,7 +569,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen, #endif return decode_current_locale(arg, wstr, wlen, reason, errors); -#endif /* __APPLE__ or __ANDROID__ */ +#endif /* __APPLE__ or __ANDROID__ or __VXWORKS__ */ } |