Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c848a8

Browse files
author
Victor Stinner
committed
Isse #8589: Decode PYTHONWARNINGS from utf-8 on Mac OS X
Instead of the locale encoding.
1 parent 4c7db31 commit 5c848a8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Modules/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ Py_Main(int argc, wchar_t **argv)
488488
#else
489489
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
490490
char *buf, *oldloc;
491-
wchar_t *wchar;
492491
PyObject *unicode;
493492

494493
/* settle for strtok here as there's no one standard
@@ -501,11 +500,16 @@ Py_Main(int argc, wchar_t **argv)
501500
oldloc = strdup(setlocale(LC_ALL, NULL));
502501
setlocale(LC_ALL, "");
503502
for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) {
504-
wchar = _Py_char2wchar(p);
503+
#ifdef __APPLE__
504+
/* Use utf-8 on Mac OS X */
505+
unicode = PyUnicode_FromString(p);
506+
#else
507+
wchar_t *wchar = _Py_char2wchar(p);
505508
if (wchar == NULL)
506509
continue;
507510
unicode = PyUnicode_FromWideChar(wchar, wcslen(wchar));
508511
PyMem_Free(wchar);
512+
#endif
509513
if (unicode == NULL)
510514
continue;
511515
PySys_AddWarnOptionUnicode(unicode);

0 commit comments

Comments
 (0)