GNOME Bugzilla – Bug 704000
Gtk2 -init brokes perl internal locale handling
Last modified: 2013-07-11 16:39:39 UTC
Preamble: Hungarian locale uses a comma instead of a decimal point in fractional numbers. The two oneliner examples below show the bug: doome@freedom:~$ LC_ALL=hu_HU.utf8 perl -e 'print 3.123."\n";' 3.123 doome@freedom:~$ LC_ALL=hu_HU.utf8 perl -e 'use Gtk2 -init; print 3.123."\n";' 3,123 Somehow using Gtk2 -init; mangles (localizes) how Perl fetches a number from the memory, thus all modules trying to access a number got it converted to the locale, even if it shouldn't have. Using pack shows the problem, too, so hopefully it is not in printing or some weird IO Layer of Perl: doome@freedom:~$ LC_ALL=hu_HU.utf8 perl -e 'use Gtk2 -init; print unpack("H*", 3.123)."\n";' 332c313233 doome@freedom:~$ LC_ALL=hu_HU.utf8 perl -e 'print unpack("H*", 3.123)."\n";' 332e313233 This shows the problem lies somewhere deep, because even pack show difference: 2c (an ASCII comma) with Gtk2 -init, and 2e (an ASCII period) without it, so internal stringifying goes wrong.. Tried it on a system with perl-gtk2 1.247, Gtk 2.24 and Perl 5.16, and another one with perl-gtk2 1.220, Gtk2 2.18.9, Perl 5.10.1, both were affected.
This happens because "use Gtk2 -init" calls Gtk2->init which calls the C function gtk_init which ends up calling setlocale(). This sets up the environment for locale-specific formatting, among other things. And apparently, the hu_HU locale defines the decimal separator to be a comma. The perl interpreter avoids calling setlocale() by default (unless "use locale" is used), which explains the different formatting when "use Gtk2 -init" is not used. You can call Gtk2->disable_setlocale before Gtk2->init if you do not want setlocale() to be called. But notice that if you want to continue to use the "use Gtk2 -init" shortcut, the Gtk2->disable_setlocale call needs to be in a BEGIN block. So, I don't think this is a bug.