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

Skip to content

Commit 90bbaa5

Browse files
author
Victor Stinner
committed
Issue #9992: On Mac OS X, decode command line arguments from utf-8 instead of
the locale encoding.
1 parent eb1410f commit 90bbaa5

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9992: On Mac OS X, decode command line arguments from utf-8 instead of
14+
the locale encoding.
15+
1316
- Issue #9992: Remove PYTHONFSENCODING environment variable.
1417

1518
Library

Modules/python.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ main(int argc, char **argv)
4141
oldloc = strdup(setlocale(LC_ALL, NULL));
4242
setlocale(LC_ALL, "");
4343
for (i = 0; i < argc; i++) {
44-
argv_copy2[i] = argv_copy[i] = _Py_char2wchar(argv[i]);
44+
#ifdef __APPLE__
45+
/* Use utf-8 on Mac OS X */
46+
PyObject *unicode = PyUnicode_FromString(argv[i]);
47+
argv_copy[i] = PyUnicode_AsWideCharString(unicode, NULL);
48+
Py_DECREF(unicode);
49+
#else
50+
argv_copy[i] = _Py_char2wchar(argv[i]);
51+
#endif
52+
argv_copy2[i] = argv_copy[i];
4553
if (!argv_copy[i])
4654
return 1;
4755
}

0 commit comments

Comments
 (0)