gh-134041: Make _winapi functions compatible with non-desktop API partitions (GH-134042)

This commit is contained in:
Max Bachmann 2025-05-15 13:50:46 +02:00 committed by GitHub
parent 43410953c2
commit 1c4b34c6cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -1573,6 +1573,7 @@ static PyObject *
_winapi_GetLongPathName_impl(PyObject *module, LPCWSTR path)
/*[clinic end generated code: output=c4774b080275a2d0 input=9872e211e3a4a88f]*/
{
#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)
DWORD cchBuffer;
PyObject *result = NULL;
@ -1596,6 +1597,9 @@ _winapi_GetLongPathName_impl(PyObject *module, LPCWSTR path)
PyErr_SetFromWindowsErr(0);
}
return result;
#else
return PyUnicode_FromWideChar(path, -1);
#endif
}
/*[clinic input]
@ -1632,6 +1636,8 @@ _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle)
return PyUnicode_FromWideChar(filename, wcslen(filename));
}
#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
/*[clinic input]
_winapi.GetShortPathName
@ -1674,6 +1680,8 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path)
return result;
}
#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */
/*[clinic input]
_winapi.GetStdHandle -> HANDLE
@ -2883,6 +2891,7 @@ _winapi_NeedCurrentDirectoryForExePath_impl(PyObject *module,
LPCWSTR exe_name)
/*[clinic end generated code: output=a65ec879502b58fc input=972aac88a1ec2f00]*/
{
#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
BOOL result;
Py_BEGIN_ALLOW_THREADS
@ -2890,6 +2899,9 @@ _winapi_NeedCurrentDirectoryForExePath_impl(PyObject *module,
Py_END_ALLOW_THREADS
return result;
#else
return TRUE;
#endif
}

View file

@ -857,6 +857,8 @@ exit:
return return_value;
}
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
PyDoc_STRVAR(_winapi_GetShortPathName__doc__,
"GetShortPathName($module, /, path)\n"
"--\n"
@ -930,6 +932,8 @@ exit:
return return_value;
}
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
PyDoc_STRVAR(_winapi_GetStdHandle__doc__,
"GetStdHandle($module, std_handle, /)\n"
"--\n"
@ -2161,4 +2165,8 @@ exit:
return return_value;
}
/*[clinic end generated code: output=6cd07628af447d0a input=a9049054013a1b77]*/
#ifndef _WINAPI_GETSHORTPATHNAME_METHODDEF
#define _WINAPI_GETSHORTPATHNAME_METHODDEF
#endif /* !defined(_WINAPI_GETSHORTPATHNAME_METHODDEF) */
/*[clinic end generated code: output=ede63eaaf63aa7e6 input=a9049054013a1b77]*/