comparison Modules/python.c @ 80411:48fbdaf3a849

Issue #16416: OS data are now always encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding (which may be ASCII if no locale environment variable is set), to avoid inconsistencies with os.fsencode() and os.fsdecode() functions which are already using UTF-8/surrogateescape.
author Victor Stinner <victor.stinner@gmail.com>
date Mon, 12 Nov 2012 23:04:02 +0100
parents f77998006917
children 3b344eac6b0f
comparison
equal deleted inserted replaced
80410:9a984c051cde 80411:48fbdaf3a849
12 wmain(int argc, wchar_t **argv) 12 wmain(int argc, wchar_t **argv)
13 { 13 {
14 return Py_Main(argc, argv); 14 return Py_Main(argc, argv);
15 } 15 }
16 #else 16 #else
17
18 #ifdef __APPLE__
19 extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size);
20 #endif
21 17
22 int 18 int
23 main(int argc, char **argv) 19 main(int argc, char **argv)
24 { 20 {
25 wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1)); 21 wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*(argc+1));
43 return 1; 39 return 1;
44 } 40 }
45 oldloc = strdup(setlocale(LC_ALL, NULL)); 41 oldloc = strdup(setlocale(LC_ALL, NULL));
46 setlocale(LC_ALL, ""); 42 setlocale(LC_ALL, "");
47 for (i = 0; i < argc; i++) { 43 for (i = 0; i < argc; i++) {
48 #ifdef __APPLE__
49 argv_copy[i] = _Py_DecodeUTF8_surrogateescape(argv[i], strlen(argv[i]));
50 #else
51 argv_copy[i] = _Py_char2wchar(argv[i], NULL); 44 argv_copy[i] = _Py_char2wchar(argv[i], NULL);
52 #endif
53 if (!argv_copy[i]) { 45 if (!argv_copy[i]) {
54 free(oldloc); 46 free(oldloc);
55 fprintf(stderr, "Fatal Python error: " 47 fprintf(stderr, "Fatal Python error: "
56 "unable to decode the command line argument #%i\n", 48 "unable to decode the command line argument #%i\n",
57 i + 1); 49 i + 1);