+2004-12-07 Matthias Clasen <mclasen@redhat.com>
+
+ * glib/gutils.c (g_get_language_names): Update the returned
+ value after locale changes. (#160271, Christian Persch)
+ (_g_utils_thread_init): Initialize the language name cache
+ before going threaded.
+
+ * glib/gthread.c (g_thread_init_glib): Call _g_utils_thread_init().
+
+ * glib/gthreadinit.h: Add _g_utils_thread_init().
+
2004-12-06 Tor Lillqvist <tml@iki.fi>
* glib/giowin32.c (g_io_win32_finalize): Fix a write to freed
+2004-12-07 Matthias Clasen <mclasen@redhat.com>
+
+ * glib/gutils.c (g_get_language_names): Update the returned
+ value after locale changes. (#160271, Christian Persch)
+ (_g_utils_thread_init): Initialize the language name cache
+ before going threaded.
+
+ * glib/gthread.c (g_thread_init_glib): Call _g_utils_thread_init().
+
+ * glib/gthreadinit.h: Add _g_utils_thread_init().
+
2004-12-06 Tor Lillqvist <tml@iki.fi>
* glib/giowin32.c (g_io_win32_finalize): Fix a write to freed
+2004-12-07 Matthias Clasen <mclasen@redhat.com>
+
+ * glib/gutils.c (g_get_language_names): Update the returned
+ value after locale changes. (#160271, Christian Persch)
+ (_g_utils_thread_init): Initialize the language name cache
+ before going threaded.
+
+ * glib/gthread.c (g_thread_init_glib): Call _g_utils_thread_init().
+
+ * glib/gthreadinit.h: Add _g_utils_thread_init().
+
2004-12-06 Tor Lillqvist <tml@iki.fi>
* glib/giowin32.c (g_io_win32_finalize): Fix a write to freed
+2004-12-07 Matthias Clasen <mclasen@redhat.com>
+
+ * glib/gutils.c (g_get_language_names): Update the returned
+ value after locale changes. (#160271, Christian Persch)
+ (_g_utils_thread_init): Initialize the language name cache
+ before going threaded.
+
+ * glib/gthread.c (g_thread_init_glib): Call _g_utils_thread_init().
+
+ * glib/gthreadinit.h: Add _g_utils_thread_init().
+
2004-12-06 Tor Lillqvist <tml@iki.fi>
* glib/giowin32.c (g_io_win32_finalize): Fix a write to freed
+2004-12-07 Matthias Clasen <mclasen@redhat.com>
+
+ * glib/gutils.c (g_get_language_names): Update the returned
+ value after locale changes. (#160271, Christian Persch)
+ (_g_utils_thread_init): Initialize the language name cache
+ before going threaded.
+
+ * glib/gthread.c (g_thread_init_glib): Call _g_utils_thread_init().
+
+ * glib/gthreadinit.h: Add _g_utils_thread_init().
+
2004-12-06 Tor Lillqvist <tml@iki.fi>
* glib/giowin32.c (g_io_win32_finalize): Fix a write to freed
_g_mem_thread_init ();
_g_messages_thread_init ();
_g_atomic_thread_init ();
+ _g_utils_thread_init ();
#ifdef G_OS_WIN32
_g_win32_thread_init ();
#endif
void _g_rand_thread_init (void) G_GNUC_INTERNAL;
void _g_main_thread_init (void) G_GNUC_INTERNAL;
void _g_atomic_thread_init (void) G_GNUC_INTERNAL;
+void _g_utils_thread_init (void) G_GNUC_INTERNAL;
#ifdef G_OS_WIN32
void _g_win32_thread_init (void) G_GNUC_INTERNAL;
#endif
#include "galias.h"
#include "glib.h"
#include "gprintfint.h"
+#include "gthreadinit.h"
#ifdef MAXPATHLEN
#define G_PATH_LENGTH MAXPATHLEN
return NULL;
}
-static gchar **languages = NULL;
+typedef struct _GLanguageNamesCache GLanguageNamesCache;
+
+struct _GLanguageNamesCache {
+ gchar *languages;
+ gchar **language_names;
+};
+
+static void
+language_names_cache_free (gpointer data)
+{
+ GLanguageNamesCache *cache = data;
+ g_free (cache->languages);
+ g_strfreev (cache->language_names);
+ g_free (cache);
+}
/**
* g_get_language_names:
G_CONST_RETURN gchar * G_CONST_RETURN *
g_get_language_names (void)
{
- G_LOCK (g_utils_global);
+ static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT;
+ GLanguageNamesCache *cache = g_static_private_get (&cache_private);
+ const gchar *value;
+
+ if (!cache)
+ {
+ cache = g_new0 (GLanguageNamesCache, 1);
+ g_static_private_set (&cache_private, cache, language_names_cache_free);
+ }
+
+ value = guess_category_value ("LC_MESSAGES");
+ if (!value)
+ value = "C";
- if (!languages)
+ if (!(cache->languages && strcmp (cache->languages, value) == 0))
{
- const gchar *value;
+ gchar **languages;
gchar **alist, **a;
GSList *list, *l;
gint i;
- value = guess_category_value ("LC_MESSAGES");
- if (!value)
- value = "C";
+ g_free (cache->languages);
+ g_strfreev (cache->language_names);
+ cache->languages = g_strdup (value);
alist = g_strsplit (value, ":", 0);
list = NULL;
list = g_slist_concat (list, _g_compute_locale_variants (b));
}
g_strfreev (alist);
- list = g_slist_append (list, "C");
+ list = g_slist_append (list, g_strdup ("C"));
- languages = g_new (gchar *, g_slist_length (list) + 1);
+ cache->language_names = languages = g_new (gchar *, g_slist_length (list) + 1);
for (l = list, i = 0; l; l = l->next, i++)
languages[i] = l->data;
languages[i] = NULL;
g_slist_free (list);
}
- G_UNLOCK (g_utils_global);
-
- return (G_CONST_RETURN gchar * G_CONST_RETURN *) languages;
+ return (G_CONST_RETURN gchar * G_CONST_RETURN *) cache->language_names;
}
guint
return g_strdup (charset);
}
+/* This is called from g_thread_init(). It's used to
+ * initialize some static data in a threadsafe way.
+ */
+void
+_g_utils_thread_init (void)
+{
+ g_get_language_names ();
+}
+
#ifdef ENABLE_NLS
#include <libintl.h>