Bug 822004 - Call setlocale from nsNativeCharsetConverter::LazyInit if it is called before xpcom initialization. r=bsmedberg
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 21 Dec 2012 17:33:30 +0100
changeset 125763 f2e4c3f694dd045dc94917684129a2809fff9a2e
parent 125762 cf15d495a7fd2f3ee0111cfd47cb7fee7f41d902
child 125764 0a8702aae0a71409975c27569e7187483d781531
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs822004
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 822004 - Call setlocale from nsNativeCharsetConverter::LazyInit if it is called before xpcom initialization. r=bsmedberg
xpcom/io/nsNativeCharsetUtils.cpp
--- a/xpcom/io/nsNativeCharsetUtils.cpp
+++ b/xpcom/io/nsNativeCharsetUtils.cpp
@@ -291,16 +291,22 @@ iconv_t nsNativeCharsetConverter::gUTF8T
 #endif
 Mutex  *nsNativeCharsetConverter::gLock            = nullptr;
 bool    nsNativeCharsetConverter::gInitialized     = false;
 bool    nsNativeCharsetConverter::gIsNativeUTF8    = false;
 
 void
 nsNativeCharsetConverter::LazyInit()
 {
+    // LazyInit may be called before NS_StartupNativeCharsetUtils, but
+    // the setlocale it does has to be called before nl_langinfo. Like in
+    // NS_StartupNativeCharsetUtils, assume we are called early enough that
+    // we are the first to care about the locale's charset.
+    if (!gLock)
+      setlocale(LC_CTYPE, "");
     const char  *blank_list[] = { "", NULL };
     const char **native_charset_list = blank_list;
     const char  *native_charset = nl_langinfo(CODESET);
     if (native_charset == nullptr) {
         NS_ERROR("native charset is unknown");
         // fallback to ISO-8859-1
         native_charset_list = ISO_8859_1_NAMES;
     }