From 5135b9b9e3037a78e6fb8eda347412583a9f536e Mon Sep 17 00:00:00 2001 From: Alexey Pavlov Date: Wed, 3 Sep 2025 22:52:16 +0300 Subject: [PATCH 160/N] Update iscygpty from upstream. Cleanup changes --- Include/iscygpty.h | 2 +- Modules/_multiprocessing/multiprocessing.h | 2 +- Python/iscygpty.c | 67 ++++++++++++---------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Include/iscygpty.h b/Include/iscygpty.h index 82fd0af..b053007 100644 --- a/Include/iscygpty.h +++ b/Include/iscygpty.h @@ -38,4 +38,4 @@ int is_cygpty_used(void); #define is_cygpty_used() 0 #endif -#endif /* _ISCYGPTY_H */ +#endif // _ISCYGPTY_H diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h index a31443b..ba80920 100644 --- a/Modules/_multiprocessing/multiprocessing.h +++ b/Modules/_multiprocessing/multiprocessing.h @@ -30,7 +30,7 @@ # endif # define SEM_HANDLE HANDLE # define SEM_VALUE_MAX LONG_MAX -# define HAVE_MP_SEMAPHORE +# define HAVE_MP_SEMAPHORE # if defined(HAVE_SEM_OPEN) && defined(_POSIX_THREADS) # include # endif diff --git a/Python/iscygpty.c b/Python/iscygpty.c index 722f88f..9976f06 100644 --- a/Python/iscygpty.c +++ b/Python/iscygpty.c @@ -2,7 +2,7 @@ * iscygpty.c -- part of ptycheck * https://github.com/k-takata/ptycheck * - * Copyright (c) 2015-2017 K.Takata + * Copyright (c) 2015-2023 K.Takata * * You can redistribute it and/or modify it under the terms of either * the MIT license (as described below) or the Vim license. @@ -35,18 +35,18 @@ #include #ifdef USE_FILEEXTD -/* VC 7.1 or earlier doesn't support SAL. */ +// VC 7.1 or earlier doesn't support SAL. # if !defined(_MSC_VER) || (_MSC_VER < 1400) # define __out # define __in # define __in_opt # endif -/* Win32 FileID API Library: - * http://www.microsoft.com/en-us/download/details.aspx?id=22599 - * Needed for WinXP. */ +// Win32 FileID API Library: +// http://www.microsoft.com/en-us/download/details.aspx?id=22599 +// Needed for WinXP. # include -#else /* USE_FILEEXTD */ -/* VC 8 or earlier. */ +#else // USE_FILEEXTD +// VC 8 or earlier. # if defined(_MSC_VER) && (_MSC_VER < 1500) # ifdef ENABLE_STUB_IMPL # define STUB_IMPL @@ -54,28 +54,31 @@ # error "Win32 FileID API Library is required for VC2005 or earlier." # endif # endif -#endif /* USE_FILEEXTD */ +#endif // USE_FILEEXTD +#ifdef __MINGW32__ +# define UNUSED __attribute__((unused)) +#else +# define UNUSED +#endif #include "iscygpty.h" //#define USE_DYNFILEID #ifdef USE_DYNFILEID typedef BOOL (WINAPI *pfnGetFileInformationByHandleEx)( - HANDLE hFile, - FILE_INFO_BY_HANDLE_CLASS FileInformationClass, - LPVOID lpFileInformation, - DWORD dwBufferSize -); + HANDLE hFile, + FILE_INFO_BY_HANDLE_CLASS FileInformationClass, + LPVOID lpFileInformation, + DWORD dwBufferSize); static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL; # ifndef USE_FILEEXTD static BOOL WINAPI stub_GetFileInformationByHandleEx( - HANDLE hFile, - FILE_INFO_BY_HANDLE_CLASS FileInformationClass, - LPVOID lpFileInformation, - DWORD dwBufferSize - ) + HANDLE hFile UNUSED, + FILE_INFO_BY_HANDLE_CLASS FileInformationClass UNUSED, + LPVOID lpFileInformation UNUSED, + DWORD dwBufferSize UNUSED) { return FALSE; } @@ -106,14 +109,14 @@ static void setup_fileid_api(void) #define is_wprefix(s, prefix) \ (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0) -/* Check if the fd is a cygwin/msys's pty. */ +// Check if the fd is a cygwin/msys's pty. int is_cygpty(int fd) { #ifdef STUB_IMPL return 0; #else HANDLE h; - int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * (MAX_PATH - 1); + const int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * (MAX_PATH - 1); FILE_NAME_INFO *nameinfo; WCHAR *p = NULL; @@ -123,7 +126,7 @@ int is_cygpty(int fd) if (h == INVALID_HANDLE_VALUE) { return 0; } - /* Cygwin/msys's pty is a pipe. */ + // Cygwin/msys's pty is a pipe. if (GetFileType(h) != FILE_TYPE_PIPE) { return 0; } @@ -131,20 +134,21 @@ int is_cygpty(int fd) if (nameinfo == NULL) { return 0; } - /* Check the name of the pipe: - * '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master' */ + // Check the name of the pipe: + // "\\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master" if (pGetFileInformationByHandleEx(h, FileNameInfo, nameinfo, size)) { nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0'; p = nameinfo->FileName; - if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */ + if (is_wprefix(p, L"\\cygwin-")) { // Cygwin p += 8; - } else if (is_wprefix(p, L"\\msys-")) { /* MSYS and MSYS2 */ + } else if (is_wprefix(p, L"\\msys-")) { // MSYS and MSYS2 p += 6; } else { p = NULL; } if (p != NULL) { - while (*p && isxdigit(*p)) /* Skip 16-digit hexadecimal. */ + // Skip 16-digit hexadecimal. + while (*p && iswascii(*p) && isxdigit(*p)) ++p; if (is_wprefix(p, L"-pty")) { p += 4; @@ -153,7 +157,8 @@ int is_cygpty(int fd) } } if (p != NULL) { - while (*p && isdigit(*p)) /* Skip pty number. */ + // Skip pty number. + while (*p && iswascii(*p) && isdigit(*p)) ++p; if (is_wprefix(p, L"-from-master")) { //p += 12; @@ -166,10 +171,10 @@ int is_cygpty(int fd) } free(nameinfo); return (p != NULL); -#endif /* STUB_IMPL */ +#endif // STUB_IMPL } -/* Check if at least one cygwin/msys pty is used. */ +// Check if at least one cygwin/msys pty is used. int is_cygpty_used(void) { int fd, ret = 0; @@ -180,6 +185,6 @@ int is_cygpty_used(void) return ret; } -#endif /* _WIN32 */ +#endif // _WIN32 -/* vim: set ts=4 sw=4: */ +// vim: set ts=4 sw=4: