git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: git@vger.kernel.org
Cc: j6t@kdbg.org, gitster@pobox.com,
	"Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Subject: [PATCH v2] lazyload.h: use an even more generic function pointer than FARPROC
Date: Wed, 22 Sep 2021 23:52:51 -0700	[thread overview]
Message-ID: <20210923065251.21363-1-carenas@gmail.com> (raw)
In-Reply-To: <20210923060306.21073-1-carenas@gmail.com>

gcc will helpfully raise a -Wcast-function-type warning when casting
between functions that might have incompatible return types
(ex: GetUserNameExW returns bool which is only half the size of the
return type from FARPROC which is long long), so create a new type that
could be used as a completely generic function pointer and cast through
it instead.

Because of the way the function declaration was done in the previous
patch the order of variables that use it had to be adjusted so that
it is the last variable declared, as well.

Additionaly remove the -Wno-incompatible-pointer-types temporary
flag added in 27e0c3c (win32: allow building with pedantic mode
enabled, 2021-09-03), as it will be no longer needed.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
v2:
* fixes a silly typo in the previous one
* adds more places where -Wdeclaration-after-statement will trigger

 compat/mingw.c              | 4 ++--
 compat/win32/lazyload.h     | 9 ++++++---
 config.mak.dev              | 1 -
 t/helper/test-drop-caches.c | 2 +-
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 9e0cd1e097..d96fc39bf7 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -2183,10 +2183,10 @@ enum EXTENDED_NAME_FORMAT {
 
 static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)
 {
-	DECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW,
-		enum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG);
 	static wchar_t wbuffer[1024];
 	DWORD len;
+	DECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW,
+		enum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG);
 
 	if (!INIT_PROC_ADDR(GetUserNameExW))
 		return NULL;
diff --git a/compat/win32/lazyload.h b/compat/win32/lazyload.h
index dc35cf080b..c688e545ad 100644
--- a/compat/win32/lazyload.h
+++ b/compat/win32/lazyload.h
@@ -15,10 +15,12 @@
  *                        source, target);
  */
 
+typedef void (*FARVOIDPROC)(void);
+
 struct proc_addr {
 	const char *const dll;
 	const char *const function;
-	FARPROC pfunction;
+	FARVOIDPROC pfunction;
 	unsigned initialized : 1;
 };
 
@@ -38,7 +40,7 @@ struct proc_addr {
 #define INIT_PROC_ADDR(function) \
 	(function = (proc_type_##function)get_proc_addr(&proc_addr_##function))
 
-static inline FARPROC get_proc_addr(struct proc_addr *proc)
+static inline FARVOIDPROC get_proc_addr(struct proc_addr *proc)
 {
 	/* only do this once */
 	if (!proc->initialized) {
@@ -47,7 +49,8 @@ static inline FARPROC get_proc_addr(struct proc_addr *proc)
 		hnd = LoadLibraryExA(proc->dll, NULL,
 				     LOAD_LIBRARY_SEARCH_SYSTEM32);
 		if (hnd)
-			proc->pfunction = GetProcAddress(hnd, proc->function);
+			proc->pfunction = (FARVOIDPROC)GetProcAddress(hnd,
+							proc->function);
 	}
 	/* set ENOSYS if DLL or function was not found */
 	if (!proc->pfunction)
diff --git a/config.mak.dev b/config.mak.dev
index c080ac0231..cdf043c52b 100644
--- a/config.mak.dev
+++ b/config.mak.dev
@@ -12,7 +12,6 @@ DEVELOPER_CFLAGS += -pedantic
 DEVELOPER_CFLAGS += -Wpedantic
 ifneq ($(filter gcc5,$(COMPILER_FEATURES)),)
 DEVELOPER_CFLAGS += -Wno-pedantic-ms-format
-DEVELOPER_CFLAGS += -Wno-incompatible-pointer-types
 endif
 endif
 DEVELOPER_CFLAGS += -Wdeclaration-after-statement
diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
index 7b4278462b..9dccda95b6 100644
--- a/t/helper/test-drop-caches.c
+++ b/t/helper/test-drop-caches.c
@@ -86,9 +86,9 @@ static int cmd_dropcaches(void)
 {
 	HANDLE hProcess = GetCurrentProcess();
 	HANDLE hToken;
-	DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
 	SYSTEM_MEMORY_LIST_COMMAND command;
 	int status;
+	DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
 
 	if (!OpenProcessToken(hProcess, TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken))
 		return error("Can't open current process token");
-- 
2.33.0.911.gbe391d4e11


  parent reply	other threads:[~2021-09-23  6:53 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22 19:56 [PATCH cb/pedantic-build-for-developers] lazyload.h: fix warnings about mismatching function pointer types Johannes Sixt
2021-09-22 20:16 ` Carlo Arenas
2021-09-22 21:21   ` Johannes Sixt
2021-09-23  6:20     ` Carlo Arenas
2021-09-23  6:03 ` [PATCH] lazyload.h: use an even more generic function pointer than FARPROC Carlo Marcelo Arenas Belón
2021-09-23  6:33   ` Johannes Sixt
2021-09-23  6:49     ` Carlo Arenas
2021-09-23  6:52   ` Carlo Marcelo Arenas Belón [this message]
2021-09-26 10:05     ` [PATCH v3 0/2] js/win-lazyload-buildfix Carlo Marcelo Arenas Belón
2021-09-26 10:05       ` [PATCH v3 1/2] lazyload.h: fix warnings about mismatching function pointer types Carlo Marcelo Arenas Belón
2021-09-27  2:58         ` Eric Sunshine
2021-09-26 10:05       ` [PATCH v3 2/2] lazyload.h: use an even more generic function pointer than FARPROC Carlo Marcelo Arenas Belón
2021-09-27 16:35         ` Junio C Hamano
2021-09-27 18:50           ` Carlo Arenas
2021-09-27 20:13             ` Junio C Hamano
2021-09-29  0:48       ` [PATCH v4 0/3] js/win-lazyload-buildfix Carlo Marcelo Arenas Belón
2021-09-29  0:48         ` [PATCH v4 1/3] lazyload.h: fix warnings about mismatching function pointer types Carlo Marcelo Arenas Belón
2021-09-29  0:48         ` [PATCH v4 2/3] lazyload.h: use an even more generic function pointer than FARPROC Carlo Marcelo Arenas Belón
2021-09-29  0:48         ` [PATCH v4 3/3] Makefile: restrict -Wpedantic and -Wno-pedantic-ms-format better Carlo Marcelo Arenas Belón
2021-09-29  1:14           ` Ramsay Jones
2021-09-29  3:19         ` [PATCH v5 0/3] js/win-lazyload-buildfix Carlo Marcelo Arenas Belón
2021-09-29  3:19           ` [PATCH v5 1/3] lazyload.h: fix warnings about mismatching function pointer types Carlo Marcelo Arenas Belón
2021-09-29  3:19           ` [PATCH v5 2/3] lazyload.h: use an even more generic function pointer than FARPROC Carlo Marcelo Arenas Belón
2021-09-29  3:19           ` [PATCH v5 3/3] Makefile: restrict -Wpedantic and -Wno-pedantic-ms-format better Carlo Marcelo Arenas Belón
2021-09-23 21:00 ` [PATCH cb/pedantic-build-for-developers] lazyload.h: fix warnings about mismatching function pointer types Carlo Arenas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210923065251.21363-1-carenas@gmail.com \
    --to=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).