mingw: avoid warnings when casting HANDLEs to int

HANDLE is defined internally as a void *, but in many cases it is actually guaranteed to be a 32-bit integer. In these cases, GCC should not warn about a cast of a pointer to an integer of a different type because we know exactly what we are doing. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 15, 2016 at 14:24 UTC 7c00bc39eb39a26a9ad33de6e4a03fff45e86f5e
3 files changed +9 -5
compat/mingw.c
+6 -3
@@ -6,6 +6,8 @@
6 #include "../run-command.h"
7 #include "../cache.h"
8
9 +#define HCAST(type, handle) ((type)(intptr_t)handle)
10 +
11 static const int delay[] = { 0, 1, 10, 20, 40 };
12
13 int err_win_to_posix(DWORD winerr)
@@ -691,13 +693,13 @@ int pipe(int filedes[2])
693 errno = err_win_to_posix(GetLastError());
694 return -1;
695 }
694 - filedes[0] = _open_osfhandle((int)h[0], O_NOINHERIT);
696 + filedes[0] = _open_osfhandle(HCAST(int, h[0]), O_NOINHERIT);
697 if (filedes[0] < 0) {
698 CloseHandle(h[0]);
699 CloseHandle(h[1]);
700 return -1;
701 }
700 - filedes[1] = _open_osfhandle((int)h[1], O_NOINHERIT);
702 + filedes[1] = _open_osfhandle(HCAST(int, h[1]), O_NOINHERIT);
703 if (filedes[1] < 0) {
704 close(filedes[0]);
705 CloseHandle(h[1]);
@@ -1846,7 +1848,8 @@ void mingw_open_html(const char *unixpath)
1848 die("cannot run browser");
1849
1850 printf("Launching default browser to display HTML ...\n");
1849 - r = (int)ShellExecute(NULL, "open", htmlpath, NULL, "\\", SW_SHOWNORMAL);
1851 + r = HCAST(int, ShellExecute(NULL, "open", htmlpath,
1852 + NULL, "\\", SW_SHOWNORMAL));
1853 FreeLibrary(shell32);
1854 /* see the MSDN documentation referring to the result codes here */
1855 if (r <= 32) {
compat/poll/poll.c
+1 -1
@@ -76,7 +76,7 @@
76
77 #ifdef WIN32_NATIVE
78
79 -#define IsConsoleHandle(h) (((long) (h) & 3) == 3)
79 +#define IsConsoleHandle(h) (((long) (intptr_t) (h) & 3) == 3)
80
81 static BOOL
82 IsSocketHandle (HANDLE h)
compat/winansi.c
+2 -1
@@ -454,7 +454,8 @@ static HANDLE duplicate_handle(HANDLE hnd)
454 HANDLE hresult, hproc = GetCurrentProcess();
455 if (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE,
456 DUPLICATE_SAME_ACCESS))
457 - die_lasterr("DuplicateHandle(%li) failed", (long) hnd);
457 + die_lasterr("DuplicateHandle(%li) failed",
458 + (long) (intptr_t) hnd);
459 return hresult;
460 }
461