From d1fa8b64e42a646b7452fd0cc1a480531d0180c9 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Thu, 15 Apr 2010 14:26:47 +0200 Subject: [PATCH] msvcrt: Use per thread locale in many functions. --- dlls/msvcrt/ctype.c | 14 +++++---- dlls/msvcrt/file.c | 2 +- dlls/msvcrt/locale.c | 2 +- dlls/msvcrt/mbcs.c | 75 +++++++++++++++++++++++--------------------- 4 files changed, 49 insertions(+), 44 deletions(-) diff --git a/dlls/msvcrt/ctype.c b/dlls/msvcrt/ctype.c index 1e1257d274b..7baa5725269 100644 --- a/dlls/msvcrt/ctype.c +++ b/dlls/msvcrt/ctype.c @@ -62,7 +62,7 @@ WORD* MSVCRT__pctype; */ WORD** CDECL MSVCRT___pctype_func(void) { - return &MSVCRT__pctype; + return &get_locale()->locinfo->pctype; } /********************************************************************* @@ -70,21 +70,23 @@ WORD** CDECL MSVCRT___pctype_func(void) */ int CDECL _isctype(int c, int type) { - if (c >= -1 && c <= 255) - return MSVCRT__pctype[c] & type; + MSVCRT__locale_t locale = get_locale(); - if (MSVCRT___mb_cur_max != 1 && c > 0) + if (c >= -1 && c <= 255) + return locale->locinfo->pctype[c] & type; + + if (locale->locinfo->mb_cur_max != 1 && c > 0) { /* FIXME: Is there a faster way to do this? */ WORD typeInfo; char convert[3], *pconv = convert; - if (MSVCRT__pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE) + if (locale->locinfo->pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE) *pconv++ = (UINT)c >> 8; *pconv++ = c & 0xff; *pconv = 0; /* FIXME: Use ctype LCID, not lc_all */ - if (GetStringTypeExA(MSVCRT_locale->locinfo->lc_handle[MSVCRT_LC_CTYPE], + if (GetStringTypeExA(get_locale()->locinfo->lc_handle[MSVCRT_LC_CTYPE], CT_CTYPE1, convert, convert[1] ? 2 : 1, &typeInfo)) return typeInfo & type; } diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 7e3c217df17..c5b2798873f 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2467,7 +2467,7 @@ MSVCRT_wint_t CDECL MSVCRT_fgetwc(MSVCRT_FILE* file) } c = MSVCRT_fgetc(file); - if ((MSVCRT___mb_cur_max > 1) && MSVCRT_isleadbyte(c)) + if ((get_locale()->locinfo->mb_cur_max > 1) && MSVCRT_isleadbyte(c)) { FIXME("Treat Multibyte characters\n"); } diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index adef89c9850..55d2ca9ad1a 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -526,7 +526,7 @@ int CDECL ___lc_codepage_func(void) */ int CDECL ___lc_collate_cp_func(void) { - return MSVCRT___lc_collate_cp; + return get_locale()->locinfo->lc_collate_cp; } /* _free_locale - not exported in native msvcrt */ diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index 302b54e979b..cd52f6ce806 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -85,7 +85,7 @@ static MSVCRT_wchar_t msvcrt_mbc_to_wc(unsigned int ch) mbch[1] = ch & 0xff; n_chars = 2; } - if (!MultiByteToWideChar(MSVCRT___lc_codepage, 0, mbch, n_chars, &chW, 1)) + if (!MultiByteToWideChar(get_locale()->locinfo->lc_codepage, 0, mbch, n_chars, &chW, 1)) { WARN("MultiByteToWideChar failed on %x\n", ch); return 0; @@ -166,7 +166,7 @@ unsigned char* CDECL __p__mbctype(void) */ int* CDECL MSVCRT____mb_cur_max_func(void) { - return &MSVCRT___mb_cur_max; + return &get_locale()->locinfo->mb_cur_max; } /********************************************************************* @@ -174,6 +174,7 @@ int* CDECL MSVCRT____mb_cur_max_func(void) */ int CDECL _setmbcp(int cp) { + MSVCRT__locale_t locale = get_locale(); int newcp; CPINFO cpi; BYTE *bytes; @@ -194,7 +195,7 @@ int CDECL _setmbcp(int cp) newcp = GetOEMCP(); break; case _MB_CP_LOCALE: - newcp = MSVCRT___lc_codepage; + newcp = locale->locinfo->lc_codepage; break; case _MB_CP_SBCS: newcp = 20127; /* ASCII */ @@ -287,8 +288,9 @@ int CDECL _setmbcp(int cp) MSVCRT_mbctype[i + 1] |= _MS; } - MSVCRT___lc_collate_cp = MSVCRT___lc_codepage = newcp; - TRACE("(%d) -> %d\n", cp, MSVCRT___lc_codepage); + locale->locinfo->lc_collate_cp = newcp; + locale->locinfo->lc_codepage = newcp; + TRACE("(%d) -> %d\n", cp, locale->locinfo->lc_codepage); return 0; } @@ -297,7 +299,8 @@ int CDECL _setmbcp(int cp) */ int CDECL _getmbcp(void) { - return MSVCRT___lc_codepage; + /* FIXME: get_locale()->mbcinfo->mbcodepage should be used here */ + return get_locale()->locinfo->lc_codepage; } /********************************************************************* @@ -343,7 +346,7 @@ unsigned int CDECL _mbctombb(unsigned int c) { unsigned int value; - if(MSVCRT___lc_codepage == 932) + if(get_locale()->locinfo->lc_codepage == 932) { if(c >= 0x829f && c <= 0x82f1) /* Hiragana */ return mbctombb_932_kana[c - 0x829f]; @@ -375,7 +378,7 @@ unsigned int CDECL _mbcjistojms(unsigned int c) { /* Conversion takes place only when codepage is 932. In all other cases, c is returned unchanged */ - if(MSVCRT___lc_codepage == 932) + if(get_locale()->locinfo->lc_codepage == 932) { if(HIBYTE(c) >= 0x21 && HIBYTE(c) <= 0x7e && LOBYTE(c) >= 0x21 && LOBYTE(c) <= 0x7e) @@ -405,7 +408,7 @@ unsigned int CDECL _mbcjistojms(unsigned int c) */ unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cur) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) return (unsigned char *)(_ismbstrail(start,cur-1) ? cur - 2 : cur -1); return (unsigned char *)cur - 1; /* ASCII CP or SB char */ @@ -629,7 +632,7 @@ unsigned char* CDECL _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSV */ int CDECL _mbscmp(const unsigned char* str, const unsigned char* cmp) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int strc, cmpc; do { @@ -654,7 +657,7 @@ int CDECL _mbscmp(const unsigned char* str, const unsigned char* cmp) */ int CDECL _mbsicoll(const unsigned char* str, const unsigned char* cmp) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int strc, cmpc; do { @@ -682,7 +685,7 @@ int CDECL _mbsicoll(const unsigned char* str, const unsigned char* cmp) */ int CDECL _mbscoll(const unsigned char* str, const unsigned char* cmp) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int strc, cmpc; do { @@ -707,7 +710,7 @@ int CDECL _mbscoll(const unsigned char* str, const unsigned char* cmp) */ int CDECL _mbsicmp(const unsigned char* str, const unsigned char* cmp) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int strc, cmpc; do { @@ -734,7 +737,7 @@ int CDECL _mbsncmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_si if(!len) return 0; - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int strc, cmpc; while(len--) @@ -764,7 +767,7 @@ int CDECL _mbsnbcmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_s { if (!len) return 0; - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int strc, cmpc; while (len) @@ -807,7 +810,7 @@ int CDECL _mbsnbcmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_s int CDECL _mbsnicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_size_t len) { /* FIXME: No tolower() for mb strings yet */ - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int strc, cmpc; while(len--) @@ -835,7 +838,7 @@ int CDECL _mbsnbicmp(const unsigned char* str, const unsigned char* cmp, MSVCRT_ { if (!len) return 0; - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int strc, cmpc; while (len) @@ -905,7 +908,7 @@ unsigned char * CDECL _mbsstr(const unsigned char *haystack, const unsigned char */ unsigned char* CDECL _mbschr(const unsigned char* s, unsigned int x) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int c; while (1) @@ -926,7 +929,7 @@ unsigned char* CDECL _mbschr(const unsigned char* s, unsigned int x) */ unsigned char* CDECL _mbsrchr(const unsigned char* s, unsigned int x) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int c; unsigned char* match=NULL; @@ -954,7 +957,7 @@ unsigned char* CDECL _mbstok(unsigned char *str, const unsigned char *delim) thread_data_t *data = msvcrt_get_thread_data(); unsigned char *ret; - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned int c; @@ -1006,7 +1009,7 @@ int CDECL MSVCRT_mbtowc(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n) */ unsigned int CDECL _mbbtombc(unsigned int c) { - if(MSVCRT___mb_cur_max > 1 && + if(get_locale()->locinfo->mb_cur_max > 1 && ((c >= 0x20 && c <=0x7e) ||(c >= 0xa1 && c <= 0xdf))) { /* FIXME: I can't get this function to return anything @@ -1047,7 +1050,7 @@ int CDECL _mbbtype(unsigned char c, int type) int CDECL _ismbbkana(unsigned int c) { /* FIXME: use lc_ctype when supported, not lc_all */ - if(MSVCRT___lc_codepage == 932) + if(get_locale()->locinfo->lc_codepage == 932) { /* Japanese/Katakana, CP 932 */ return (c >= 0xa1 && c <= 0xdf); @@ -1157,7 +1160,7 @@ int CDECL _ismbcpunct(unsigned int ch) int CDECL _ismbchira(unsigned int c) { /* FIXME: use lc_ctype when supported, not lc_all */ - if(MSVCRT___lc_codepage == 932) + if(get_locale()->locinfo->lc_codepage == 932) { /* Japanese/Hiragana, CP 932 */ return (c >= 0x829f && c <= 0x82f1); @@ -1171,7 +1174,7 @@ int CDECL _ismbchira(unsigned int c) int CDECL _ismbckata(unsigned int c) { /* FIXME: use lc_ctype when supported, not lc_all */ - if(MSVCRT___lc_codepage == 932) + if(get_locale()->locinfo->lc_codepage == 932) { if(c < 256) return _ismbbkana(c); @@ -1280,7 +1283,7 @@ unsigned char* CDECL _mbsset(unsigned char* str, unsigned int c) { unsigned char* ret = str; - if(MSVCRT___mb_cur_max == 1 || c < 256) + if(get_locale()->locinfo->mb_cur_max == 1 || c < 256) return u__strset(str, c); /* ASCII CP or SB char */ c &= 0xffff; /* Strip high bits */ @@ -1306,7 +1309,7 @@ unsigned char* CDECL _mbsnbset(unsigned char *str, unsigned int c, MSVCRT_size_t if(!len) return ret; - if(MSVCRT___mb_cur_max == 1 || c < 256) + if(get_locale()->locinfo->mb_cur_max == 1 || c < 256) return u__strnset(str, c, len); /* ASCII CP or SB char */ c &= 0xffff; /* Strip high bits */ @@ -1336,7 +1339,7 @@ unsigned char* CDECL _mbsnset(unsigned char* str, unsigned int c, MSVCRT_size_t if(!len) return ret; - if(MSVCRT___mb_cur_max == 1 || c < 256) + if(get_locale()->locinfo->mb_cur_max == 1 || c < 256) return u__strnset(str, c, len); /* ASCII CP or SB char */ c &= 0xffff; /* Strip high bits */ @@ -1359,7 +1362,7 @@ unsigned char* CDECL _mbsnset(unsigned char* str, unsigned int c, MSVCRT_size_t MSVCRT_size_t CDECL _mbsnccnt(const unsigned char* str, MSVCRT_size_t len) { MSVCRT_size_t ret; - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { ret=0; while(*str && len-- > 0) @@ -1387,7 +1390,7 @@ MSVCRT_size_t CDECL _mbsnccnt(const unsigned char* str, MSVCRT_size_t len) MSVCRT_size_t CDECL _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len) { MSVCRT_size_t ret; - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { const unsigned char* xstr = str; while(*xstr && len-- > 0) @@ -1406,7 +1409,7 @@ MSVCRT_size_t CDECL _mbsnbcnt(const unsigned char* str, MSVCRT_size_t len) */ unsigned char* CDECL _mbsnbcat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned char *res = dst; while (*dst) { @@ -1433,7 +1436,7 @@ unsigned char* CDECL _mbsnbcat(unsigned char* dst, const unsigned char* src, MSV */ unsigned char* CDECL _mbsncat(unsigned char* dst, const unsigned char* src, MSVCRT_size_t len) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { unsigned char *res = dst; while (*dst) @@ -1462,7 +1465,7 @@ unsigned char* CDECL _mbslwr(unsigned char* s) unsigned char *ret = s; if (!s) return NULL; - if (MSVCRT___mb_cur_max > 1) + if (get_locale()->locinfo->mb_cur_max > 1) { unsigned int c; while (*s) @@ -1490,7 +1493,7 @@ unsigned char* CDECL _mbsupr(unsigned char* s) unsigned char *ret = s; if (!s) return NULL; - if (MSVCRT___mb_cur_max > 1) + if (get_locale()->locinfo->mb_cur_max > 1) { unsigned int c; while (*s) @@ -1581,7 +1584,7 @@ unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned char* */ MSVCRT_size_t CDECL _mbscspn(const unsigned char* str, const unsigned char* cmp) { - if (MSVCRT___mb_cur_max > 1) + if (get_locale()->locinfo->mb_cur_max > 1) FIXME("don't handle double character case\n"); return u_strcspn(str, cmp); } @@ -1668,7 +1671,7 @@ int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size) { if (str && *str && size) { - if(MSVCRT___mb_cur_max == 1) + if(get_locale()->locinfo->mb_cur_max == 1) return 1; /* ASCII CP */ return !MSVCRT_isleadbyte(*str) ? 1 : (size>1 ? 2 : -1); @@ -1684,7 +1687,7 @@ int CDECL MSVCRT_mblen(const char* str, MSVCRT_size_t size) */ MSVCRT_size_t CDECL _mbstrlen(const char* str) { - if(MSVCRT___mb_cur_max > 1) + if(get_locale()->locinfo->mb_cur_max > 1) { MSVCRT_size_t len = 0; while(*str)