diff --git a/ChangeLog b/ChangeLog index 84e1b912f..128d56ab3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2003-01-01 Tor Lillqvist + + * glib/gmessages.c (ensure_stderr_valid): New function, parallel + to ensure_stdout_valid(). #defined as empty on Unix. Move the + alloc_console_called static flag inside these two functions. + (mklevel_prefix): Do use either stderr or stdout on Windows, + too. Otherwise g_warning() messages (that are just warnings, by + definition) will get mixed with proper stdout output. Noticed in + GIMP's gimpconfig-dump. + (strdup_convert, mklevel_prefix, g_printerr): Call + ensure_stderr_valid() before trying to use stderr. + (g_logv): [Win32] Convert message to current codepage before + display with MessageBox(). + 2002-12-28 Tõivo Leedjärv * configure.in: Added et to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 84e1b912f..128d56ab3 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +2003-01-01 Tor Lillqvist + + * glib/gmessages.c (ensure_stderr_valid): New function, parallel + to ensure_stdout_valid(). #defined as empty on Unix. Move the + alloc_console_called static flag inside these two functions. + (mklevel_prefix): Do use either stderr or stdout on Windows, + too. Otherwise g_warning() messages (that are just warnings, by + definition) will get mixed with proper stdout output. Noticed in + GIMP's gimpconfig-dump. + (strdup_convert, mklevel_prefix, g_printerr): Call + ensure_stderr_valid() before trying to use stderr. + (g_logv): [Win32] Convert message to current codepage before + display with MessageBox(). + 2002-12-28 Tõivo Leedjärv * configure.in: Added et to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 84e1b912f..128d56ab3 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,17 @@ +2003-01-01 Tor Lillqvist + + * glib/gmessages.c (ensure_stderr_valid): New function, parallel + to ensure_stdout_valid(). #defined as empty on Unix. Move the + alloc_console_called static flag inside these two functions. + (mklevel_prefix): Do use either stderr or stdout on Windows, + too. Otherwise g_warning() messages (that are just warnings, by + definition) will get mixed with proper stdout output. Noticed in + GIMP's gimpconfig-dump. + (strdup_convert, mklevel_prefix, g_printerr): Call + ensure_stderr_valid() before trying to use stderr. + (g_logv): [Win32] Convert message to current codepage before + display with MessageBox(). + 2002-12-28 Tõivo Leedjärv * configure.in: Added et to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 84e1b912f..128d56ab3 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,17 @@ +2003-01-01 Tor Lillqvist + + * glib/gmessages.c (ensure_stderr_valid): New function, parallel + to ensure_stdout_valid(). #defined as empty on Unix. Move the + alloc_console_called static flag inside these two functions. + (mklevel_prefix): Do use either stderr or stdout on Windows, + too. Otherwise g_warning() messages (that are just warnings, by + definition) will get mixed with proper stdout output. Noticed in + GIMP's gimpconfig-dump. + (strdup_convert, mklevel_prefix, g_printerr): Call + ensure_stderr_valid() before trying to use stderr. + (g_logv): [Win32] Convert message to current codepage before + display with MessageBox(). + 2002-12-28 Tõivo Leedjärv * configure.in: Added et to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 84e1b912f..128d56ab3 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,17 @@ +2003-01-01 Tor Lillqvist + + * glib/gmessages.c (ensure_stderr_valid): New function, parallel + to ensure_stdout_valid(). #defined as empty on Unix. Move the + alloc_console_called static flag inside these two functions. + (mklevel_prefix): Do use either stderr or stdout on Windows, + too. Otherwise g_warning() messages (that are just warnings, by + definition) will get mixed with proper stdout output. Noticed in + GIMP's gimpconfig-dump. + (strdup_convert, mklevel_prefix, g_printerr): Call + ensure_stderr_valid() before trying to use stderr. + (g_logv): [Win32] Convert message to current codepage before + display with MessageBox(). + 2002-12-28 Tõivo Leedjärv * configure.in: Added et to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 84e1b912f..128d56ab3 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,17 @@ +2003-01-01 Tor Lillqvist + + * glib/gmessages.c (ensure_stderr_valid): New function, parallel + to ensure_stdout_valid(). #defined as empty on Unix. Move the + alloc_console_called static flag inside these two functions. + (mklevel_prefix): Do use either stderr or stdout on Windows, + too. Otherwise g_warning() messages (that are just warnings, by + definition) will get mixed with proper stdout output. Noticed in + GIMP's gimpconfig-dump. + (strdup_convert, mklevel_prefix, g_printerr): Call + ensure_stderr_valid() before trying to use stderr. + (g_logv): [Win32] Convert message to current codepage before + display with MessageBox(). + 2002-12-28 Tõivo Leedjärv * configure.in: Added et to ALL_LINGUAS. diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 940843164..71e0f94d3 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +2003-01-01 Tor Lillqvist + + * glib/tmpl/messages.sgml (g_log_default_handler): Remove note + that only stdout would be used on Windows, no longer true. + 2002-12-15 Matthias Clasen * gobject/tmpl/param_value_types.sgml: Move some docs inline. diff --git a/docs/reference/glib/tmpl/messages.sgml b/docs/reference/glib/tmpl/messages.sgml index 57c773bc9..0f4920384 100644 --- a/docs/reference/glib/tmpl/messages.sgml +++ b/docs/reference/glib/tmpl/messages.sgml @@ -242,7 +242,6 @@ and if the log level is fatal it calls abort(). stderr is used for levels %G_LOG_LEVEL_ERROR, %G_LOG_LEVEL_CRITICAL, and %G_LOG_LEVEL_WARNING. stdout is used for the rest. -(On the Windows platform, stdout is always used.) @log_domain: the log domain of the message. diff --git a/glib/gmessages.c b/glib/gmessages.c index 820c3eeb8..d2b8efb31 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -87,7 +87,6 @@ static GLogLevelFlags g_log_msg_prefix = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING # include # undef STRICT # include /* For _getpid() */ -static gboolean alloc_console_called = FALSE; static gboolean win32_keep_fatal_message = FALSE; /* This default message will usually be overwritten. */ @@ -122,6 +121,7 @@ dowrite (GFileDescriptor fd, static void ensure_stdout_valid (void) { + static gboolean alloc_console_called = FALSE; HANDLE handle; if (win32_keep_fatal_message) @@ -139,8 +139,32 @@ ensure_stdout_valid (void) } } } + +static void +ensure_stderr_valid (void) +{ + static gboolean alloc_console_called = FALSE; + HANDLE handle; + + if (win32_keep_fatal_message) + return; + + if (!alloc_console_called) + { + handle = GetStdHandle (STD_ERROR_HANDLE); + + if (handle == INVALID_HANDLE_VALUE) + { + AllocConsole (); + alloc_console_called = TRUE; + freopen ("CONOUT$", "w", stderr); + } + } +} + #else #define ensure_stdout_valid() /* Define as empty */ +#define ensure_stderr_valid() #endif static void @@ -470,7 +494,9 @@ g_logv (const gchar *log_domain, if (test_level & G_LOG_FLAG_FATAL) { #ifdef G_OS_WIN32 - MessageBox (NULL, fatal_msg_buf, NULL, MB_OK); + gchar *locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL); + + MessageBox (NULL, locale_msg, NULL, MB_OK); #endif #if defined (G_ENABLE_DEBUG) && (defined (SIGTRAP) || defined (G_OS_WIN32)) if (!(test_level & G_LOG_FLAG_RECURSION)) @@ -522,6 +548,7 @@ strdup_convert (const gchar *string, if (!warned) { warned = TRUE; + ensure_stderr_valid (); _g_fprintf (stderr, "GLib: Cannot convert message: %s\n", err->message); } g_error_free (err); @@ -654,11 +681,19 @@ mklevel_prefix (gchar level_prefix[STRING_BUFFER_SIZE], if (log_level & ALERT_LEVELS) strcat (level_prefix, " **"); - ensure_stdout_valid (); #ifdef G_OS_WIN32 win32_keep_fatal_message = (log_level & G_LOG_FLAG_FATAL) != 0; - /* Use just stdout as stderr is hard to get redirected from the DOS prompt. */ - return stdout; + + if (to_stdout) + { + ensure_stdout_valid (); + return stdout; + } + else + { + ensure_stderr_valid (); + return stderr; + } #else return to_stdout ? 1 : 2; #endif @@ -869,6 +904,7 @@ g_printerr (const gchar *format, { const gchar *charset; + ensure_stderr_valid (); if (g_get_charset (&charset)) fputs (string, stderr); /* charset is UTF-8 already */ else