diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2020-04-19 11:31:28 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2021-08-21 01:04:29 +0300 |
commit | 28ef4eeca3eb3ad231b6b4d540b6a9a739f93293 (patch) | |
tree | 7b55a7a8b4bc75781800e2d018a357eaacee9056 | |
parent | 3cd2ffdd4174c3f253fbc2179bd244cf52340010 (diff) | |
download | bdwgc-28ef4eeca3eb3ad231b6b4d540b6a9a739f93293.tar.gz |
Eliminate 'cast between incompatible func types' warnings for FARPROC vars
(a cherry-pick of commit 95175f0db from 'master')
Direct conversion of GetProcAddress() result (of FARPROC type) to the
required functional type is performed by casting the result to word
type first.
* misc.c [MSGBOX_ON_ERROR && DONT_USE_USER32_DLL]
(GC_win32_MessageBoxA): Cast pfn to word type first.
* win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (GC_thr_init):
Likewise.
* misc.c [GC_WIN32_THREADS && !GC_PTHREADS && !MSWINRT_FLAVOR
&& !MSWINCE] (GC_init): Change pfn type to FARPROC; cast pfn to word
type first and, then, to the required functional type.
* os_dep.c [!OS2 && GWW_VDB] (GetWriteWatch_func): Change type to
FARPROC.
* os_dep.c [!OS2 && GWW_VDB] (GC_GWW_AVAILABLE): Compare
GetWriteWatch_func to 0 instead of NULL.
* os_dep.c [GWW_VDB] (detect_GetWriteWatch, GC_gww_read_dirty): Cast
GetWriteWatch_func to word type first and, then, to the required
functional type.
-rw-r--r-- | misc.c | 12 | ||||
-rw-r--r-- | os_dep.c | 33 | ||||
-rw-r--r-- | win32_threads.c | 4 |
3 files changed, 23 insertions, 26 deletions
@@ -830,7 +830,7 @@ GC_API int GC_CALL GC_is_init_called(void) if (hU32) { FARPROC pfn = GetProcAddress(hU32, "MessageBoxA"); if (pfn) - (void)(*(int (WINAPI *)(HWND, LPCSTR, LPCSTR, UINT))pfn)( + (void)(*(int (WINAPI *)(HWND, LPCSTR, LPCSTR, UINT))(word)pfn)( NULL /* hWnd */, msg, caption, flags); (void)FreeLibrary(hU32); } @@ -957,14 +957,14 @@ GC_API void GC_CALL GC_init(void) # else { # ifndef MSWINCE - BOOL (WINAPI *pfn)(LPCRITICAL_SECTION, DWORD) = 0; + FARPROC pfn = 0; HMODULE hK32 = GetModuleHandle(TEXT("kernel32.dll")); if (hK32) - pfn = (BOOL (WINAPI *)(LPCRITICAL_SECTION, DWORD)) - GetProcAddress(hK32, - "InitializeCriticalSectionAndSpinCount"); + pfn = GetProcAddress(hK32, + "InitializeCriticalSectionAndSpinCount"); if (pfn) { - pfn(&GC_allocate_ml, SPIN_COUNT); + (*(BOOL (WINAPI *)(LPCRITICAL_SECTION, DWORD))(word)pfn)( + &GC_allocate_ml, SPIN_COUNT); } else # endif /* !MSWINCE */ /* else */ InitializeCriticalSection(&GC_allocate_ml); @@ -1640,10 +1640,10 @@ void GC_register_data_segments(void) typedef UINT (WINAPI * GetWriteWatch_type)( DWORD, PVOID, GC_ULONG_PTR /* SIZE_T */, PVOID *, GC_ULONG_PTR *, PULONG); - static GetWriteWatch_type GetWriteWatch_func; + static FARPROC GetWriteWatch_func; static DWORD GetWriteWatch_alloc_flag; -# define GC_GWW_AVAILABLE() (GetWriteWatch_func != NULL) +# define GC_GWW_AVAILABLE() (GetWriteWatch_func != 0) static void detect_GetWriteWatch(void) { @@ -1685,8 +1685,7 @@ void GC_register_data_segments(void) hK32 = GetModuleHandle(TEXT("kernel32.dll")); # endif if (hK32 != (HMODULE)0 && - (GetWriteWatch_func = (GetWriteWatch_type)GetProcAddress(hK32, - "GetWriteWatch")) != NULL) { + (GetWriteWatch_func = GetProcAddress(hK32, "GetWriteWatch")) != 0) { /* Also check whether VirtualAlloc accepts MEM_WRITE_WATCH, */ /* as some versions of kernel32.dll have one but not the */ /* other, making the feature completely broken. */ @@ -1700,24 +1699,23 @@ void GC_register_data_segments(void) /* Check that it actually works. In spite of some */ /* documentation it actually seems to exist on Win2K. */ /* This test may be unnecessary, but ... */ - if (GetWriteWatch_func(WRITE_WATCH_FLAG_RESET, - page, GC_page_size, - pages, - &count, - &page_size) != 0) { + if ((*(GetWriteWatch_type)(word)GetWriteWatch_func)( + WRITE_WATCH_FLAG_RESET, page, + GC_page_size, pages, &count, + &page_size) != 0) { /* GetWriteWatch always fails. */ - GetWriteWatch_func = NULL; + GetWriteWatch_func = 0; } else { GetWriteWatch_alloc_flag = MEM_WRITE_WATCH; } VirtualFree(page, 0 /* dwSize */, MEM_RELEASE); } else { /* GetWriteWatch will be useless. */ - GetWriteWatch_func = NULL; + GetWriteWatch_func = 0; } } # ifndef SMALL_CONFIG - if (GetWriteWatch_func == NULL) { + if (!GetWriteWatch_func) { GC_COND_LOG_PRINTF("Did not find a usable GetWriteWatch()\n"); } else { GC_COND_LOG_PRINTF("Using GetWriteWatch()\n"); @@ -2917,12 +2915,11 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void) /* loop condition. Since each partial call will reset the */ /* status of some pages, this should eventually terminate even */ /* in the overflow case. */ - if (GetWriteWatch_func(WRITE_WATCH_FLAG_RESET, - GC_heap_sects[i].hs_start, - GC_heap_sects[i].hs_bytes, - pages, - &count, - &page_size) != 0) { + if ((*(GetWriteWatch_type)(word)GetWriteWatch_func)( + WRITE_WATCH_FLAG_RESET, + GC_heap_sects[i].hs_start, + GC_heap_sects[i].hs_bytes, + pages, &count, &page_size) != 0) { static int warn_count = 0; struct hblk * start = (struct hblk *)GC_heap_sects[i].hs_start; static struct hblk *last_warned = 0; diff --git a/win32_threads.c b/win32_threads.c index d73ac919..b5e45f06 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2640,8 +2640,8 @@ GC_INNER void GC_thr_init(void) if (hK32) { FARPROC pfn = GetProcAddress(hK32, "IsWow64Process"); if (pfn - && !(*(BOOL (WINAPI*)(HANDLE, BOOL*))pfn)(GetCurrentProcess(), - &isWow64)) + && !(*(BOOL (WINAPI*)(HANDLE, BOOL*))(word)pfn)( + GetCurrentProcess(), &isWow64)) isWow64 = FALSE; /* IsWow64Process failed */ } } |