git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] lazyload.h: use an even more generic function pointer than FARPROC

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Sep 23, 2021, 06:52 UTC
Message-ID
<20210923065251.21363-1-carenas@gmail.com>
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
Previous: Carlo ArenasNext: Carlo Marcelo Arenas Belón
Message 8 of 25 in “lazyload.h: fix warnings about mismatching function pointer types”
  1. lazyload.h: fix warnings about mismatching function pointer typesJohannes Sixt, Sep 22, 2021
  2. Carlo ArenasSep 22, 2021
  3. Johannes SixtSep 22, 2021
  4. Carlo ArenasSep 23, 2021
  5. lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 23, 2021
  6. Johannes SixtSep 23, 2021
  7. Carlo ArenasSep 23, 2021
  8. lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 23, 2021
  9. 0/2 js/win-lazyload-buildfixCarlo Marcelo Arenas Belón, Sep 26, 2021
  10. 1/2 lazyload.h: fix warnings about mismatching function pointer typesCarlo Marcelo Arenas Belón, Sep 26, 2021
  11. Eric SunshineSep 27, 2021
  12. 2/2 lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 26, 2021
  13. Junio C HamanoSep 27, 2021
  14. Carlo ArenasSep 27, 2021
  15. Junio C HamanoSep 27, 2021
  16. 0/3 js/win-lazyload-buildfixCarlo Marcelo Arenas Belón, Sep 29, 2021
  17. 1/3 lazyload.h: fix warnings about mismatching function pointer typesCarlo Marcelo Arenas Belón, Sep 29, 2021
  18. 2/3 lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 29, 2021
  19. 3/3 Makefile: restrict -Wpedantic and -Wno-pedantic-ms-format betterCarlo Marcelo Arenas Belón, Sep 29, 2021
  20. Ramsay JonesSep 29, 2021
  21. 0/3 js/win-lazyload-buildfixCarlo Marcelo Arenas Belón, Sep 29, 2021
  22. 1/3 lazyload.h: fix warnings about mismatching function pointer typesCarlo Marcelo Arenas Belón, Sep 29, 2021
  23. 2/3 lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 29, 2021
  24. 3/3 Makefile: restrict -Wpedantic and -Wno-pedantic-ms-format betterCarlo Marcelo Arenas Belón, Sep 29, 2021
  25. Carlo ArenasSep 23, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.