Index: Modules/main.c =================================================================== --- Modules/main.c (révision 85298) +++ Modules/main.c (copie de travail) @@ -326,7 +326,27 @@ return run != 0; } +static wchar_t* +redecode_wchar(const wchar_t *text) +{ + char *bytes; + PyObject *unicode; + wchar_t* res; + bytes = _Py_wchar2char(text); + if (bytes == NULL) + return NULL; + + unicode = PyUnicode_DecodeFSDefault(bytes); + PyMem_Free(bytes); + if (unicode == NULL) + return NULL; + + res = PyUnicode_AsWideCharString(unicode, NULL); + Py_DECREF(unicode); + return res; +} + /* Main program */ int @@ -347,6 +367,7 @@ int help = 0; int version = 0; int saw_unbuffered_flag = 0; + int no_fs_encoding; PyCompilerFlags cf; cf.cf_flags = 0; @@ -610,8 +631,21 @@ #else Py_SetProgramName(argv[0]); #endif + + no_fs_encoding = (Py_FileSystemDefaultEncoding == NULL); Py_Initialize(); + /* Redecode the filename from the locale encoding to the filesystem + encoding if initfsencoding() changed the filesystem encoding */ + if (no_fs_encoding && filename != NULL) { + filename = redecode_wchar(filename); + if (filename == NULL) { + fprintf(stderr, "%ls: can't decode filename\n", argv[0]); + PyErr_Print(); + return 1; + } + } + if (Py_VerboseFlag || (command == NULL && filename == NULL && module == NULL && stdin_is_interactive)) { fprintf(stderr, "Python %s on %s\n",