Skip to content

Commit

Permalink
Merge branch 'js/win-lazyload-buildfix' into jch
Browse files Browse the repository at this point in the history
Compilation fix.

* js/win-lazyload-buildfix:
  lazyload.h: use an even more generic function pointer than FARPROC
  lazyload.h: fix warnings about mismatching function pointer types
  • Loading branch information
gitster committed Sep 23, 2021
2 parents 1b27d03 + 912c443 commit 545456c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions compat/mingw.c
Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions compat/win32/lazyload.h
Expand Up @@ -15,18 +15,21 @@
* source, target);
*/

typedef void (*FARVOIDPROC)(void);

struct proc_addr {
const char *const dll;
const char *const function;
FARPROC pfunction;
FARVOIDPROC pfunction;
unsigned initialized : 1;
};

/* Declares a function to be loaded dynamically from a DLL. */
#define DECLARE_PROC_ADDR(dll, rettype, function, ...) \
static struct proc_addr proc_addr_##function = \
{ #dll, #function, NULL, 0 }; \
static rettype (WINAPI *function)(__VA_ARGS__)
typedef rettype (WINAPI *proc_type_##function)(__VA_ARGS__); \
static proc_type_##function function;

/*
* Loads a function from a DLL (once-only).
Expand All @@ -35,9 +38,9 @@ struct proc_addr {
* This function is not thread-safe.
*/
#define INIT_PROC_ADDR(function) \
(function = get_proc_addr(&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 @@ -46,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
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
2 changes: 1 addition & 1 deletion t/helper/test-drop-caches.c
Expand Up @@ -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");
Expand Down

0 comments on commit 545456c

Please sign in to comment.