After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 704000 - Gtk2 -init brokes perl internal locale handling
Gtk2 -init brokes perl internal locale handling
Status: RESOLVED NOTABUG
Product: gnome-perl
Classification: Bindings
Component: Gtk2
unspecified
Other Linux
: Normal major
: ---
Assigned To: gtk2-perl-bugs
gtk2-perl-bugs
Depends on:
Blocks:
 
 
Reported: 2013-07-11 12:53 UTC by Gergely Dömsödi
Modified: 2013-07-11 16:39 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Gergely Dömsödi 2013-07-11 12:53:05 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.
Comment 1 Torsten Schoenfeld 2013-07-11 16:39:39 UTC
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.