]> granicus.if.org Git - gc/commitdiff
Resolve MessageBoxA at run-time (if requested) in GC_init (Win32)
authorIvan Maidanski <ivmai@mail.ru>
Sat, 2 Aug 2014 08:17:57 +0000 (12:17 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 11 May 2015 15:58:02 +0000 (18:58 +0300)
(and code refactoring of GC_abort)

* misc.c (GC_win32_MessageBoxA): New static routine (only if MSWIN32,
move code from GC_abort).
* misc.c (GC_init, GC_abort): Replace MessageBoxA with
GC_win32_MessageBoxA call (to resolve "MessageBoxA" at run-time if
DONT_USE_USER32_DLL).

Conflicts:

misc.c

misc.c

diff --git a/misc.c b/misc.c
index 6e56c3a267d5e11d0c9c433f7b0b516a27a33136..7db5a88cb02045925008acf17ed23f73c367bd26 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -795,6 +795,29 @@ GC_INNER GC_bool GC_is_initialized = FALSE;
   }
 #endif
 
+#if defined(MSWIN32) && (!defined(SMALL_CONFIG) \
+                         || (!defined(_WIN64) && defined(GC_WIN32_THREADS) \
+                             && defined(CHECK_NOT_WOW64)))
+  STATIC void GC_win32_MessageBoxA(const char *msg, const char *caption,
+                                   unsigned flags)
+  {
+#   ifndef DONT_USE_USER32_DLL
+      /* Use static binding to "user32.dll".    */
+      (void)MessageBoxA(NULL, msg, caption, flags);
+#   else
+      /* This simplifies linking - resolve "MessageBoxA" at run-time. */
+      HINSTANCE hU32 = LoadLibrary(TEXT("user32.dll"));
+      if (hU32) {
+        FARPROC pfn = GetProcAddress(hU32, "MessageBoxA");
+        if (pfn)
+          (void)(*(int (WINAPI *)(HWND, LPCSTR, LPCSTR, UINT))pfn)(
+                              NULL /* hWnd */, msg, caption, flags);
+        (void)FreeLibrary(hU32);
+      }
+#   endif
+  }
+#endif /* MSWIN32 */
+
 STATIC word GC_parse_mem_size_arg(const char *str)
 {
   char *endptr;
@@ -866,7 +889,7 @@ GC_API void GC_CALL GC_init(void)
               && (*(BOOL (WINAPI*)(HANDLE, BOOL*))pfn)(GetCurrentProcess(),
                                                        &bIsWow64)
               && bIsWow64) {
-            MessageBoxA(NULL, "This program uses BDWGC garbage collector"
+            GC_win32_MessageBoxA("This program uses BDWGC garbage collector"
                 " compiled for 32-bit but running on 64-bit Windows.\n"
                 "This is known to be broken due to a design flaw"
                 " in Windows itself! Expect erratic behavior...",
@@ -1686,22 +1709,7 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void)
 
     if (msg != NULL) {
 #     if defined(MSWIN32)
-#       ifndef DONT_USE_USER32_DLL
-          /* Use static binding to "user32.dll".        */
-          (void)MessageBoxA(NULL, msg, "Fatal error in GC",
-                            MB_ICONERROR | MB_OK);
-#       else
-          /* This simplifies linking - resolve "MessageBoxA" at run-time. */
-          HINSTANCE hU32 = LoadLibrary(TEXT("user32.dll"));
-          if (hU32) {
-            FARPROC pfn = GetProcAddress(hU32, "MessageBoxA");
-            if (pfn)
-              (void)(*(int (WINAPI *)(HWND, LPCSTR, LPCSTR, UINT))pfn)(
-                                  NULL /* hWnd */, msg, "Fatal error in GC",
-                                  MB_ICONERROR | MB_OK);
-            (void)FreeLibrary(hU32);
-          }
-#       endif
+        GC_win32_MessageBoxA(msg, "Fatal error in GC", MB_ICONERROR | MB_OK);
         /* Also duplicate msg to GC log file.   */
 #     endif