Commit f4b0a1c0 authored by pxinwr's avatar pxinwr Committed by Victor Stinner

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.
parent 8bc401a5
...@@ -108,7 +108,7 @@ Operating System Utilities ...@@ -108,7 +108,7 @@ Operating System Utilities
Encoding, highest priority to lowest priority: 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`` on Windows if :c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
* ``UTF-8`` if the Python UTF-8 mode is enabled; * ``UTF-8`` if the Python UTF-8 mode is enabled;
* ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``, * ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``,
...@@ -154,7 +154,7 @@ Operating System Utilities ...@@ -154,7 +154,7 @@ Operating System Utilities
Encoding, highest priority to lowest priority: 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`` on Windows if :c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
* ``UTF-8`` if the Python UTF-8 mode is enabled; * ``UTF-8`` if the Python UTF-8 mode is enabled;
* ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``, * ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``,
......
...@@ -760,8 +760,8 @@ system. ...@@ -760,8 +760,8 @@ system.
Py_ssize_t len, \ Py_ssize_t len, \
const char *errors) const char *errors)
Decode a string from UTF-8 on Android, or from the current locale encoding Decode a string from UTF-8 on Android and VxWorks, or from the current
on other platforms. The supported locale encoding on other platforms. The supported
error handlers are ``"strict"`` and ``"surrogateescape"`` error handlers are ``"strict"`` and ``"surrogateescape"``
(:pep:`383`). The decoder uses ``"strict"`` error handler if (:pep:`383`). The decoder uses ``"strict"`` error handler if
*errors* is ``NULL``. *str* must end with a null character but *errors* is ``NULL``. *str* must end with a null character but
...@@ -796,8 +796,8 @@ system. ...@@ -796,8 +796,8 @@ system.
.. c:function:: PyObject* PyUnicode_EncodeLocale(PyObject *unicode, const char *errors) .. c:function:: PyObject* PyUnicode_EncodeLocale(PyObject *unicode, const char *errors)
Encode a Unicode object to UTF-8 on Android, or to the current locale Encode a Unicode object to UTF-8 on Android and VxWorks, or to the current
encoding on other platforms. The locale encoding on other platforms. The
supported error handlers are ``"strict"`` and ``"surrogateescape"`` supported error handlers are ``"strict"`` and ``"surrogateescape"``
(:pep:`383`). The encoder uses ``"strict"`` error handler if (:pep:`383`). The encoder uses ``"strict"`` error handler if
*errors* is ``NULL``. Return a :class:`bytes` object. *unicode* cannot *errors* is ``NULL``. Return a :class:`bytes` object. *unicode* cannot
......
...@@ -524,13 +524,17 @@ always available. ...@@ -524,13 +524,17 @@ always available.
* In the UTF-8 mode, the encoding is ``utf-8`` on any platform. * 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 Unix, the encoding is the locale encoding.
* On Windows, the encoding may be ``'utf-8'`` or ``'mbcs'``, depending * On Windows, the encoding may be ``'utf-8'`` or ``'mbcs'``, depending
on user configuration. on user configuration.
* On Android, the encoding is ``'utf-8'``.
* On VxWorks, the encoding is ``'utf-8'``.
.. versionchanged:: 3.2 .. versionchanged:: 3.2
:func:`getfilesystemencoding` result cannot be ``None`` anymore. :func:`getfilesystemencoding` result cannot be ``None`` anymore.
...@@ -1023,7 +1027,7 @@ always available. ...@@ -1023,7 +1027,7 @@ always available.
Linux ``'linux'`` Linux ``'linux'``
Windows ``'win32'`` Windows ``'win32'``
Windows/Cygwin ``'cygwin'`` Windows/Cygwin ``'cygwin'``
Mac OS X ``'darwin'`` macOS ``'darwin'``
================ =========================== ================ ===========================
.. versionchanged:: 3.3 .. versionchanged:: 3.3
......
...@@ -90,8 +90,8 @@ typedef struct { ...@@ -90,8 +90,8 @@ typedef struct {
* The UTF-8 Mode uses UTF-8/surrogateescape; * The UTF-8 Mode uses UTF-8/surrogateescape;
* If Python forces the usage of the ASCII encoding (ex: C locale * If Python forces the usage of the ASCII encoding (ex: C locale
or POSIX locale on FreeBSD or HP-UX), use ASCII/surrogateescape; or POSIX locale on FreeBSD or HP-UX), use ASCII/surrogateescape;
* locale encoding: ANSI code page on Windows, UTF-8 on Android, * locale encoding: ANSI code page on Windows, UTF-8 on Android and
LC_CTYPE locale encoding on other platforms; VxWorks, LC_CTYPE locale encoding on other platforms;
* On Windows, "surrogateescape" error handler; * 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 is "C" or "POSIX";
* "surrogateescape" error handler if the LC_CTYPE locale has been coerced * "surrogateescape" error handler if the LC_CTYPE locale has been coerced
......
...@@ -1280,7 +1280,7 @@ get_locale_encoding(char **locale_encoding) ...@@ -1280,7 +1280,7 @@ get_locale_encoding(char **locale_encoding)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
char encoding[20]; char encoding[20];
PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP()); PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
#elif defined(__ANDROID__) #elif defined(__ANDROID__) || defined(__VXWORKS__)
const char *encoding = "UTF-8"; const char *encoding = "UTF-8";
#else #else
const char *encoding = nl_langinfo(CODESET); const char *encoding = nl_langinfo(CODESET);
......
...@@ -536,7 +536,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen, ...@@ -536,7 +536,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen,
int current_locale, _Py_error_handler errors) int current_locale, _Py_error_handler errors)
{ {
if (current_locale) { if (current_locale) {
#ifdef __ANDROID__ #if defined(__ANDROID__) || defined(__VXWORKS__)
return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason, return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason,
errors); errors);
#else #else
...@@ -544,7 +544,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen, ...@@ -544,7 +544,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen,
#endif #endif
} }
#if defined(__APPLE__) || defined(__ANDROID__) #if defined(__APPLE__) || defined(__ANDROID__) || defined(__VXWORKS__)
return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason, return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason,
errors); errors);
#else #else
...@@ -569,7 +569,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen, ...@@ -569,7 +569,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen,
#endif #endif
return decode_current_locale(arg, wstr, wlen, reason, errors); return decode_current_locale(arg, wstr, wlen, reason, errors);
#endif /* __APPLE__ or __ANDROID__ */ #endif /* __APPLE__ or __ANDROID__ or __VXWORKS__ */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment