msvcrt: Improved locale initialization.

This commit is contained in:
Piotr Caban 2011-05-26 11:40:04 +02:00 committed by Alexandre Julliard
parent 3b4cc4464d
commit 27ff2ae967
4 changed files with 34 additions and 9 deletions

View File

@ -43,8 +43,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
MSVCRT__locale_t MSVCRT_locale = NULL; MSVCRT__locale_t MSVCRT_locale = NULL;
int MSVCRT___lc_codepage = 0; int MSVCRT___lc_codepage = 0;
int MSVCRT___lc_collate_cp = 0; int MSVCRT___lc_collate_cp = 0;
HANDLE MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 }; LCID MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
unsigned char charmax = CHAR_MAX; static unsigned char charmax = CHAR_MAX;
/* MT */ /* MT */
#define LOCK_LOCALE _mlock(_SETLOCALE_LOCK); #define LOCK_LOCALE _mlock(_SETLOCALE_LOCK);
@ -572,7 +572,7 @@ int CDECL __lconv_init(void)
/********************************************************************* /*********************************************************************
* ___lc_handle_func (MSVCRT.@) * ___lc_handle_func (MSVCRT.@)
*/ */
HANDLE * CDECL ___lc_handle_func(void) LCID* CDECL ___lc_handle_func(void)
{ {
return MSVCRT___lc_handle; return MSVCRT___lc_handle;
} }
@ -1234,10 +1234,14 @@ char* CDECL MSVCRT_setlocale(int category, const char* locale)
UNLOCK_LOCALE; UNLOCK_LOCALE;
if(locinfo == MSVCRT_locale->locinfo) { if(locinfo == MSVCRT_locale->locinfo) {
int i;
MSVCRT___lc_codepage = locinfo->lc_codepage; MSVCRT___lc_codepage = locinfo->lc_codepage;
MSVCRT___lc_collate_cp = locinfo->lc_collate_cp; MSVCRT___lc_collate_cp = locinfo->lc_collate_cp;
MSVCRT___mb_cur_max = locinfo->mb_cur_max; MSVCRT___mb_cur_max = locinfo->mb_cur_max;
MSVCRT__pctype = locinfo->pctype; 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) if(category == MSVCRT_LC_ALL)
@ -1291,3 +1295,22 @@ int CDECL _configthreadlocale(int type)
return -1; 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;
}

View File

@ -74,8 +74,10 @@ static inline void msvcrt_free_tls_mem(void)
HeapFree(GetProcessHeap(),0,tls->strerror_buffer); HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
HeapFree(GetProcessHeap(),0,tls->wcserror_buffer); HeapFree(GetProcessHeap(),0,tls->wcserror_buffer);
HeapFree(GetProcessHeap(),0,tls->time_buffer); HeapFree(GetProcessHeap(),0,tls->time_buffer);
free_locinfo(tls->locinfo); if(tls->have_locale) {
free_mbcinfo(tls->mbcinfo); free_locinfo(tls->locinfo);
free_mbcinfo(tls->mbcinfo);
}
} }
HeapFree(GetProcessHeap(), 0, tls); HeapFree(GetProcessHeap(), 0, tls);
} }
@ -96,7 +98,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
if (!msvcrt_init_tls()) if (!msvcrt_init_tls())
return FALSE; return FALSE;
msvcrt_init_mt_locks(); msvcrt_init_mt_locks();
if(!(MSVCRT_locale = MSVCRT__create_locale(0, "C"))) { if(!msvcrt_init_locale()) {
msvcrt_free_mt_locks(); msvcrt_free_mt_locks();
msvcrt_free_tls_mem(); msvcrt_free_tls_mem();
return FALSE; return FALSE;

View File

@ -112,7 +112,7 @@ typedef struct MSVCRT_threadlocaleinfostruct {
int refcount; int refcount;
unsigned int lc_codepage; unsigned int lc_codepage;
unsigned int lc_collate_cp; unsigned int lc_collate_cp;
unsigned long lc_handle[6]; MSVCRT_ulong lc_handle[6];
MSVCRT_LC_ID lc_id[6]; MSVCRT_LC_ID lc_id[6];
struct { struct {
char *locale; 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_init_mt_locks(void);
extern void msvcrt_free_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_math(void);
extern void msvcrt_init_io(void); extern void msvcrt_init_io(void);
extern void msvcrt_free_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 #define MSVCRT__DISABLE_PER_THREAD_LOCALE 2
extern MSVCRT__locale_t MSVCRT_locale; extern MSVCRT__locale_t MSVCRT_locale;
MSVCRT__locale_t MSVCRT__create_locale(int, const char*);
MSVCRT_pthreadlocinfo get_locinfo(void); MSVCRT_pthreadlocinfo get_locinfo(void);
void __cdecl MSVCRT__free_locale(MSVCRT__locale_t); void __cdecl MSVCRT__free_locale(MSVCRT__locale_t);
void free_locinfo(MSVCRT_pthreadlocinfo); void free_locinfo(MSVCRT_pthreadlocinfo);

View File

@ -212,7 +212,7 @@ typedef struct threadlocaleinfostruct {
int refcount; int refcount;
unsigned int lc_codepage; unsigned int lc_codepage;
unsigned int lc_collate_cp; unsigned int lc_collate_cp;
unsigned long lc_handle[6]; __msvcrt_ulong lc_handle[6];
LC_ID lc_id[6]; LC_ID lc_id[6];
struct { struct {
char *locale; char *locale;