static gboolean alloc_console_called = FALSE;
+static gboolean gonna_abort = FALSE;
+
+/* This default message will usually be overwritten. */
+/* Yes, a fixed size buffer is bad. So sue me. But g_error is never
+ * with huge strings, is it? */
+static char fatal_msg_buf[1000] = "Unspecified fatal error encountered, aborting.";
+static char *fatal_msg_ptr = fatal_msg_buf;
+
/* Just use stdio. If we're out of memory, we're hosed anyway. */
#undef write
static inline int
-write (FILE *fd,
- const char *buf,
- int len)
+dowrite (FILE *fd,
+ const void *buf,
+ unsigned int len)
{
+ if (gonna_abort)
+ {
+ memcpy (fatal_msg_ptr, buf, len);
+ fatal_msg_ptr += len;
+ *fatal_msg_ptr = 0;
+ return len;
+ }
+
fwrite (buf, len, 1, fd);
fflush (fd);
return len;
}
+
+#define write(fd, buf, len) dowrite(fd, buf, len)
+
static void
ensure_stdout_valid (void)
{
HANDLE handle;
+ if (gonna_abort)
+ return;
+
if (!alloc_console_called)
{
handle = GetStdHandle (STD_OUTPUT_HANDLE);
else
abort ();
#else /* !G_ENABLE_DEBUG || !SIGTRAP */
+#ifdef G_OS_WIN32
+ MessageBox (NULL, fatal_msg_buf, NULL, MB_OK);
+#endif
abort ();
#endif /* !G_ENABLE_DEBUG || !SIGTRAP */
}
* DOS prompt.
*/
fd = stdout;
+ gonna_abort = is_fatal;
#else
- fd = (log_level >= G_LOG_LEVEL_MESSAGE) ? 1 : 2;
+ fd = (log_level > G_LOG_LEVEL_MESSAGE) ? 1 : 2;
#endif
g_mutex_lock (g_messages_lock);