Skip to content

Commit f4b0a1c

Browse files
pxinwrvstinner
authored andcommitted
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.
1 parent 8bc401a commit f4b0a1c

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

Doc/c-api/sys.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Operating System Utilities
108108
109109
Encoding, highest priority to lowest priority:
110110
111-
* ``UTF-8`` on macOS and Android;
111+
* ``UTF-8`` on macOS, Android, and VxWorks;
112112
* ``UTF-8`` on Windows if :c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
113113
* ``UTF-8`` if the Python UTF-8 mode is enabled;
114114
* ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``,
@@ -154,7 +154,7 @@ Operating System Utilities
154154
155155
Encoding, highest priority to lowest priority:
156156
157-
* ``UTF-8`` on macOS and Android;
157+
* ``UTF-8`` on macOS, Android, and VxWorks;
158158
* ``UTF-8`` on Windows if :c:data:`Py_LegacyWindowsFSEncodingFlag` is zero;
159159
* ``UTF-8`` if the Python UTF-8 mode is enabled;
160160
* ``ASCII`` if the ``LC_CTYPE`` locale is ``"C"``,

Doc/c-api/unicode.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,8 @@ system.
760760
Py_ssize_t len, \
761761
const char *errors)
762762
763-
Decode a string from UTF-8 on Android, or from the current locale encoding
764-
on other platforms. The supported
763+
Decode a string from UTF-8 on Android and VxWorks, or from the current
764+
locale encoding on other platforms. The supported
765765
error handlers are ``"strict"`` and ``"surrogateescape"``
766766
(:pep:`383`). The decoder uses ``"strict"`` error handler if
767767
*errors* is ``NULL``. *str* must end with a null character but
@@ -796,8 +796,8 @@ system.
796796
797797
.. c:function:: PyObject* PyUnicode_EncodeLocale(PyObject *unicode, const char *errors)
798798
799-
Encode a Unicode object to UTF-8 on Android, or to the current locale
800-
encoding on other platforms. The
799+
Encode a Unicode object to UTF-8 on Android and VxWorks, or to the current
800+
locale encoding on other platforms. The
801801
supported error handlers are ``"strict"`` and ``"surrogateescape"``
802802
(:pep:`383`). The encoder uses ``"strict"`` error handler if
803803
*errors* is ``NULL``. Return a :class:`bytes` object. *unicode* cannot

Doc/library/sys.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,17 @@ always available.
524524

525525
* In the UTF-8 mode, the encoding is ``utf-8`` on any platform.
526526

527-
* On Mac OS X, the encoding is ``'utf-8'``.
527+
* On macOS, the encoding is ``'utf-8'``.
528528

529529
* On Unix, the encoding is the locale encoding.
530530

531531
* On Windows, the encoding may be ``'utf-8'`` or ``'mbcs'``, depending
532532
on user configuration.
533533

534+
* On Android, the encoding is ``'utf-8'``.
535+
536+
* On VxWorks, the encoding is ``'utf-8'``.
537+
534538
.. versionchanged:: 3.2
535539
:func:`getfilesystemencoding` result cannot be ``None`` anymore.
536540

@@ -1023,7 +1027,7 @@ always available.
10231027
Linux ``'linux'``
10241028
Windows ``'win32'``
10251029
Windows/Cygwin ``'cygwin'``
1026-
Mac OS X ``'darwin'``
1030+
macOS ``'darwin'``
10271031
================ ===========================
10281032

10291033
.. versionchanged:: 3.3

Include/cpython/coreconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ typedef struct {
9090
* The UTF-8 Mode uses UTF-8/surrogateescape;
9191
* If Python forces the usage of the ASCII encoding (ex: C locale
9292
or POSIX locale on FreeBSD or HP-UX), use ASCII/surrogateescape;
93-
* locale encoding: ANSI code page on Windows, UTF-8 on Android,
94-
LC_CTYPE locale encoding on other platforms;
93+
* locale encoding: ANSI code page on Windows, UTF-8 on Android and
94+
VxWorks, LC_CTYPE locale encoding on other platforms;
9595
* On Windows, "surrogateescape" error handler;
9696
* "surrogateescape" error handler if the LC_CTYPE locale is "C" or "POSIX";
9797
* "surrogateescape" error handler if the LC_CTYPE locale has been coerced
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use UTF-8 as the system encoding on VxWorks.

Python/coreconfig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ get_locale_encoding(char **locale_encoding)
12801280
#ifdef MS_WINDOWS
12811281
char encoding[20];
12821282
PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
1283-
#elif defined(__ANDROID__)
1283+
#elif defined(__ANDROID__) || defined(__VXWORKS__)
12841284
const char *encoding = "UTF-8";
12851285
#else
12861286
const char *encoding = nl_langinfo(CODESET);

Python/fileutils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,15 +536,15 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen,
536536
int current_locale, _Py_error_handler errors)
537537
{
538538
if (current_locale) {
539-
#ifdef __ANDROID__
539+
#if defined(__ANDROID__) || defined(__VXWORKS__)
540540
return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason,
541541
errors);
542542
#else
543543
return decode_current_locale(arg, wstr, wlen, reason, errors);
544544
#endif
545545
}
546546

547-
#if defined(__APPLE__) || defined(__ANDROID__)
547+
#if defined(__APPLE__) || defined(__ANDROID__) || defined(__VXWORKS__)
548548
return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason,
549549
errors);
550550
#else
@@ -569,7 +569,7 @@ _Py_DecodeLocaleEx(const char* arg, wchar_t **wstr, size_t *wlen,
569569
#endif
570570

571571
return decode_current_locale(arg, wstr, wlen, reason, errors);
572-
#endif /* __APPLE__ or __ANDROID__ */
572+
#endif /* __APPLE__ or __ANDROID__ or __VXWORKS__ */
573573
}
574574

575575

0 commit comments

Comments
 (0)