Commit cc5325b0 authored by Andy Moreton's avatar Andy Moreton Committed by Eli Zaretskii

Pacify -Wcast-function-type warnings in GCC 8.1

* src/image.c: Move attributes into DEF_DLL_FN call.
* src/dynlib.c (dynlib_addr): Use get_proc_addr.
* src/w32.h: (get_proc_addr): New function.
(LOAD_DLL_FN): Use it.
(DEF_DLL_FN): Allow function attributes after argument
list.  Add function pointer type used by LOAD_DLL_FN.
* src/w32.c (open_process_token, get_token_information)
(lookup_account_sid, get_sid_sub_authority)
(get_sid_sub_authority_count, get_security_info)
(get_file_security, set_file_security)
(set_named_security_info)
(get_security_descriptor_owner, get_security_descriptor_group)
(get_security_descriptor_dacl, is_valid_sid, equal_sid)
(get_length_sid, copy_sid, get_native_system_info)
(get_system_times, create_symbolic_link)
(is_valid_security_descriptor, convert_sd_to_sddl)
(convert_sddl_to_sd, get_adapters_info, reg_open_key_ex_w)
(reg_query_value_ex_w, expand_environment_strings_w)
(init_environment, create_toolhelp32_snapshot)
(process32_first, process32_next, open_thread_token)
(impersonate_self, revert_to_self, get_process_memory_info)
(get_process_working_set_size, global_memory_status)
(global_memory_status_ex, init_winsock)
(maybe_load_unicows_dll, globals_of_w32): Use get_proc_addr.
* src/w32fns.c (setup_w32_kbdhook, Ffile_system_info)
(get_dll_version, w32_reset_stack_overflow_guard)
(w32_backtrace, globals_of_w32fns): Use get_proc_addr.
* src/w32font.c (get_outline_metrics_w, get_text_metrics_w)
(get_glyph_outline_w, get_char_width_32_w): Use get_proc_addr.
* src/w32heap.c (init_heap): Use get_proc_addr.
* src/w32menu.c (globals_of_w32menu): Use get_proc_addr.
* src/w32proc.c (init_timers, sys_kill, w32_compare_strings):
Use get_proc_addr.
* src/w32uniscribe.c (syms_of_w32uniscribe): Use get_proc_addr.
parent 58e5f10f
......@@ -156,9 +156,8 @@ dynlib_addr (void *addr, const char **fname, const char **symname)
address we pass to it is not an address of a string, but
an address of a function. So we don't care about the
Unicode version. */
s_pfn_Get_Module_HandleExA =
(GetModuleHandleExA_Proc) GetProcAddress (hm_kernel32,
"GetModuleHandleExA");
s_pfn_Get_Module_HandleExA = (GetModuleHandleExA_Proc)
get_proc_addr (hm_kernel32, "GetModuleHandleExA");
}
if (s_pfn_Get_Module_HandleExA)
{
......
......@@ -5734,7 +5734,7 @@ DEF_DLL_FN (void, png_read_end, (png_structp, png_infop));
DEF_DLL_FN (void, png_error, (png_structp, png_const_charp));
# if (PNG_LIBPNG_VER >= 10500)
DEF_DLL_FN (void, png_longjmp, (png_structp, int)) PNG_NORETURN;
DEF_DLL_FN (void, png_longjmp, (png_structp, int) PNG_NORETURN);
DEF_DLL_FN (jmp_buf *, png_set_longjmp_fn,
(png_structp, png_longjmp_ptr, size_t));
# endif /* libpng version >= 1.5 */
......
This diff is collapsed.
......@@ -164,6 +164,10 @@ extern void reset_standard_handles (int in, int out,
/* Return the string resource associated with KEY of type TYPE. */
extern LPBYTE w32_get_resource (const char * key, LPDWORD type);
/* Load a function from a DLL. Defined in this file. */
typedef void (* VOIDFNPTR) (void);
INLINE VOIDFNPTR get_proc_addr (HINSTANCE handle, LPCSTR fname);
extern void release_listen_threads (void);
extern void init_ntproc (int);
extern void term_ntproc (int);
......@@ -241,14 +245,30 @@ extern ssize_t emacs_gnutls_push (gnutls_transport_ptr_t p,
const void* buf, size_t sz);
#endif /* HAVE_GNUTLS */
/* Definine a function that will be loaded from a DLL. */
#define DEF_DLL_FN(type, func, args) static type (FAR CDECL *fn_##func) args
/* Load a function address from a DLL. Cast the result via "VOIDFNPTR"
to pacify -Wcast-function-type in GCC 8.1. */
INLINE VOIDFNPTR
get_proc_addr (HINSTANCE handle, LPCSTR fname)
{
return (VOIDFNPTR) GetProcAddress (handle, fname);
}
/* Define a function that will be loaded from a DLL. The variable
arguments should contain the argument list for the function, and
optionally be followed by function attributes. For example:
DEF_DLL_FN (void, png_longjmp, (png_structp, int) PNG_NORETURN);
*/
#define DEF_DLL_FN(type, func, ...) \
typedef type (CDECL *W32_PFN_##func) __VA_ARGS__; \
static W32_PFN_##func fn_##func
/* Load a function from the DLL. */
#define LOAD_DLL_FN(lib, func) \
do \
{ \
fn_##func = (void *) GetProcAddress (lib, #func); \
fn_##func = (W32_PFN_##func) get_proc_addr (lib, #func); \
if (!fn_##func) \
return false; \
} \
......
......@@ -2640,7 +2640,7 @@ setup_w32_kbdhook (void)
if (w32_kbdhook_active)
{
IsDebuggerPresent_Proc is_debugger_present = (IsDebuggerPresent_Proc)
GetProcAddress (GetModuleHandle ("kernel32.dll"), "IsDebuggerPresent");
get_proc_addr (GetModuleHandle ("kernel32.dll"), "IsDebuggerPresent");
if (is_debugger_present && is_debugger_present ())
return;
}
......@@ -2655,7 +2655,7 @@ setup_w32_kbdhook (void)
(https://support.microsoft.com/en-us/kb/124103) is used for
NT 4 systems. */
GetConsoleWindow_Proc get_console = (GetConsoleWindow_Proc)
GetProcAddress (GetModuleHandle ("kernel32.dll"), "GetConsoleWindow");
get_proc_addr (GetModuleHandle ("kernel32.dll"), "GetConsoleWindow");
if (get_console != NULL)
kbdhook.console = get_console ();
......@@ -9117,9 +9117,9 @@ DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0,
{
HMODULE hKernel = GetModuleHandle ("kernel32");
GetDiskFreeSpaceExW_Proc pfn_GetDiskFreeSpaceExW =
(GetDiskFreeSpaceExW_Proc) GetProcAddress (hKernel, "GetDiskFreeSpaceExW");
(GetDiskFreeSpaceExW_Proc) get_proc_addr (hKernel, "GetDiskFreeSpaceExW");
GetDiskFreeSpaceExA_Proc pfn_GetDiskFreeSpaceExA =
(GetDiskFreeSpaceExA_Proc) GetProcAddress (hKernel, "GetDiskFreeSpaceExA");
(GetDiskFreeSpaceExA_Proc) get_proc_addr (hKernel, "GetDiskFreeSpaceExA");
bool have_pfn_GetDiskFreeSpaceEx =
((w32_unicode_filenames && pfn_GetDiskFreeSpaceExW)
|| (!w32_unicode_filenames && pfn_GetDiskFreeSpaceExA));
......@@ -9694,8 +9694,8 @@ get_dll_version (const char *dll_name)
if (hdll)
{
DLLGETVERSIONPROC pDllGetVersion
= (DLLGETVERSIONPROC) GetProcAddress (hdll, "DllGetVersion");
DLLGETVERSIONPROC pDllGetVersion = (DLLGETVERSIONPROC)
get_proc_addr (hdll, "DllGetVersion");
if (pDllGetVersion)
{
......@@ -10662,9 +10662,8 @@ void
w32_reset_stack_overflow_guard (void)
{
if (resetstkoflw == NULL)
resetstkoflw =
(_resetstkoflw_proc)GetProcAddress (GetModuleHandle ("msvcrt.dll"),
"_resetstkoflw");
resetstkoflw = (_resetstkoflw_proc)
get_proc_addr (GetModuleHandle ("msvcrt.dll"), "_resetstkoflw");
/* We ignore the return value. If _resetstkoflw fails, the next
stack overflow will crash the program. */
if (resetstkoflw != NULL)
......@@ -10738,9 +10737,8 @@ w32_backtrace (void **buffer, int limit)
if (!s_pfn_CaptureStackBackTrace)
{
hm_kernel32 = LoadLibrary ("Kernel32.dll");
s_pfn_CaptureStackBackTrace =
(CaptureStackBackTrace_proc) GetProcAddress (hm_kernel32,
"RtlCaptureStackBackTrace");
s_pfn_CaptureStackBackTrace = (CaptureStackBackTrace_proc)
get_proc_addr (hm_kernel32, "RtlCaptureStackBackTrace");
}
if (s_pfn_CaptureStackBackTrace)
return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX, limit),
......@@ -10873,29 +10871,29 @@ globals_of_w32fns (void)
it dynamically. Do it once, here, instead of every time it is used.
*/
track_mouse_event_fn = (TrackMouseEvent_Proc)
GetProcAddress (user32_lib, "TrackMouseEvent");
get_proc_addr (user32_lib, "TrackMouseEvent");
monitor_from_point_fn = (MonitorFromPoint_Proc)
GetProcAddress (user32_lib, "MonitorFromPoint");
get_proc_addr (user32_lib, "MonitorFromPoint");
get_monitor_info_fn = (GetMonitorInfo_Proc)
GetProcAddress (user32_lib, "GetMonitorInfoA");
get_proc_addr (user32_lib, "GetMonitorInfoA");
monitor_from_window_fn = (MonitorFromWindow_Proc)
GetProcAddress (user32_lib, "MonitorFromWindow");
get_proc_addr (user32_lib, "MonitorFromWindow");
enum_display_monitors_fn = (EnumDisplayMonitors_Proc)
GetProcAddress (user32_lib, "EnumDisplayMonitors");
get_proc_addr (user32_lib, "EnumDisplayMonitors");
get_title_bar_info_fn = (GetTitleBarInfo_Proc)
GetProcAddress (user32_lib, "GetTitleBarInfo");
get_proc_addr (user32_lib, "GetTitleBarInfo");
{
HMODULE imm32_lib = GetModuleHandle ("imm32.dll");
get_composition_string_fn = (ImmGetCompositionString_Proc)
GetProcAddress (imm32_lib, "ImmGetCompositionStringW");
get_proc_addr (imm32_lib, "ImmGetCompositionStringW");
get_ime_context_fn = (ImmGetContext_Proc)
GetProcAddress (imm32_lib, "ImmGetContext");
get_proc_addr (imm32_lib, "ImmGetContext");
release_ime_context_fn = (ImmReleaseContext_Proc)
GetProcAddress (imm32_lib, "ImmReleaseContext");
get_proc_addr (imm32_lib, "ImmReleaseContext");
set_ime_composition_window_fn = (ImmSetCompositionWindow_Proc)
GetProcAddress (imm32_lib, "ImmSetCompositionWindow");
get_proc_addr (imm32_lib, "ImmSetCompositionWindow");
}
except_code = 0;
......
......@@ -153,7 +153,7 @@ get_outline_metrics_w(HDC hdc, UINT cbData, LPOUTLINETEXTMETRICW lpotmw)
hm_unicows = w32_load_unicows_or_gdi32 ();
if (hm_unicows)
s_pfn_Get_Outline_Text_MetricsW = (GetOutlineTextMetricsW_Proc)
GetProcAddress (hm_unicows, "GetOutlineTextMetricsW");
get_proc_addr (hm_unicows, "GetOutlineTextMetricsW");
}
eassert (s_pfn_Get_Outline_Text_MetricsW != NULL);
return s_pfn_Get_Outline_Text_MetricsW (hdc, cbData, lpotmw);
......@@ -170,7 +170,7 @@ get_text_metrics_w(HDC hdc, LPTEXTMETRICW lptmw)
hm_unicows = w32_load_unicows_or_gdi32 ();
if (hm_unicows)
s_pfn_Get_Text_MetricsW = (GetTextMetricsW_Proc)
GetProcAddress (hm_unicows, "GetTextMetricsW");
get_proc_addr (hm_unicows, "GetTextMetricsW");
}
eassert (s_pfn_Get_Text_MetricsW != NULL);
return s_pfn_Get_Text_MetricsW (hdc, lptmw);
......@@ -188,7 +188,7 @@ get_glyph_outline_w (HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm,
hm_unicows = w32_load_unicows_or_gdi32 ();
if (hm_unicows)
s_pfn_Get_Glyph_OutlineW = (GetGlyphOutlineW_Proc)
GetProcAddress (hm_unicows, "GetGlyphOutlineW");
get_proc_addr (hm_unicows, "GetGlyphOutlineW");
}
eassert (s_pfn_Get_Glyph_OutlineW != NULL);
return s_pfn_Get_Glyph_OutlineW (hdc, uChar, uFormat, lpgm, cbBuffer,
......@@ -206,7 +206,7 @@ get_char_width_32_w (HDC hdc, UINT uFirstChar, UINT uLastChar, LPINT lpBuffer)
hm_unicows = w32_load_unicows_or_gdi32 ();
if (hm_unicows)
s_pfn_Get_Char_Width_32W = (GetCharWidth32W_Proc)
GetProcAddress (hm_unicows, "GetCharWidth32W");
get_proc_addr (hm_unicows, "GetCharWidth32W");
}
eassert (s_pfn_Get_Char_Width_32W != NULL);
return s_pfn_Get_Char_Width_32W (hdc, uFirstChar, uLastChar, lpBuffer);
......
......@@ -250,7 +250,9 @@ init_heap (void)
#ifndef MINGW_W64
/* Set the low-fragmentation heap for OS before Vista. */
HMODULE hm_kernel32dll = LoadLibrary ("kernel32.dll");
HeapSetInformation_Proc s_pfn_Heap_Set_Information = (HeapSetInformation_Proc) GetProcAddress (hm_kernel32dll, "HeapSetInformation");
HeapSetInformation_Proc s_pfn_Heap_Set_Information =
(HeapSetInformation_Proc) get_proc_addr (hm_kernel32dll,
"HeapSetInformation");
if (s_pfn_Heap_Set_Information != NULL)
{
if (s_pfn_Heap_Set_Information ((PVOID) heap,
......@@ -281,7 +283,7 @@ init_heap (void)
in ntdll.dll since XP. */
HMODULE hm_ntdll = LoadLibrary ("ntdll.dll");
RtlCreateHeap_Proc s_pfn_Rtl_Create_Heap
= (RtlCreateHeap_Proc) GetProcAddress (hm_ntdll, "RtlCreateHeap");
= (RtlCreateHeap_Proc) get_proc_addr (hm_ntdll, "RtlCreateHeap");
/* Specific parameters for the private heap. */
RTL_HEAP_PARAMETERS params;
ZeroMemory (&params, sizeof(params));
......
......@@ -1607,9 +1607,13 @@ globals_of_w32menu (void)
#ifndef NTGUI_UNICODE
/* See if Get/SetMenuItemInfo functions are available. */
HMODULE user32 = GetModuleHandle ("user32.dll");
get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA");
set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA");
unicode_append_menu = (AppendMenuW_Proc) GetProcAddress (user32, "AppendMenuW");
unicode_message_box = (MessageBoxW_Proc) GetProcAddress (user32, "MessageBoxW");
get_menu_item_info = (GetMenuItemInfoA_Proc)
get_proc_addr (user32, "GetMenuItemInfoA");
set_menu_item_info = (SetMenuItemInfoA_Proc)
get_proc_addr (user32, "SetMenuItemInfoA");
unicode_append_menu = (AppendMenuW_Proc)
get_proc_addr (user32, "AppendMenuW");
unicode_message_box = (MessageBoxW_Proc)
get_proc_addr (user32, "MessageBoxW");
#endif /* !NTGUI_UNICODE */
}
......@@ -548,9 +548,8 @@ init_timers (void)
through a pointer. */
s_pfn_Get_Thread_Times = NULL; /* in case dumped Emacs comes with a value */
if (os_subtype != OS_9X)
s_pfn_Get_Thread_Times =
(GetThreadTimes_Proc)GetProcAddress (GetModuleHandle ("kernel32.dll"),
"GetThreadTimes");
s_pfn_Get_Thread_Times = (GetThreadTimes_Proc)
get_proc_addr (GetModuleHandle ("kernel32.dll"), "GetThreadTimes");
/* Make sure we start with zeroed out itimer structures, since
dumping may have left there traces of threads long dead. */
......@@ -2691,8 +2690,8 @@ sys_kill (pid_t pid, int sig)
{
g_b_init_debug_break_process = 1;
s_pfn_Debug_Break_Process = (DebugBreakProcess_Proc)
GetProcAddress (GetModuleHandle ("kernel32.dll"),
"DebugBreakProcess");
get_proc_addr (GetModuleHandle ("kernel32.dll"),
"DebugBreakProcess");
}
if (s_pfn_Debug_Break_Process == NULL)
......@@ -3608,9 +3607,9 @@ w32_compare_strings (const char *s1, const char *s2, char *locname,
{
if (os_subtype == OS_9X)
{
pCompareStringW =
(CompareStringW_Proc) GetProcAddress (LoadLibrary ("Unicows.dll"),
"CompareStringW");
pCompareStringW = (CompareStringW_Proc)
get_proc_addr (LoadLibrary ("Unicows.dll"),
"CompareStringW");
if (!pCompareStringW)
{
errno = EINVAL;
......
......@@ -1194,11 +1194,11 @@ syms_of_w32uniscribe (void)
register_font_driver (&uniscribe_font_driver, NULL);
script_get_font_scripts_fn = (ScriptGetFontScriptTags_Proc)
GetProcAddress (uniscribe, "ScriptGetFontScriptTags");
get_proc_addr (uniscribe, "ScriptGetFontScriptTags");
script_get_font_languages_fn = (ScriptGetFontLanguageTags_Proc)
GetProcAddress (uniscribe, "ScriptGetFontLanguageTags");
get_proc_addr (uniscribe, "ScriptGetFontLanguageTags");
script_get_font_features_fn = (ScriptGetFontFeatureTags_Proc)
GetProcAddress (uniscribe, "ScriptGetFontFeatureTags");
get_proc_addr (uniscribe, "ScriptGetFontFeatureTags");
if (script_get_font_scripts_fn
&& script_get_font_languages_fn
&& script_get_font_features_fn)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment