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 79529 - Calling glib functions prior to setlocale() sticks g_get_charset in ASCII
Calling glib functions prior to setlocale() sticks g_get_charset in ASCII
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.0.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 95810 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2002-04-22 18:39 UTC by Havoc Pennington
Modified: 2011-02-18 15:55 UTC
See Also:
GNOME target: ---
GNOME version: 2.0



Description Havoc Pennington 2002-04-22 18:39:50 UTC
If you call g_print for example before calling setlocale(), g_get_charset
will get stuck in ASCII and g_locale_to_utf8 etc. won't work.
Comment 1 Owen Taylor 2002-05-20 19:52:06 UTC
There are thread-safety problems if we consider locale something
that can change ... the standard C library makes no provision
for handling the result of setlocale() in a thread-safe fashion
if another thread makes a call to setlocale().

But, if we assume non-threadedness, then something like:

 const gchar *new_lc_ctype = setlocale (LC_CTYPE, NULL);
 if (cached_lc_ctype && strcmp (new_lc_ctype, cached_lc_ctype) == 0)
   {
     return cached result
   }
 else
   {
     g_free (cached_lc_ctype);
     cached_lc_ctype = setlocale (LC_CTYPE, NULL);

     [ get result and cache it ]
   }

Probably is right for UNIX ... we can probably assume
 that LC_CTYPE always exists and a change in 
nl_langinfo() is always a result in a change in the LC_CTYPE
category. We don't need to worry about thread locking
since the libc interfaces aren't thread safe anyways.

(Does the uselocale() stuff in glibc-2.3 help the threading
issue? Or does it not matter if the app is still using
setlocale?)
Comment 2 Owen Taylor 2002-10-15 13:34:05 UTC
*** Bug 95810 has been marked as a duplicate of this bug. ***
Comment 3 Owen Taylor 2002-12-15 01:36:15 UTC
Sat Dec 14 20:11:41 2002  Owen Taylor  <otaylor@redhat.com>

        * glib/libcharset/{localcharset.[ch] libcharset-glib.patch}
        glib/gutf8.c: Break _g_locale_charset() into two pieces
        - a fast "raw" piece, and a slow "unalias pieces".
        Always call the "raw" piece, and call the unalias bit
        if it changes. Use a per-thread cache. (#79529)