Piotr Caban : msvcrt: Improved locale initialization.

Alexandre Julliard julliard at winehq.org
Thu May 26 10:56:27 CDT 2011


Module: wine
Branch: master
Commit: 27ff2ae967ff571e87c52fde9e9e4b9da4260b06
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=27ff2ae967ff571e87c52fde9e9e4b9da4260b06

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Thu May 26 11:40:04 2011 +0200

msvcrt: Improved locale initialization.

---

 dlls/msvcrt/locale.c     |   29 ++++++++++++++++++++++++++---
 dlls/msvcrt/main.c       |    8 +++++---
 dlls/msvcrt/msvcrt.h     |    4 ++--
 include/msvcrt/crtdefs.h |    2 +-
 4 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index 2551123..587d4fb 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -43,8 +43,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 MSVCRT__locale_t MSVCRT_locale = NULL;
 int MSVCRT___lc_codepage = 0;
 int MSVCRT___lc_collate_cp = 0;
-HANDLE MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
-unsigned char charmax = CHAR_MAX;
+LCID MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
+static unsigned char charmax = CHAR_MAX;
 
 /* MT */
 #define LOCK_LOCALE   _mlock(_SETLOCALE_LOCK);
@@ -572,7 +572,7 @@ int CDECL __lconv_init(void)
 /*********************************************************************
  *      ___lc_handle_func (MSVCRT.@)
  */
-HANDLE * CDECL ___lc_handle_func(void)
+LCID* CDECL ___lc_handle_func(void)
 {
     return MSVCRT___lc_handle;
 }
@@ -1234,10 +1234,14 @@ char* CDECL MSVCRT_setlocale(int category, const char* locale)
     UNLOCK_LOCALE;
 
     if(locinfo == MSVCRT_locale->locinfo) {
+        int i;
+
         MSVCRT___lc_codepage = locinfo->lc_codepage;
         MSVCRT___lc_collate_cp = locinfo->lc_collate_cp;
         MSVCRT___mb_cur_max = locinfo->mb_cur_max;
         MSVCRT__pctype = locinfo->pctype;
+        for(i=MSVCRT_LC_MIN; i<=MSVCRT_LC_MAX; i++)
+            MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
     }
 
     if(category == MSVCRT_LC_ALL)
@@ -1291,3 +1295,22 @@ int CDECL _configthreadlocale(int type)
 
     return -1;
 }
+
+BOOL msvcrt_init_locale(void)
+{
+    int i;
+
+    LOCK_LOCALE;
+    MSVCRT_locale = MSVCRT__create_locale(0, "C");
+    UNLOCK_LOCALE;
+    if(!MSVCRT_locale)
+        return FALSE;
+
+    MSVCRT___lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
+    MSVCRT___lc_collate_cp = MSVCRT_locale->locinfo->lc_collate_cp;
+    MSVCRT___mb_cur_max = MSVCRT_locale->locinfo->mb_cur_max;
+    MSVCRT__pctype = MSVCRT_locale->locinfo->pctype;
+    for(i=MSVCRT_LC_MIN; i<=MSVCRT_LC_MAX; i++)
+        MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
+    return TRUE;
+}
diff --git a/dlls/msvcrt/main.c b/dlls/msvcrt/main.c
index 902fb64..5d6e37a 100644
--- a/dlls/msvcrt/main.c
+++ b/dlls/msvcrt/main.c
@@ -74,8 +74,10 @@ static inline void msvcrt_free_tls_mem(void)
     HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
     HeapFree(GetProcessHeap(),0,tls->wcserror_buffer);
     HeapFree(GetProcessHeap(),0,tls->time_buffer);
-    free_locinfo(tls->locinfo);
-    free_mbcinfo(tls->mbcinfo);
+    if(tls->have_locale) {
+        free_locinfo(tls->locinfo);
+        free_mbcinfo(tls->mbcinfo);
+    }
   }
   HeapFree(GetProcessHeap(), 0, tls);
 }
@@ -96,7 +98,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
     if (!msvcrt_init_tls())
       return FALSE;
     msvcrt_init_mt_locks();
-    if(!(MSVCRT_locale = MSVCRT__create_locale(0, "C"))) {
+    if(!msvcrt_init_locale()) {
         msvcrt_free_mt_locks();
         msvcrt_free_tls_mem();
         return FALSE;
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 48d200b..7388091 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -112,7 +112,7 @@ typedef struct MSVCRT_threadlocaleinfostruct {
     int refcount;
     unsigned int lc_codepage;
     unsigned int lc_collate_cp;
-    unsigned long lc_handle[6];
+    MSVCRT_ulong lc_handle[6];
     MSVCRT_LC_ID lc_id[6];
     struct {
         char *locale;
@@ -234,6 +234,7 @@ extern char* __cdecl __unDNameEx(char *,const char*,int,malloc_func_t,free_func_
 extern void msvcrt_init_mt_locks(void);
 extern void msvcrt_free_mt_locks(void);
 
+extern BOOL msvcrt_init_locale(void);
 extern void msvcrt_init_math(void);
 extern void msvcrt_init_io(void);
 extern void msvcrt_free_io(void);
@@ -881,7 +882,6 @@ int            __cdecl MSVCRT_raise(int sig);
 #define MSVCRT__DISABLE_PER_THREAD_LOCALE 2
 
 extern MSVCRT__locale_t MSVCRT_locale;
-MSVCRT__locale_t MSVCRT__create_locale(int, const char*);
 MSVCRT_pthreadlocinfo get_locinfo(void);
 void __cdecl MSVCRT__free_locale(MSVCRT__locale_t);
 void free_locinfo(MSVCRT_pthreadlocinfo);
diff --git a/include/msvcrt/crtdefs.h b/include/msvcrt/crtdefs.h
index 9685a99..bc017c4 100644
--- a/include/msvcrt/crtdefs.h
+++ b/include/msvcrt/crtdefs.h
@@ -212,7 +212,7 @@ typedef struct threadlocaleinfostruct {
     int refcount;
     unsigned int lc_codepage;
     unsigned int lc_collate_cp;
-    unsigned long lc_handle[6];
+    __msvcrt_ulong lc_handle[6];
     LC_ID lc_id[6];
     struct {
         char *locale;




More information about the wine-cvs mailing list