]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-31904: Add encoding support for VxWorks RTOS (GH-12051)
authorpxinwr <peixing.xin@windriver.com>
Mon, 4 Mar 2019 09:02:06 +0000 (17:02 +0800)
committerVictor Stinner <vstinner@redhat.com>
Mon, 4 Mar 2019 09:02:06 +0000 (10:02 +0100)
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.

Doc/c-api/sys.rst
Doc/c-api/unicode.rst
Doc/library/sys.rst
Include/cpython/coreconfig.h
Misc/NEWS.d/next/Core and Builtins/2019-02-26-17-34-49.bpo-31904.R4KSj6.rst [new file with mode: 0644]
Python/coreconfig.c
Python/fileutils.c

index 0eee35a1285cc1f635c1f07e97cc5872ca3247f9..c8ea78363dfa51524f542d8f5a0f49ff5c1670b1 100644 (file)
@@ -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"``,
index 39c067d439cc6446ccf0f004c6de3de1e2ffa376..97c5ebcb10953c2b0567c8e8384a02b73995d782 100644 (file)
@@ -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
index 018f0c9f1061f4df411c55f712ee3fff411b3735..0fa5bd462294f8972b9be0b6d5506f9dccfc0e2a 100644 (file)
@@ -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
index e3ebf7365b9416f1a3a6dbc06755592b2aa1e189..8ad3b230612c8c06dc7d0bd56a3f2c36ffda2133 100644 (file)
@@ -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 (file)
index 0000000..2951495
--- /dev/null
@@ -0,0 +1 @@
+Use UTF-8 as the system encoding on VxWorks.
index e1bf8b523ccf8b1eb313c5aa84af654273f33a0d..c3eccb3b192a52fba36dd82fc99f1fe5aae2b67a 100644 (file)
@@ -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);
index 366bd007e1c9374bb9127e99794217dc99e659f5..75e015afaec32becf827a5d1b91bf4e5130aa586 100644 (file)
@@ -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__ */
 }