Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (révision 80702) +++ Python/pythonrun.c (copie de travail) @@ -264,21 +264,31 @@ _PyImportHooks_Init(); + if (!Py_FileSystemDefaultEncoding) { + /* On Unix, set the file system encoding according to the + user's preference, if the CODESET names a well-known + Python codec, and Py_FileSystemDefaultEncoding isn't + initialized by other means. Also set the encoding of + stdin and stdout if these are terminals. */ #if defined(HAVE_LANGINFO_H) && defined(CODESET) - /* On Unix, set the file system encoding according to the - user's preference, if the CODESET names a well-known - Python codec, and Py_FileSystemDefaultEncoding isn't - initialized by other means. Also set the encoding of - stdin and stdout if these are terminals. */ - - codeset = get_codeset(); - if (codeset) { - if (!Py_FileSystemDefaultEncoding) - Py_FileSystemDefaultEncoding = codeset; - else - free(codeset); + codeset = get_codeset(); +#else + codeset = NULL; +#endif + if (codeset == NULL) + Py_FatalError( + "Py_Initialize: unable to get the locale encoding"); + Py_FileSystemDefaultEncoding = codeset; + } else { + PyObject *codec; + codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding); + if (!codec) { + Py_FatalError( + "Py_Initialize: unable to load the file system codec"); + } else { + Py_DECREF(codec); + } } -#endif if (install_sigs) initsigs(); /* Signal handling stuff, including initintr() */