[glib: 2/4] Only call _set_abort_behavior with the ucrt.




commit 77df44371e321cb0f0bbcaa0b9d15b0c714a66e0
Author: Charles Barto <barto charlie gmail com>
Date:   Fri Dec 17 16:05:14 2021 -0800

    Only call _set_abort_behavior with the ucrt.

 glib/gtestutils.c | 22 ++++++++++++----------
 glib/gutils.c     |  6 +++---
 2 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index ebf696c6d..314a9fda3 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -37,8 +37,6 @@
 #ifdef G_OS_WIN32
 #include <io.h>
 #include <windows.h>
-#endif
-#ifdef G_PLATFORM_WIN32
 #include <crtdbg.h>
 #endif
 #include <errno.h>
@@ -1600,20 +1598,24 @@ void
   mutable_test_config_vars.test_undefined = FALSE;
 #endif
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
   // don't open a window for errors (like the "abort() was called one")
-  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
-  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
+  _CrtSetReportMode (_CRT_ERROR, _CRTDBG_MODE_FILE);
+  _CrtSetReportFile (_CRT_ERROR, _CRTDBG_FILE_STDERR);
   // while gtest tests tend to use g_assert and friends
   // if they do use the C standard assert macro we want to
   // output a message to stderr, not open a popup window
-  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
-  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
+  _CrtSetReportMode (_CRT_ASSERT, _CRTDBG_MODE_FILE);
+  _CrtSetReportFile (_CRT_ASSERT, _CRTDBG_FILE_STDERR);
   // in release mode abort() will pop up a windows error
-  // reporting dialog, let's prevent that.
-  _set_abort_behavior(0, _CALL_REPORTFAULT);
+  // reporting dialog, let's prevent that. Only msvcrxx and
+  // the UCRT have this function, but there's no great way to
+  // detect msvcrxx (that I know of) so only call this when using
+  // the UCRT
+#ifdef _UCRT
+  _set_abort_behavior (0, _CALL_REPORTFAULT);
+#endif
 #endif
-
 
   va_start (args, argv);
   while ((option = va_arg (args, char *)))
diff --git a/glib/gutils.c b/glib/gutils.c
index 2789fe157..87f10f69f 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -3160,12 +3160,12 @@ g_check_setuid (void)
 void
 g_abort (void)
 {
-  /* One call to break the debugger 
+  /* One call to break the debugger
    * We check if a debugger is actually attached to
    * avoid a windows error reporting popup window
-   * when run in a test harness / on CI 
+   * when run in a test harness / on CI
    */
-  if(IsDebuggerPresent())
+  if (IsDebuggerPresent ())
     DebugBreak ();
   /* One call in case CRT changes its abort() behaviour */
   abort ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]