8000 Fix GetNamedPipeHandleStateW on non-desktop Windows API partitions (G… · python/cpython@20095fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 20095fb

Browse files
authored
Fix GetNamedPipeHandleStateW on non-desktop Windows API partitions (GH-134049)
1 parent 52a7a22 commit 20095fb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Python/fileutils.c

+37
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,43 @@ _Py_set_blocking(int fd, int blocking)
27842784
return -1;
27852785
}
27862786
#else /* MS_WINDOWS */
2787+
2788+
// The Windows Games API family doesn't expose GetNamedPipeHandleStateW so attempt
2789+
// to load it directly from the Kernel32.dll
2790+
#if !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM)
2791+
BOOL
2792+
GetNamedPipeHandleStateW(HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances, LPDWORD lpMaxCollectionCount,
2793+
LPDWORD lpCollectDataTimeout, LPWSTR lpUserName, DWORD nMaxUserNameSize)
2794+
{
2795+
static int initialized = 0;
2796+
typedef BOOL(__stdcall* PGetNamedPipeHandleStateW) (
2797+
HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances, LPDWORD lpMaxCollectionCount,
2798+
LPDWORD lpCollectDataTimeout, LPWSTR lpUserName, DWORD nMaxUserNameSize);
2799+
static PGetNamedPipeHandleStateW _GetNamedPipeHandleStateW;
2800+
2801+
if (initialized == 0) {
2802+
HMODULE api = LoadLibraryExW(L"Kernel32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
2803+
if (api) {
2804+
_GetNamedPipeHandleStateW = (PGetNamedPipeHandleStateW)GetProcAddress(
2805+
api, "GetNamedPipeHandleStateW");
2806+
}
2807+
else {
2808+
_GetNamedPipeHandleStateW = NULL;
2809+
}
2810+
initialized = 1;
2811+
}
2812+
2813+
if (!_GetNamedPipeHandleStateW) {
2814+
SetLastError(E_NOINTERFACE);
2815+
return FALSE;
2816+
}
2817+
2818+
return _GetNamedPipeHandleStateW(
2819+
hNamedPipe, lpState, lpCurInstances, lpMaxCollectionCount, lpCollectDataTimeout, lpUserName, nMaxUserNameSize
2820+
);
2821+
}
2822+
#endif /* !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */
2823+
27872824
int
27882825
_Py_get_blocking(int fd)
27892826
{

0 commit comments

Comments
 (0)
0