diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2008-11-08 03:46:17 (GMT) |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2008-11-08 03:46:17 (GMT) |
commit | ed29bb49f8c6305d00e589fb503f10d5aedd99a1 (patch) | |
tree | 3fcd44469577c8ef9959800ed08ff3f7dcc927b3 /Modules | |
parent | 3d6f8ff81f96e6ded17c0aeb52d6226b7d9aee35 (diff) | |
download | cpython-ed29bb49f8c6305d00e589fb503f10d5aedd99a1.zip cpython-ed29bb49f8c6305d00e589fb503f10d5aedd99a1.tar.gz cpython-ed29bb49f8c6305d00e589fb503f10d5aedd99a1.tar.bz2 |
Issue #4071: ntpath.abspath returned an empty string for long unicode path.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 39387a9..409974a 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2389,13 +2389,27 @@ posix__getfullpathname(PyObject *self, PyObject *args) if (unicode_file_names()) { PyUnicodeObject *po; if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) { - Py_UNICODE woutbuf[MAX_PATH*2]; + Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po); + Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf; Py_UNICODE *wtemp; - if (!GetFullPathNameW(PyUnicode_AS_UNICODE(po), - sizeof(woutbuf)/sizeof(woutbuf[0]), - woutbuf, &wtemp)) - return win32_error("GetFullPathName", ""); - return PyUnicode_FromUnicode(woutbuf, wcslen(woutbuf)); + DWORD result; + PyObject *v; + result = GetFullPathNameW(wpath, + sizeof(woutbuf)/sizeof(woutbuf[0]), + woutbuf, &wtemp); + if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) { + woutbufp = malloc(result * sizeof(Py_UNICODE)); + if (!woutbufp) + return PyErr_NoMemory(); + result = GetFullPathNameW(wpath, result, woutbufp, &wtemp); + } + if (result) + v = PyUnicode_FromUnicode(woutbufp, wcslen(woutbufp)); + else + v = win32_error_unicode("GetFullPathNameW", wpath); + if (woutbufp != woutbuf) + free(woutbufp); + return v; } /* Drop the argument parsing error as narrow strings are also valid. */ |