[perl-Gtk3] Fix compatibility with perl 5.20 and non-dot locales



commit 6229db7a78da0b35c24ce1395e31a2d887a97e05
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Wed Jun 25 22:00:23 2014 +0200

    Fix compatibility with perl 5.20 and non-dot locales
    
    In locales with something else than a dot as the decimal separator, the
    combination of perl >= 5.20 and Gtk2 lead to errors wherever perl tried to
    parse version numbers, as in "use 5.8.0" or "use Encode 0.5".  Fix by making
    sure we notify perl when the locale might have changed behind its back.

 NEWS        |    2 ++
 lib/Gtk3.pm |   43 +++++++++++++++++++++++++++++++++++++++++++
 t/00-init.t |    8 ++++++--
 3 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 4d55f96..a0c3e64 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
 {{$NEXT}}
 
+* Fix compatibility with perl 5.20 and non-dot locales.
+
 Overview of changes in Gtk3 0.016 [2014-02-19]
 ==============================================
 
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index 065957b..e182903 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -1471,6 +1471,49 @@ sub Pango::Layout::set_text {
     @_ == 3 ? @_ : (@_[0,1], -1)); # wants length in bytes
 }
 
+# - Fixes ------------------------------------------------------------------- #
+
+# Compatibility with perl 5.20 and non-dot locales.  Wrap all functions that
+# might end up calling setlocale() such that POSIX::setlocale() is also called
+# to ensure perl knows about the current locale.  See the discussion in
+# <https://rt.perl.org/Public/Bug/Display.html?id=121930>,
+# <https://rt.perl.org/Public/Bug/Display.html?id=121317>,
+# <https://rt.perl.org/Public/Bug/Display.html?id=120723>.
+if ($^V ge v5.20.0) {
+  require POSIX;
+  no strict 'refs';
+  no warnings 'redefine';
+
+  my $disable_setlocale = 0;
+  my $orig = \&Gtk3::disable_setlocale;
+  *{Gtk3::disable_setlocale} = sub {
+    $disable_setlocale = 1;
+    $orig->(@_);
+  };
+
+  # These two already have overrides.
+  foreach my $function (qw/Gtk3::init Gtk3::init_check/) {
+    my $orig = \&{$function};
+    *{$function} = sub {
+      if (!$disable_setlocale) {
+        POSIX::setlocale (POSIX::LC_ALL (), '');
+      }
+      $orig->(@_);
+    };
+  }
+
+  # These do not.
+  foreach my $function (qw/init_with_args parse_args/) {
+    *{'Gtk3::' . $function} = sub {
+      if (!$disable_setlocale) {
+        POSIX::setlocale (POSIX::LC_ALL (), '');
+      }
+      Glib::Object::Introspection->invoke (
+        $_GTK_BASENAME, undef, $function, @_);
+    };
+  }
+}
+
 # - Helpers ----------------------------------------------------------------- #
 
 sub _common_tree_model_new {
diff --git a/t/00-init.t b/t/00-init.t
index e912c0f..2afd03b 100644
--- a/t/00-init.t
+++ b/t/00-init.t
@@ -10,12 +10,16 @@ my $success = eval { Gtk3->import; 1 };
 BAIL_OUT ("Cannot load Gtk3: $@")
   unless $success;
 
-plan tests => 1;
+plan tests => 2;
 
 SKIP: {
   @ARGV = qw(--help --name gtk2perl --urgs tree);
-  skip 'Gtk3::init_check failed, probably unable to open DISPLAY', 1
+  skip 'Gtk3::init_check failed, probably unable to open DISPLAY', 2
     unless Gtk3::init_check ();
   Gtk3::init ();
   is_deeply (\ ARGV, [qw(--help --urgs tree)]);
+
+  # Ensure that version parsing still works after the setlocale() done by
+  # Gtk3::init().
+  ok (defined eval 'use 5.8.0; 1');
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]