Index: Python/fileutils.c =================================================================== --- Python/fileutils.c (révision 85310) +++ Python/fileutils.c (copie de travail) @@ -336,7 +336,7 @@ #ifdef HAVE_REALPATH /* Return the canonicalized absolute pathname. Encode path to the locale - encoding, decode the result from the locale encoding. */ + encoding, decode the result from the filesystem encoding. */ wchar_t* _Py_wrealpath(const wchar_t *path, @@ -345,21 +345,28 @@ char *cpath; char cresolved_path[PATH_MAX]; char *res; - size_t r; + Py_ssize_t r; + PyObject *unicode; + cpath = _Py_wchar2char(path); - if (cpath == NULL) { - errno = EINVAL; + if (cpath == NULL) return NULL; - } + res = realpath(cpath, cresolved_path); PyMem_Free(cpath); if (res == NULL) return NULL; - r = mbstowcs(resolved_path, cresolved_path, resolved_path_size); - if (r == (size_t)-1 || r >= PATH_MAX) { - errno = EINVAL; + + unicode = PyUnicode_DecodeFSDefault(cresolved_path); + if (unicode == NULL) return NULL; - } + + r = PyUnicode_AsWideChar((PyUnicodeObject*)unicode, + resolved_path, resolved_path_size); + Py_DECREF(unicode); + if (r == -1 || r == resolved_path_size) + return NULL; + return resolved_path; } #endif