From 398008dac54945e336484e7534a26aa42adda28a Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sun, 20 Mar 2005 10:52:38 +0000 Subject: [PATCH] glib/gmessages.c (g_log_default_handler) Move the Win32 code that asks the 2005-03-20 Tor Lillqvist * glib/gmessages.c (g_log_default_handler) * glib/gutils.c (g_get_prgname): Move the Win32 code that asks the program name from the system to g_get_prgname(). Do output the pid also on Win32 (useful in case there are several instances of the same program running). --- ChangeLog | 6 ++++++ ChangeLog.pre-2-10 | 6 ++++++ ChangeLog.pre-2-12 | 6 ++++++ ChangeLog.pre-2-8 | 6 ++++++ glib/gmessages.c | 43 ------------------------------------------- glib/gutils.c | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b2bb125d..3ffe87d1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2005-03-20 Tor Lillqvist + * glib/gmessages.c (g_log_default_handler) + * glib/gutils.c (g_get_prgname): Move the Win32 code that asks the + program name from the system to g_get_prgname(). Do output the pid + also on Win32 (useful in case there are several instances of the + same program running). + * tests/testglib.c (main): Print more detailled output from the timer tests. Don't print home directory twice. Test g_win32_error_message(). diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 1b2bb125d..3ffe87d1a 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,11 @@ 2005-03-20 Tor Lillqvist + * glib/gmessages.c (g_log_default_handler) + * glib/gutils.c (g_get_prgname): Move the Win32 code that asks the + program name from the system to g_get_prgname(). Do output the pid + also on Win32 (useful in case there are several instances of the + same program running). + * tests/testglib.c (main): Print more detailled output from the timer tests. Don't print home directory twice. Test g_win32_error_message(). diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 1b2bb125d..3ffe87d1a 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,11 @@ 2005-03-20 Tor Lillqvist + * glib/gmessages.c (g_log_default_handler) + * glib/gutils.c (g_get_prgname): Move the Win32 code that asks the + program name from the system to g_get_prgname(). Do output the pid + also on Win32 (useful in case there are several instances of the + same program running). + * tests/testglib.c (main): Print more detailled output from the timer tests. Don't print home directory twice. Test g_win32_error_message(). diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 1b2bb125d..3ffe87d1a 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,11 @@ 2005-03-20 Tor Lillqvist + * glib/gmessages.c (g_log_default_handler) + * glib/gutils.c (g_get_prgname): Move the Win32 code that asks the + program name from the system to g_get_prgname(). Do output the pid + also on Win32 (useful in case there are several instances of the + same program running). + * tests/testglib.c (main): Print more detailled output from the timer tests. Don't print home directory twice. Test g_win32_error_message(). diff --git a/glib/gmessages.c b/glib/gmessages.c index 42019e643..55582fbbf 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -883,53 +883,10 @@ g_log_default_handler (const gchar *log_domain, { const gchar *prg_name = g_get_prgname (); -#ifdef G_OS_WIN32 - if (prg_name) - prg_name = g_strdup (prg_name); - else - { - if (G_WIN32_HAVE_WIDECHAR_API ()) - { - wchar_t buf[MAX_PATH+1]; - if (GetModuleFileNameW (GetModuleHandle (NULL), - buf, G_N_ELEMENTS (buf)) > 0) - { - gchar *utf8_buf = g_utf16_to_utf8 (buf, -1, - NULL, NULL, NULL); - if (utf8_buf) - { - prg_name = g_path_get_basename (utf8_buf); - g_free (utf8_buf); - } - } - } - else - { - gchar buf[MAX_PATH+1]; - if (GetModuleFileNameA (GetModuleHandle (NULL), - buf, G_N_ELEMENTS (buf)) > 0) - { - gchar *locale_buf = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - if (locale_buf) - { - prg_name = g_path_get_basename (locale_buf); - g_free (locale_buf); - } - } - } - } - - if (prg_name) - { - g_string_append_printf (gstring, "(%s): ", prg_name); - g_free ((gchar *) prg_name); - } -#else if (!prg_name) g_string_append_printf (gstring, "(process:%lu): ", (gulong)getpid ()); else g_string_append_printf (gstring, "(%s:%lu): ", prg_name, (gulong)getpid ()); -#endif } if (log_domain) diff --git a/glib/gutils.c b/glib/gutils.c index 95cf20202..b07a95aee 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -1756,6 +1756,38 @@ g_get_prgname (void) gchar* retval; G_LOCK (g_prgname); +#ifdef G_OS_WIN32 + if (g_prgname == NULL) + { + static gboolean beenhere = FALSE; + + if (!beenhere) + { + gchar *utf8_buf = NULL; + + beenhere = TRUE; + if (G_WIN32_HAVE_WIDECHAR_API ()) + { + wchar_t buf[MAX_PATH+1]; + if (GetModuleFileNameW (GetModuleHandle (NULL), + buf, G_N_ELEMENTS (buf)) > 0) + utf8_buf = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL); + } + else + { + gchar buf[MAX_PATH+1]; + if (GetModuleFileNameA (GetModuleHandle (NULL), + buf, G_N_ELEMENTS (buf)) > 0) + utf8_buf = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); + } + if (utf8_buf) + { + g_prgname = g_path_get_basename (utf8_buf); + g_free (utf8_buf); + } + } + } +#endif retval = g_prgname; G_UNLOCK (g_prgname);