[gnome-desktop] Revert "gnome-languages: Use uselocale to avoid threadsafety issues"



commit b951e74f13e3987675ae73953c12ead041bc8f72
Author: Michael Catanzaro <mcatanzaro posteo net>
Date:   Thu Mar 7 03:30:55 2019 +0000

    Revert "gnome-languages: Use uselocale to avoid threadsafety issues"
    
    This reverts commit 1f33beb651a641d0715e3b7ae014bc1acf48b816

 libgnome-desktop/gnome-languages.c | 49 ++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 28 deletions(-)
---
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index e073571f..74959c55 100644
--- a/libgnome-desktop/gnome-languages.c
+++ b/libgnome-desktop/gnome-languages.c
@@ -286,15 +286,15 @@ gnome_normalize_locale (const char *locale)
 static gboolean
 language_name_is_valid (const char *language_name)
 {
-        locale_t locale;
+        gboolean  is_valid;
+        int lc_type_id = LC_MESSAGES;
+        g_autofree char *old_locale = NULL;
 
-        locale = newlocale (LC_MESSAGES_MASK, language_name, (locale_t) 0);
-        if (locale != (locale_t) 0) {
-                freelocale (locale);
-                return TRUE;
-        }
+        old_locale = g_strdup (setlocale (lc_type_id, NULL));
+        is_valid = setlocale (lc_type_id, language_name) != NULL;
+        setlocale (lc_type_id, old_locale);
 
-        return FALSE;
+        return is_valid;
 }
 
 static void
@@ -302,15 +302,13 @@ language_name_get_codeset_details (const char  *language_name,
                                    char       **pcodeset,
                                    gboolean    *is_utf8)
 {
-        locale_t locale;
-        locale_t old_locale;
+        g_autofree char *old_locale = NULL;
         const char *codeset = NULL;
 
-        locale = newlocale (LC_CTYPE_MASK, language_name, (locale_t) 0);
-        if (locale == (locale_t) 0)
-                return;
+        old_locale = g_strdup (setlocale (LC_CTYPE, NULL));
 
-        old_locale = uselocale (locale);
+        if (setlocale (LC_CTYPE, language_name) == NULL)
+                return;
 
         codeset = nl_langinfo (CODESET);
 
@@ -324,8 +322,7 @@ language_name_get_codeset_details (const char  *language_name,
                 *is_utf8 = strcmp (normalized_codeset, "UTF-8") == 0;
         }
 
-        uselocale (old_locale);
-        freelocale (locale);
+        setlocale (LC_CTYPE, old_locale);
 }
 
 /**
@@ -702,13 +699,12 @@ get_translated_language (const char *code,
 
         name = NULL;
         if (language != NULL) {
-                const char *translated_name;
-                locale_t loc;
-                locale_t old_locale;
+                const char  *translated_name;
+                g_autofree char *old_locale = NULL;
 
                 if (locale != NULL) {
-                        loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t) 0);
-                        old_locale = uselocale (loc);
+                        old_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
+                        setlocale (LC_MESSAGES, locale);
                 }
 
                 if (is_fallback_language (code)) {
@@ -721,8 +717,7 @@ get_translated_language (const char *code,
                 }
 
                 if (locale != NULL) {
-                        uselocale (old_locale);
-                        freelocale (loc);
+                        setlocale (LC_MESSAGES, old_locale);
                 }
         }
 
@@ -759,13 +754,12 @@ get_translated_territory (const char *code,
         name = NULL;
         if (territory != NULL) {
                 const char *translated_territory;
-                locale_t loc;
-                locale_t old_locale;
+                g_autofree char *old_locale = NULL;
                 g_autofree char *tmp = NULL;
 
                 if (locale != NULL) {
-                        loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t) 0);
-                        old_locale = uselocale (loc);
+                        old_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
+                        setlocale (LC_MESSAGES, locale);
                 }
 
                 translated_territory = dgettext ("iso_3166", territory);
@@ -773,8 +767,7 @@ get_translated_territory (const char *code,
                 name = capitalize_utf8_string (tmp);
 
                 if (locale != NULL) {
-                        uselocale (old_locale);
-                        freelocale (loc);
+                        setlocale (LC_MESSAGES, old_locale);
                 }
         }
 


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