Kaydet (Commit) 5c848a84 authored tarafından Victor Stinner's avatar Victor Stinner

Isse #8589: Decode PYTHONWARNINGS from utf-8 on Mac OS X

Instead of the locale encoding.
üst 4c7db315
...@@ -488,7 +488,6 @@ Py_Main(int argc, wchar_t **argv) ...@@ -488,7 +488,6 @@ Py_Main(int argc, wchar_t **argv)
#else #else
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') { if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
char *buf, *oldloc; char *buf, *oldloc;
wchar_t *wchar;
PyObject *unicode; PyObject *unicode;
/* settle for strtok here as there's no one standard /* settle for strtok here as there's no one standard
...@@ -501,11 +500,16 @@ Py_Main(int argc, wchar_t **argv) ...@@ -501,11 +500,16 @@ Py_Main(int argc, wchar_t **argv)
oldloc = strdup(setlocale(LC_ALL, NULL)); oldloc = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) { for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) {
wchar = _Py_char2wchar(p); #ifdef __APPLE__
/* Use utf-8 on Mac OS X */
unicode = PyUnicode_FromString(p);
#else
wchar_t *wchar = _Py_char2wchar(p);
if (wchar == NULL) if (wchar == NULL)
continue; continue;
unicode = PyUnicode_FromWideChar(wchar, wcslen(wchar)); unicode = PyUnicode_FromWideChar(wchar, wcslen(wchar));
PyMem_Free(wchar); PyMem_Free(wchar);
#endif
if (unicode == NULL) if (unicode == NULL)
continue; continue;
PySys_AddWarnOptionUnicode(unicode); PySys_AddWarnOptionUnicode(unicode);
......
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