Hi, the attached patch is currently being considered for application to gtkmm, both stable and unstable. Since it changes user-visible behavior, it is possible that it may break some odd piece of code out there.
If it breaks your code, raise your veto now. :-) The change is to initialize the global C++ locale in the constructor of Gtk::Main. The current situation is that the global C library locale is initialized by gtk_init() to the user locale from the environment. This results in an inconsistency because the global C++ locale is independent from the the global C library locale. The proposed patch makes Gtk::Main initialize the C++ locale as well, to complement the setting of the global C library locale by GTK+. This is particularly important for functions which make implicit use of the global C++ locale such as Glib::ustring::format(). Of course, this change could potentially break code which relies on the global C++ locale being set to the classic POSIX locale. So if you are concerned about that scenario, step up now. Cheers, --Daniel
>From fb375352f7b0cc0dc94b3dcaee4a0f7e8e4d56bf Mon Sep 17 00:00:00 2001 From: Daniel Elstner <[email protected]> Date: Tue, 30 Mar 2010 18:39:27 +0200 Subject: [PATCH] Initialize the global C++ locale in Gtk::Main * gtk/src/main.ccg (init_locale): New internal function to set the global C++ locale to the locale configured in the user environment. (Gtk::Main::init): Call init_locale() if the set_locale argument is true. (Gtk::Main::Main): Always call init_locale() in the constructor overload which accepts a Glib::OptionContext, since it a use_locale parameter is not supported by this variant. --- ChangeLog | 12 ++++++++++++ gtk/src/main.ccg | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e6c240..a3a0415 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-03-30 Daniel Elstner <[email protected]> + + Initialize the global C++ locale in Gtk::Main + + * gtk/src/main.ccg (init_locale): New internal function to set the + global C++ locale to the locale configured in the user environment. + (Gtk::Main::init): Call init_locale() if the set_locale argument is + true. + (Gtk::Main::Main): Always call init_locale() in the constructor + overload which accepts a Glib::OptionContext, since it a use_locale + parameter is not supported by this variant. + 2.20.0: 2010-03-23 Murray Cumming <[email protected]> diff --git a/gtk/src/main.ccg b/gtk/src/main.ccg index bcbd143..f658cf0 100644 --- a/gtk/src/main.ccg +++ b/gtk/src/main.ccg @@ -32,6 +32,10 @@ #endif //GTKMM_ATKMM_ENABLED #include <gdkmm/wrap_init.h> #include <gtkmm/wrap_init.h> +#include <locale> +#ifdef GLIBMM_EXCEPTIONS_ENABLED +# include <stdexcept> +#endif namespace { @@ -200,6 +204,27 @@ void GtkMainConnectionNode::list_notify_all() } } +/* Initialize the global C++ locale to the environment setting. Called from + * the Gtk::Main constructor to set the C++ locale to the environment locale, + * in order to mirror the C locale initialization done by gtk_init() if not + * explicitly disabled. + */ +static void init_locale() +{ +#ifdef GLIBMM_EXCEPTIONS_ENABLED + try // do not abort if the user-specified locale does not exist +#endif + { + std::locale::global(std::locale("")); + } +#ifdef GLIBMM_EXCEPTIONS_ENABLED + catch (const std::runtime_error& error) + { + g_warning("%s", error.what()); + } +#endif +} + } // anonymous namespace @@ -389,7 +414,9 @@ void Main::init(int* argc, char*** argv, bool set_locale) } else { - if(!set_locale) + if (set_locale) + init_locale(); + else gtk_disable_setlocale(); //TODO: Add support for gtk_init_check(). @@ -408,10 +435,15 @@ Main::Main(int& argc, char**& argv, Glib::OptionContext& option_context) } else { + // This constructor lacks a boolean set_locale parameter, thus initialize + // the global locale unconditionally. If absolutely necessary, it could + // always be undone later after the constructor has run. + init_locale(); + init_gtkmm_internals(); instance_ = this; - //This reimplements some stuff from gtk_init_with_options(), + //This reimplements some stuff from gtk_init_with_args(), //without calling check_setugid(), because that is not public API. add_gtk_option_group(option_context); -- 1.6.3.3
_______________________________________________ gtkmm-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/gtkmm-list
