[Python-checkins] bpo-31904: Add encoding support for VxWorks RTOS (GH-12051)
Victor Stinner
webhook-mailer at python.org
Mon Mar 4 04:02:32 EST 2019
https://github.com/python/cpython/commit/f4b0a1c0da80318e0a4f4c70d2722f01ce3512dd
commit: f4b0a1c0da80318e0a4f4c70d2722f01ce3512dd
branch: master
author: pxinwr <peixing.xin at windriver.com>
committer: Victor Stinner <vstinner at redhat.com>
date: 2019-03-04T10:02:06+01:00
summary:
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.
files:
A Misc/NEWS.d/next/Core and Builtins/2019-02-26-17-34-49.bpo-31904.R4KSj6.rst
M Doc/c-api/sys.rst
M Doc/c-api/unicode.rst
M Doc/library/sys.rst
M Include/cpython/coreconfig.h
M Python/coreconfig.c
M Python/fileutils.c
diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst
index 0eee35a1285c..c8ea78363dfa 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 39c067d439cc..97c5ebcb1095 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 018f0c9f1061..0fa5bd462294 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 e3ebf7365b94..8ad3b230612c 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 000000000000..29514952fd74
--- /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 e1bf8b523ccf..c3eccb3b192a 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 366bd007e1c9..75e015afaec3 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__ */
}
More information about the Python-checkins
mailing list