Skip to content

Commit

Permalink
lazyload.h: use an even more generic function pointer than FARPROC
Browse files Browse the repository at this point in the history
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.

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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
carenas authored and gitster committed Sep 27, 2021
1 parent d2c470f commit 2d84c4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 6 additions & 3 deletions compat/win32/lazyload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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) {
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion config.mak.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d84c4e

Please sign in to comment.