{"thread":{"id":"41198","subject":"[PATCH 2/4] mingw: avoid warnings when casting HANDLEs to int","startedAt":"2016-01-15T13:24:19Z","lastAt":"2016-01-16T17:00:09Z","messageCount":7,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"276153","messageId":"cover.1452864241.git.johannes.schindelin@gmx.de","threadId":"41198","inReplyTo":null,"subject":"[PATCH 0/4] Fix compile warnings with MSys2's compiler","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-01-15T13:24:19Z","receivedAt":"2016-01-15T13:24:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"This is the second batch of Windows-specific patches from the Git for\nWindows project. Naturally, it is based on the first batch of patches\nthat fixed the compile errors.\n\nPlease note that this series does the *minimal* job of fixing the\ncompile warnings. Don't try to run the tests, they will still fail. You\nhave been warned.\n\n\nJohannes Schindelin (4):\n  mingw: avoid redefining S_* constants\n  mingw: avoid warnings when casting HANDLEs to int\n  mingw: squash another warning about a cast\n  mingw: uglify (a, 0) definitions to shut up warnings\n\n compat/mingw.c              | 9 ++++++---\n compat/mingw.h              | 4 ++++\n compat/nedmalloc/malloc.c.h | 3 ++-\n compat/poll/poll.c          | 2 +-\n compat/win32/pthread.h      | 7 +++++--\n compat/winansi.c            | 3 ++-\n 6 files changed, 20 insertions(+), 8 deletions(-)\n\n-- \n2.7.0.windows.1.7.g55a05c8\n"},{"id":"276154","messageId":"0049b80c17e14722a217d208e0400975c4d0a024.1452864241.git.johannes.schindelin@gmx.de","threadId":"41198","inReplyTo":"cover.1452864241.git.johannes.schindelin@gmx.de","subject":"[PATCH 1/4] mingw: avoid redefining S_* constants","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-01-15T13:24:29Z","receivedAt":"2016-01-15T13:24:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When compiling with MSys2's compiler, these constants are already defined.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n compat/mingw.h | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex b3e5044..3a404ff 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -14,14 +14,18 @@ typedef int socklen_t;\n #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)\n #define S_ISSOCK(x) 0\n \n+#ifndef S_IRWXG\n #define S_IRGRP 0\n #define S_IWGRP 0\n #define S_IXGRP 0\n #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)\n+#endif\n+#ifndef S_IRWXO\n #define S_IROTH 0\n #define S_IWOTH 0\n #define S_IXOTH 0\n #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)\n+#endif\n \n #define S_ISUID 0004000\n #define S_ISGID 0002000\n-- \n2.7.0.windows.1.7.g55a05c8\n"},{"id":"276152","messageId":"61a69db5495c2ea16f98fab58e160dc575f73179.1452864241.git.johannes.schindelin@gmx.de","threadId":"41198","inReplyTo":"cover.1452864241.git.johannes.schindelin@gmx.de","subject":"[PATCH 2/4] mingw: avoid warnings when casting HANDLEs to int","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-01-15T13:24:34Z","receivedAt":"2016-01-15T13:24:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"HANDLE is defined internally as a void *, but in many cases it is\nactually guaranteed to be a 32-bit integer. In these cases, GCC should\nnot warn about a cast of a pointer to an integer of a different type\nbecause we know exactly what we are doing.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n compat/mingw.c     | 9 ++++++---\n compat/poll/poll.c | 2 +-\n compat/winansi.c   | 3 ++-\n 3 files changed, 9 insertions(+), 5 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 1b3530a..8437c9a 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -6,6 +6,8 @@\n #include \"../run-command.h\"\n #include \"../cache.h\"\n \n+#define HCAST(type, handle) ((type)(intptr_t)handle)\n+\n static const int delay[] = { 0, 1, 10, 20, 40 };\n \n int err_win_to_posix(DWORD winerr)\n@@ -691,13 +693,13 @@ int pipe(int filedes[2])\n \t\terrno = err_win_to_posix(GetLastError());\n \t\treturn -1;\n \t}\n-\tfiledes[0] = _open_osfhandle((int)h[0], O_NOINHERIT);\n+\tfiledes[0] = _open_osfhandle(HCAST(int, h[0]), O_NOINHERIT);\n \tif (filedes[0] < 0) {\n \t\tCloseHandle(h[0]);\n \t\tCloseHandle(h[1]);\n \t\treturn -1;\n \t}\n-\tfiledes[1] = _open_osfhandle((int)h[1], O_NOINHERIT);\n+\tfiledes[1] = _open_osfhandle(HCAST(int, h[1]), O_NOINHERIT);\n \tif (filedes[1] < 0) {\n \t\tclose(filedes[0]);\n \t\tCloseHandle(h[1]);\n@@ -1846,7 +1848,8 @@ void mingw_open_html(const char *unixpath)\n \t\tdie(\"cannot run browser\");\n \n \tprintf(\"Launching default browser to display HTML ...\\n\");\n-\tr = (int)ShellExecute(NULL, \"open\", htmlpath, NULL, \"\\\\\", SW_SHOWNORMAL);\n+\tr = HCAST(int, ShellExecute(NULL, \"open\", htmlpath,\n+\t\t\t\tNULL, \"\\\\\", SW_SHOWNORMAL));\n \tFreeLibrary(shell32);\n \t/* see the MSDN documentation referring to the result codes here */\n \tif (r <= 32) {\ndiff --git a/compat/poll/poll.c b/compat/poll/poll.c\nindex db4e03e..b10adc7 100644\n--- a/compat/poll/poll.c\n+++ b/compat/poll/poll.c\n@@ -76,7 +76,7 @@\n \n #ifdef WIN32_NATIVE\n \n-#define IsConsoleHandle(h) (((long) (h) & 3) == 3)\n+#define IsConsoleHandle(h) (((long) (intptr_t) (h) & 3) == 3)\n \n static BOOL\n IsSocketHandle (HANDLE h)\ndiff --git a/compat/winansi.c b/compat/winansi.c\nindex ceff55b..4549848 100644\n--- a/compat/winansi.c\n+++ b/compat/winansi.c\n@@ -452,7 +452,8 @@ static HANDLE duplicate_handle(HANDLE hnd)\n \tHANDLE hresult, hproc = GetCurrentProcess();\n \tif (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE,\n \t\t\tDUPLICATE_SAME_ACCESS))\n-\t\tdie_lasterr(\"DuplicateHandle(%li) failed\", (long) hnd);\n+\t\tdie_lasterr(\"DuplicateHandle(%li) failed\",\n+\t\t\t(long) (intptr_t) hnd);\n \treturn hresult;\n }\n \n-- \n2.7.0.windows.1.7.g55a05c8\n"},{"id":"276156","messageId":"8075ca3dff83486406b05b1701d025727ab86da9.1452864241.git.johannes.schindelin@gmx.de","threadId":"41198","inReplyTo":"cover.1452864241.git.johannes.schindelin@gmx.de","subject":"[PATCH 3/4] mingw: squash another warning about a cast","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-01-15T13:24:39Z","receivedAt":"2016-01-15T13:24:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"MSys2's compiler is correct that casting a \"void *\" to a \"DWORD\" loses\nprecision, but in the case of pthread_exit() we know that the value\nfits into a DWORD.\n\nJust like casting handles to DWORDs, let's work around this issue by\ncasting to \"intrptr_t\" first, and immediately cast to the final type.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n compat/win32/pthread.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/compat/win32/pthread.h b/compat/win32/pthread.h\nindex 8ad1873..d3dd872 100644\n--- a/compat/win32/pthread.h\n+++ b/compat/win32/pthread.h\n@@ -77,7 +77,7 @@ extern pthread_t pthread_self(void);\n \n static inline int pthread_exit(void *ret)\n {\n-\tExitThread((DWORD)ret);\n+\tExitThread((DWORD)(intptr_t)ret);\n }\n \n typedef DWORD pthread_key_t;\n-- \n2.7.0.windows.1.7.g55a05c8\n"},{"id":"276155","messageId":"717146db7aa98d8f5e5b730b44a6fe2aae5e77a3.1452864241.git.johannes.schindelin@gmx.de","threadId":"41198","inReplyTo":"cover.1452864241.git.johannes.schindelin@gmx.de","subject":"[PATCH 4/4] mingw: uglify (a, 0) definitions to shut up warnings","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-01-15T13:24:45Z","receivedAt":"2016-01-15T13:24:45Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When the result of a (a, 0) expression is not used, MSys2's GCC version\nfinds it necessary to complain with a warning:\n\n\tright-hand operand of comma expression has no effect\n\nLet's just pretend to use the 0 value and have a peaceful and quiet life\nagain.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n compat/nedmalloc/malloc.c.h | 3 ++-\n compat/win32/pthread.h      | 5 ++++-\n 2 files changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/compat/nedmalloc/malloc.c.h b/compat/nedmalloc/malloc.c.h\nindex f216a2a..ac0b7b4 100644\n--- a/compat/nedmalloc/malloc.c.h\n+++ b/compat/nedmalloc/malloc.c.h\n@@ -1798,9 +1798,10 @@ struct win32_mlock_t\n   volatile long threadid;\n };\n \n+static inline int return_0(int i) { return 0; }\n #define MLOCK_T               struct win32_mlock_t\n #define CURRENT_THREAD        win32_getcurrentthreadid()\n-#define INITIAL_LOCK(sl)      (memset(sl, 0, sizeof(MLOCK_T)), 0)\n+#define INITIAL_LOCK(sl)      (memset(sl, 0, sizeof(MLOCK_T)), return_0(0))\n #define ACQUIRE_LOCK(sl)      win32_acquire_lock(sl)\n #define RELEASE_LOCK(sl)      win32_release_lock(sl)\n #define TRY_LOCK(sl)          win32_try_lock(sl)\ndiff --git a/compat/win32/pthread.h b/compat/win32/pthread.h\nindex d3dd872..20b35a2 100644\n--- a/compat/win32/pthread.h\n+++ b/compat/win32/pthread.h\n@@ -18,7 +18,10 @@\n  */\n #define pthread_mutex_t CRITICAL_SECTION\n \n-#define pthread_mutex_init(a,b) (InitializeCriticalSection((a)), 0)\n+static inline int return_0(int i) {\n+\treturn 0;\n+}\n+#define pthread_mutex_init(a,b) return_0((InitializeCriticalSection((a)), 0))\n #define pthread_mutex_destroy(a) DeleteCriticalSection((a))\n #define pthread_mutex_lock EnterCriticalSection\n #define pthread_mutex_unlock LeaveCriticalSection\n-- \n2.7.0.windows.1.7.g55a05c8\n"},{"id":"276216","messageId":"xmqqh9iefnj2.fsf@gitster.mtv.corp.google.com","threadId":"41198","inReplyTo":"cover.1452864241.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH 0/4] Fix compile warnings with MSys2's compiler","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-15T23:09:21Z","receivedAt":"2016-01-15T23:09:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, queued.\n\nThe last one does look ugly as you said; I do not think of a better\nalternative to offer, though X-<.\n"},{"id":"276231","messageId":"alpine.DEB.2.20.1601161759190.2964@virtualbox","threadId":"41198","inReplyTo":"xmqqh9iefnj2.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH 0/4] Fix compile warnings with MSys2's compiler","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-01-16T17:00:09Z","receivedAt":"2016-01-16T17:00:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Fri, 15 Jan 2016, Junio C Hamano wrote:\n\n> Thanks, queued.\n\nThank you!\n\n> The last one does look ugly as you said; I do not think of a better\n> alternative to offer, though X-<.\n\nIt makes me happy that I did not miss any obvious way to make this look\nbetter, and it makes me sad you cannot find a better alternative either\n;-)\n\nCiao,\nDscho\n"}]}