[gnome-desktop/alatiera/locale-revert: 3/3] Revert "Replace usage of non-portable `uselocale` with locale-dependent functions"




commit 96565763e950e9c281751c5fe35c9ba83cb61ac8
Author: Jordan Petridis <jordan centricular com>
Date:   Fri Apr 9 20:40:40 2021 +0300

    Revert "Replace usage of non-portable `uselocale` with locale-dependent functions"
    
    This reverts commit 4ea56a97a510cf2c587229231211552daa84d1fc.

 config.h.meson                            |  6 ---
 libgnome-desktop/gnome-gettext-portable.c | 72 -------------------------------
 libgnome-desktop/gnome-gettext-portable.h | 42 ------------------
 libgnome-desktop/gnome-languages.c        | 35 +++++++++------
 libgnome-desktop/gnome-wall-clock.c       |  9 +++-
 libgnome-desktop/meson.build              |  3 +-
 meson.build                               |  1 -
 tests/wall-clock.c                        | 52 ++++++++++++++++------
 tests/wallclock-reftest.c                 | 17 +++++---
 9 files changed, 82 insertions(+), 155 deletions(-)
---
diff --git a/config.h.meson b/config.h.meson
index 2c4778b0..75b0170d 100644
--- a/config.h.meson
+++ b/config.h.meson
@@ -27,9 +27,3 @@
 
 /* Define to include GNU extensions */
 #mesondefine _GNU_SOURCE
-
-/* define on systems that have the `uselocale` function */
-#mesondefine HAVE_USELOCALE
-
-/* define on system if OS has extended locale header */
-#mesondefine HAVE_XLOCALE
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index ef836f81..d38f9b89 100644
--- a/libgnome-desktop/gnome-languages.c
+++ b/libgnome-desktop/gnome-languages.c
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <errno.h>
 #include <dirent.h>
+#include <locale.h>
 #include <langinfo.h>
 #include <sys/stat.h>
 
@@ -35,8 +36,6 @@
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
-#include "gnome-gettext-portable.h"
-
 #define GNOME_DESKTOP_USE_UNSTABLE_API
 #include "gnome-languages.h"
 
@@ -304,14 +303,16 @@ language_name_get_codeset_details (const char  *language_name,
                                    gboolean    *is_utf8)
 {
         locale_t locale;
+        locale_t old_locale;
         const char *codeset = NULL;
 
         locale = newlocale (LC_CTYPE_MASK, language_name, (locale_t) 0);
         if (locale == (locale_t) 0)
                 return;
 
+        old_locale = uselocale (locale);
 
-        codeset = nl_langinfo_l (CODESET, locale);
+        codeset = nl_langinfo (CODESET);
 
         if (pcodeset != NULL) {
                 *pcodeset = g_strdup (codeset);
@@ -323,6 +324,7 @@ language_name_get_codeset_details (const char  *language_name,
                 *is_utf8 = strcmp (normalized_codeset, "UTF-8") == 0;
         }
 
+        uselocale (old_locale);
         freelocale (locale);
 }
 
@@ -702,23 +704,26 @@ get_translated_language (const char *code,
         if (language != NULL) {
                 const char *translated_name;
                 locale_t loc = 0;
+                locale_t old_locale = 0;
 
                 if (locale != NULL) {
                         loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t) 0);
                         if (loc == (locale_t) 0)
                                 return NULL;
+                        old_locale = uselocale (loc);
                 }
 
                 if (is_fallback_language (code)) {
                         name = g_strdup (_("Unspecified"));
                 } else {
                         g_autofree char *tmp = NULL;
-                        translated_name = dgettext_l (loc, "iso_639", language);
+                        translated_name = dgettext ("iso_639", language);
                         tmp = get_first_item_in_semicolon_list (translated_name);
                         name = capitalize_utf8_string (tmp);
                 }
 
                 if (locale != NULL) {
+                        uselocale (old_locale);
                         freelocale (loc);
                 }
         }
@@ -757,19 +762,22 @@ get_translated_territory (const char *code,
         if (territory != NULL) {
                 const char *translated_territory;
                 locale_t loc;
+                locale_t old_locale = 0;
                 g_autofree char *tmp = NULL;
 
                 if (locale != NULL) {
                         loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t) 0);
                         if (loc == (locale_t) 0)
                                 return NULL;
+                        old_locale = uselocale (loc);
                 }
 
-                translated_territory = dgettext_l (loc, "iso_3166", territory);
+                translated_territory = dgettext ("iso_3166", territory);
                 tmp = get_first_item_in_semicolon_list (translated_territory);
                 name = capitalize_utf8_string (tmp);
 
                 if (locale != NULL) {
+                        uselocale (old_locale);
                         freelocale (loc);
                 }
         }
@@ -1351,6 +1359,7 @@ gnome_get_translated_modifier (const char *modifier,
         char *retval;
         GHashTable *modifiers_map;
         locale_t loc;
+        locale_t old_locale;
 
         g_return_val_if_fail (modifier != NULL, NULL);
 
@@ -1359,6 +1368,7 @@ gnome_get_translated_modifier (const char *modifier,
                 if (loc == (locale_t) 0) {
                         return NULL;
                 }
+                old_locale = uselocale (loc);
         }
 
         /* Modifiers as listed in glibc's SUPPORTED file:
@@ -1369,26 +1379,26 @@ gnome_get_translated_modifier (const char *modifier,
         /* TRANSLATORS: Used to distinguish the labels representing the gez_ER
            and gez_ET locales from gez_ER@abegede respective gez_ET@abegede. The
            difference is related to collation. */
-        g_hash_table_insert (modifiers_map, "abegede", _l(loc, "Abegede"));
+        g_hash_table_insert (modifiers_map, "abegede", _("Abegede"));
         /* TRANSLATORS: Used to distinguish Cyrillic from Latin written language variants. */
-        g_hash_table_insert (modifiers_map, "cyrillic", _l(loc, "Cyrillic"));
+        g_hash_table_insert (modifiers_map, "cyrillic", _("Cyrillic"));
         /* TRANSLATORS: Also known as "Nagari", a written variant for many languages
            of the Indian subcontinent. See:
            https://en.wikipedia.org/wiki/Devanagari */
-        g_hash_table_insert (modifiers_map, "devanagari", _l(loc, "Devanagari"));
+        g_hash_table_insert (modifiers_map, "devanagari", _("Devanagari"));
         /* TRANSLATORS: Used to distinguish the label representing the tt_RU
            locale from tt_RU@iqtelif. It's a special alphabet for Tatar. */
-        g_hash_table_insert (modifiers_map, "iqtelif", _l(loc, "IQTElif"));
+        g_hash_table_insert (modifiers_map, "iqtelif", _("IQTElif"));
         /* TRANSLATORS: The alphabet/script, not the language. Used to distinguish
            Latin from Cyrillic written language variants. */
-        g_hash_table_insert (modifiers_map, "latin", _l(loc, "Latin"));
+        g_hash_table_insert (modifiers_map, "latin", _("Latin"));
         /* TRANSLATORS: "Saho" is a variant of the Afar language. Used to
            distinguish the label representing the aa_ER locale from aa_ER@saaho. */
-        g_hash_table_insert (modifiers_map, "saaho", _l(loc, "Saho"));
+        g_hash_table_insert (modifiers_map, "saaho", _("Saho"));
         /* TRANSLATORS: "Valencia" is a dialect of the Catalan language spoken
            in Valencia. Used to distinguish the label representing the ca_ES
            locale from ca_ES@valencia. */
-        g_hash_table_insert (modifiers_map, "valencia", _l(loc, "Valencia"));
+        g_hash_table_insert (modifiers_map, "valencia", _("Valencia"));
 
         if (g_hash_table_contains (modifiers_map, modifier))
                 retval = g_strdup (g_hash_table_lookup (modifiers_map, modifier));
@@ -1398,6 +1408,7 @@ gnome_get_translated_modifier (const char *modifier,
         g_hash_table_destroy (modifiers_map);
 
         if (translation != NULL) {
+                uselocale (old_locale);
                 freelocale (loc);
         }
 
diff --git a/libgnome-desktop/gnome-wall-clock.c b/libgnome-desktop/gnome-wall-clock.c
index b4d72b87..caede60d 100644
--- a/libgnome-desktop/gnome-wall-clock.c
+++ b/libgnome-desktop/gnome-wall-clock.c
@@ -24,8 +24,8 @@
 
 #include "config.h"
 
+#include <locale.h>
 #include <glib/gi18n-lib.h>
-#include "gnome-gettext-portable.h"
 
 #define GNOME_DESKTOP_USE_UNSTABLE_API
 #include "gnome-wall-clock.h"
@@ -289,13 +289,18 @@ translate_time_format_string (const char *str)
   const char *locale = g_getenv ("LC_TIME");
   const char *res;
   char *sep;
+  locale_t old_loc;
   locale_t loc = (locale_t)0;
 
   if (locale)
     loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t)0);
 
+  old_loc = uselocale (loc);
+
   sep = strchr (str, '\004');
-  res = g_dpgettext_l (loc, GETTEXT_PACKAGE, str, sep ? sep - str + 1 : 0);
+  res = g_dpgettext (GETTEXT_PACKAGE, str, sep ? sep - str + 1 : 0);
+
+  uselocale (old_loc);
 
   if (loc != (locale_t)0)
     freelocale (loc);
diff --git a/libgnome-desktop/meson.build b/libgnome-desktop/meson.build
index 8c3a2dfd..483f1ff6 100644
--- a/libgnome-desktop/meson.build
+++ b/libgnome-desktop/meson.build
@@ -48,8 +48,7 @@ libgnome_desktop_sources = [
   'default-input-sources.h',
   'meta-xrandr-shared.h',
   'gnome-desktop-thumbnail-script.c',
-  'gnome-desktop-thumbnail-script.h',
-  'gnome-gettext-portable.c'
+  'gnome-desktop-thumbnail-script.h'
 ]
 
 libgnome_desktop_headers = [
diff --git a/meson.build b/meson.build
index 490d43e6..3efd6773 100644
--- a/meson.build
+++ b/meson.build
@@ -94,7 +94,6 @@ conf.set('HAVE_XKBREGISTRY', xkbregistry_dep.found())
 
 conf.set('HAVE_TIMERFD', cc.has_function('timerfd_create'))
 conf.set('HAVE_OPENAT', cc.has_function('openat'))
-conf.set('HAVE_USELOCALE', cc.has_function('uselocale'))
 
 config_h = declare_dependency(
   sources: configure_file(
diff --git a/tests/wall-clock.c b/tests/wall-clock.c
index 0e8c49c9..486cfa38 100644
--- a/tests/wall-clock.c
+++ b/tests/wall-clock.c
@@ -36,7 +36,8 @@ test_utf8_character (const char *utf8_char,
 {
        GDateTime  *datetime;
        GnomeWallClock *clock;
-       const char *save_locale;
+       locale_t locale;
+       locale_t save_locale;
        const char *str;
 
        /* When testing that UTF8 locales don't use double spaces
@@ -46,7 +47,9 @@ test_utf8_character (const char *utf8_char,
 
        /* In the C locale, make sure the time string is formatted with regular
          * colons */
-       save_locale = setlocale (LC_ALL, NULL);
+       locale = newlocale (LC_ALL_MASK, "C", (locale_t) 0);
+       g_assert_true (locale != (locale_t)0);
+       save_locale = uselocale (locale);
        clock = gnome_wall_clock_new ();
        str = gnome_wall_clock_string_for_datetime (clock,
                                                    datetime,
@@ -57,7 +60,13 @@ test_utf8_character (const char *utf8_char,
        g_object_unref (clock);
 
        /* In a UTF8 locale, we want ratio characters and no colons. */
-       setlocale (LC_ALL, "en_US.utf8");
+       locale = newlocale (LC_ALL_MASK, "en_US.utf8", locale);
+       if (locale == (locale_t)0) {
+               g_test_message ("en_US.utf8 locale not found");
+               g_test_fail ();
+               return;
+       }
+       uselocale (locale);
        clock = gnome_wall_clock_new ();
        str = gnome_wall_clock_string_for_datetime (clock,
                                                    datetime,
@@ -69,7 +78,13 @@ test_utf8_character (const char *utf8_char,
 
        /* ... and same thing with an RTL locale: should be formatted with
          * ratio characters */
-       setlocale (LC_ALL, "he_IL.utf8");
+       locale = newlocale (LC_ALL_MASK, "he_IL.utf8", locale);
+       if (locale == (locale_t)0) {
+               g_test_message ("he_IL.utf8 locale not found");
+               g_test_fail ();
+               return;
+       }
+       uselocale (locale);
        clock = gnome_wall_clock_new ();
        str = gnome_wall_clock_string_for_datetime (clock,
                                                    datetime,
@@ -82,7 +97,8 @@ test_utf8_character (const char *utf8_char,
        g_date_time_unref (datetime);
 
        /* Restore previous locale */
-       setlocale (LC_ALL, save_locale);
+       uselocale (save_locale);
+       freelocale (locale);
 }
 
 static void
@@ -102,11 +118,17 @@ test_clock_format_setting (void)
 {
        GnomeWallClock *clock;
        GSettings *settings;
-       const char *save_locale;
+       locale_t locale;
+       locale_t save_locale;
        const char *str;
 
-       save_locale = setlocale (LC_ALL, NULL);
-       setlocale (LC_ALL, "en_US.utf8");
+       locale = newlocale (LC_ALL_MASK, "en_US.utf8", (locale_t) 0);
+       if (locale == (locale_t)0) {
+               g_test_message ("en_US.utf8 locale not found");
+               g_test_fail ();
+               return;
+       }
+       save_locale = uselocale (locale);
 
        settings = g_settings_new ("org.gnome.desktop.interface");
 
@@ -127,7 +149,8 @@ test_clock_format_setting (void)
        g_object_unref (settings);
 
        /* Restore previous locale */
-       setlocale (LC_ALL, save_locale);
+       uselocale (save_locale);
+       freelocale (locale);
 }
 
 static gboolean
@@ -179,12 +202,14 @@ test_weekday_setting (void)
 {
        GnomeWallClock *clock;
        GSettings *settings;
-       const char *save_locale;
+       locale_t locale;
+       locale_t save_locale;
        const char *str, *ptr, *s;
 
        /* Save current locale */
-       save_locale = setlocale (LC_ALL, NULL);
-       setlocale (LC_ALL, "C");
+       locale = newlocale (LC_ALL_MASK, "C", (locale_t) 0);
+       g_assert_true (locale != (locale_t)0);
+       save_locale = uselocale (locale);
        settings = g_settings_new ("org.gnome.desktop.interface");
 
        /* Set 24h format, so that the only alphabetical part will be the weekday */
@@ -220,7 +245,8 @@ test_weekday_setting (void)
        g_object_unref (settings);
 
        /* Restore previous locale */
-       setlocale (LC_ALL, save_locale);
+       uselocale (save_locale);
+       freelocale (locale);
 }
 
 int
diff --git a/tests/wallclock-reftest.c b/tests/wallclock-reftest.c
index e6026032..1238ea89 100644
--- a/tests/wallclock-reftest.c
+++ b/tests/wallclock-reftest.c
@@ -439,15 +439,21 @@ test_ui_file (GFile         *file,
   GnomeWallClock *clock;
   GDateTime *datetime;
   char *str;
-  const char *previous_locale;
+  locale_t loc, previous_locale;
 
   ui_file = g_file_get_path (file);
 
   locale = get_locale_for_file (ui_file);
   g_assert (locale);
-  previous_locale = setlocale (LC_ALL, NULL);
-  setlocale (LC_ALL, locale);
-  g_assert_true (previous_locale != NULL);
+  loc = newlocale (LC_ALL_MASK, locale, (locale_t) 0);
+  if (loc == (locale_t)0)
+    {
+      g_test_message ("locale '%s' not found", locale);
+      g_test_fail();
+      return;
+    }
+  previous_locale = uselocale (loc);
+  g_assert_true (previous_locale != (locale_t) 0);
 
   clock = gnome_wall_clock_new ();
   datetime = g_date_time_new_local (2014, 5, 28, 23, 59, 59);
@@ -459,7 +465,8 @@ test_ui_file (GFile         *file,
   g_date_time_unref (datetime);
   g_object_unref (clock);
 
-  setlocale (LC_ALL, previous_locale);
+  uselocale (previous_locale);
+  freelocale (loc);
 
   provider = add_extra_css (ui_file, ".css");
 


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