[Python-checkins] r85302 - in python/branches/py3k: Modules/getpath.c Python/sysmodule.c

victor.stinner python-checkins at python.org
Thu Oct 7 13:06:50 CEST 2010


Author: victor.stinner
Date: Thu Oct  7 13:06:49 2010
New Revision: 85302

Log:
_wrealpath() and _Py_wreadlink() support surrogates (PEP 383)

Use _Py_wchar2char() to support surrogate characters in the input path.


Modified:
   python/branches/py3k/Modules/getpath.c
   python/branches/py3k/Python/sysmodule.c

Modified: python/branches/py3k/Modules/getpath.c
==============================================================================
--- python/branches/py3k/Modules/getpath.c	(original)
+++ python/branches/py3k/Modules/getpath.c	Thu Oct  7 13:06:49 2010
@@ -179,15 +179,18 @@
 int
 _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
 {
+    char *cpath;
     char cbuf[PATH_MAX];
-    char cpath[PATH_MAX];
     int res;
-    size_t r1 = wcstombs(cpath, path, PATH_MAX);
-    if (r1 == (size_t)-1 || r1 >= PATH_MAX) {
+    size_t r1;
+
+    cpath = _Py_wchar2char(path);
+    if (cpath == NULL) {
         errno = EINVAL;
         return -1;
     }
     res = (int)readlink(cpath, cbuf, PATH_MAX);
+    PyMem_Free(cpath);
     if (res == -1)
         return -1;
     if (res == PATH_MAX) {

Modified: python/branches/py3k/Python/sysmodule.c
==============================================================================
--- python/branches/py3k/Python/sysmodule.c	(original)
+++ python/branches/py3k/Python/sysmodule.c	Thu Oct  7 13:06:49 2010
@@ -1661,16 +1661,17 @@
 static wchar_t*
 _wrealpath(const wchar_t *path, wchar_t *resolved_path)
 {
-    char cpath[PATH_MAX];
+    char *cpath;
     char cresolved_path[PATH_MAX];
     char *res;
     size_t r;
-    r = wcstombs(cpath, path, PATH_MAX);
-    if (r == (size_t)-1 || r >= PATH_MAX) {
+    cpath = _Py_wchar2char(path);
+    if (cpath == NULL) {
         errno = EINVAL;
         return NULL;
     }
     res = realpath(cpath, cresolved_path);
+    PyMem_Free(cpath);
     if (res == NULL)
         return NULL;
     r = mbstowcs(resolved_path, cresolved_path, PATH_MAX);


More information about the Python-checkins mailing list