mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
bpo-46362: Ensure ntpath.abspath() uses the Windows API correctly (GH-30571)
This makes ntpath.abspath()/getpath_abspath() follow normpath(), since some WinAPIs such as PathCchSkipRoot() require backslashed paths.
This commit is contained in:
parent
b8ddf7e794
commit
d4e64cd4b0
8 changed files with 114 additions and 42 deletions
|
@ -2049,42 +2049,7 @@ _Py_abspath(const wchar_t *path, wchar_t **abspath_p)
|
|||
}
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
wchar_t woutbuf[MAX_PATH], *woutbufp = woutbuf;
|
||||
DWORD result;
|
||||
|
||||
result = GetFullPathNameW(path,
|
||||
Py_ARRAY_LENGTH(woutbuf), woutbuf,
|
||||
NULL);
|
||||
if (!result) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (result >= Py_ARRAY_LENGTH(woutbuf)) {
|
||||
if ((size_t)result <= (size_t)PY_SSIZE_T_MAX / sizeof(wchar_t)) {
|
||||
woutbufp = PyMem_RawMalloc((size_t)result * sizeof(wchar_t));
|
||||
}
|
||||
else {
|
||||
woutbufp = NULL;
|
||||
}
|
||||
if (!woutbufp) {
|
||||
*abspath_p = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = GetFullPathNameW(path, result, woutbufp, NULL);
|
||||
if (!result) {
|
||||
PyMem_RawFree(woutbufp);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (woutbufp != woutbuf) {
|
||||
*abspath_p = woutbufp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*abspath_p = _PyMem_RawWcsdup(woutbufp);
|
||||
return 0;
|
||||
return _PyOS_getfullpathname(path, abspath_p);
|
||||
#else
|
||||
wchar_t cwd[MAXPATHLEN + 1];
|
||||
cwd[Py_ARRAY_LENGTH(cwd) - 1] = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue