Skip to content

Commit

Permalink
mingw: avoid warnings when casting HANDLEs to int
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jan 15, 2016
1 parent 59de49f commit 7c00bc3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "../run-command.h"
#include "../cache.h"

#define HCAST(type, handle) ((type)(intptr_t)handle)

static const int delay[] = { 0, 1, 10, 20, 40 };

int err_win_to_posix(DWORD winerr)
Expand Down Expand Up @@ -691,13 +693,13 @@ int pipe(int filedes[2])
errno = err_win_to_posix(GetLastError());
return -1;
}
filedes[0] = _open_osfhandle((int)h[0], O_NOINHERIT);
filedes[0] = _open_osfhandle(HCAST(int, h[0]), O_NOINHERIT);
if (filedes[0] < 0) {
CloseHandle(h[0]);
CloseHandle(h[1]);
return -1;
}
filedes[1] = _open_osfhandle((int)h[1], O_NOINHERIT);
filedes[1] = _open_osfhandle(HCAST(int, h[1]), O_NOINHERIT);
if (filedes[1] < 0) {
close(filedes[0]);
CloseHandle(h[1]);
Expand Down Expand Up @@ -1846,7 +1848,8 @@ void mingw_open_html(const char *unixpath)
die("cannot run browser");

printf("Launching default browser to display HTML ...\n");
r = (int)ShellExecute(NULL, "open", htmlpath, NULL, "\\", SW_SHOWNORMAL);
r = HCAST(int, ShellExecute(NULL, "open", htmlpath,
NULL, "\\", SW_SHOWNORMAL));
FreeLibrary(shell32);
/* see the MSDN documentation referring to the result codes here */
if (r <= 32) {
Expand Down
2 changes: 1 addition & 1 deletion compat/poll/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

#ifdef WIN32_NATIVE

#define IsConsoleHandle(h) (((long) (h) & 3) == 3)
#define IsConsoleHandle(h) (((long) (intptr_t) (h) & 3) == 3)

static BOOL
IsSocketHandle (HANDLE h)
Expand Down
3 changes: 2 additions & 1 deletion compat/winansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ static HANDLE duplicate_handle(HANDLE hnd)
HANDLE hresult, hproc = GetCurrentProcess();
if (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE,
DUPLICATE_SAME_ACCESS))
die_lasterr("DuplicateHandle(%li) failed", (long) hnd);
die_lasterr("DuplicateHandle(%li) failed",
(long) (intptr_t) hnd);
return hresult;
}

Expand Down

0 comments on commit 7c00bc3

Please sign in to comment.