Module: wine Branch: master Commit: db55e0701628b08050fb479acb399e6eebf2e42f URL: https://source.winehq.org/git/wine.git/?a=commit;h=db55e0701628b08050fb479ac...
Author: Charles Davis cdavis@codeweavers.com Date: Wed Nov 18 17:25:39 2020 +0100
msvcrt: Make locale name string refcounted for C locale.
Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/msvcr90/tests/msvcr90.c | 64 +++++++++++++++----------------------------- dlls/msvcrt/locale.c | 28 ++++++++++++++----- 2 files changed, 44 insertions(+), 48 deletions(-)
diff --git a/dlls/msvcr90/tests/msvcr90.c b/dlls/msvcr90/tests/msvcr90.c index 504dbf53d8f..476ad222fcf 100644 --- a/dlls/msvcr90/tests/msvcr90.c +++ b/dlls/msvcr90/tests/msvcr90.c @@ -2036,15 +2036,11 @@ static void test__get_current_locale(void) "same locale name pointers for LC_COLLATE\n"); ok(l->locinfo->lc_category[LC_COLLATE].refcount != l2->locinfo->lc_category[LC_COLLATE].refcount, "same refcount pointers for LC_COLLATE\n"); - ok(!!l->locinfo->lc_category[LC_COLLATE].refcount, "null refcount pointer for LC_COLLATE\n"); - if(l->locinfo->lc_category[LC_COLLATE].refcount) - ok(*l->locinfo->lc_category[LC_COLLATE].refcount == 1, "refcount = %d\n", - *l->locinfo->lc_category[LC_COLLATE].refcount); - ok(!!l2->locinfo->lc_category[LC_COLLATE].refcount, "null refcount pointer for LC_COLLATE\n"); - if(l2->locinfo->lc_category[LC_COLLATE].refcount) - ok(*l2->locinfo->lc_category[LC_COLLATE].refcount == 2, "refcount = %d\n", - *l2->locinfo->lc_category[LC_COLLATE].refcount); + ok(*l2->locinfo->lc_category[LC_COLLATE].refcount == 2, "refcount = %d\n", + *l2->locinfo->lc_category[LC_COLLATE].refcount); } + ok(*l->locinfo->lc_category[LC_COLLATE].refcount == 1, "refcount = %d\n", + *l->locinfo->lc_category[LC_COLLATE].refcount); for(i = LC_CTYPE; i <= LC_MAX; i++) { ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale, "different locale name pointers for category %d\n", i); @@ -2107,15 +2103,11 @@ static void test__get_current_locale(void) "same locale name pointers for category %d\n", i); ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount, "same refcount pointers for category %d\n", i); - ok(!!l->locinfo->lc_category[i].refcount, "null refcount pointer for category %d\n", i); - if(l->locinfo->lc_category[i].refcount) - ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n", - *l->locinfo->lc_category[i].refcount, i); - ok(!!l2->locinfo->lc_category[i].refcount, "null refcount pointer for category %d\n", i); - if(l2->locinfo->lc_category[i].refcount) - ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n", - *l2->locinfo->lc_category[i].refcount, i); + ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n", + *l2->locinfo->lc_category[i].refcount, i); } + ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n", + *l->locinfo->lc_category[i].refcount, i); } for(i = LC_MONETARY; i <= LC_MAX; i++) { ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale, @@ -2186,15 +2178,11 @@ static void test__get_current_locale(void) "same locale name pointers for category %d\n", i); ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount, "same refcount pointers for category %d\n", i); - ok(!!l->locinfo->lc_category[i].refcount, "null refcount pointer for category %d\n", i); - if(l->locinfo->lc_category[i].refcount) - ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n", - *l->locinfo->lc_category[i].refcount, i); - ok(!!l2->locinfo->lc_category[i].refcount, "null refcount pointer for category %d\n", i); - if(l2->locinfo->lc_category[i].refcount) - ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n", - *l2->locinfo->lc_category[i].refcount, i); + ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n", + *l2->locinfo->lc_category[i].refcount, i); } + ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n", + *l->locinfo->lc_category[i].refcount, i); } for(i = LC_NUMERIC; i <= LC_MAX; i++) { ok(l->locinfo->lc_category[i].locale == l2->locinfo->lc_category[i].locale, @@ -2273,15 +2261,11 @@ static void test__get_current_locale(void) "same locale name pointers for category %d\n", i); ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount, "same refcount pointers for category %d\n", i); - ok(!!l->locinfo->lc_category[i].refcount, "null refcount pointer for category %d\n", i); - if(l->locinfo->lc_category[i].refcount) - ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n", - *l->locinfo->lc_category[i].refcount, i); - ok(!!l2->locinfo->lc_category[i].refcount, "null refcount pointer for category %d\n", i); - if(l2->locinfo->lc_category[i].refcount) - ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n", - *l2->locinfo->lc_category[i].refcount, i); + ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n", + *l2->locinfo->lc_category[i].refcount, i); } + ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n", + *l->locinfo->lc_category[i].refcount, i); } ok(l->locinfo->lc_category[LC_TIME].locale == l2->locinfo->lc_category[LC_TIME].locale, "different locale name pointers for LC_TIME\n"); @@ -2353,21 +2337,17 @@ static void test__get_current_locale(void) ok(l2->locinfo->refcount == 2, "refcount = %d\n", l2->locinfo->refcount); }
- todo_wine { - for(i = LC_MIN+1; i <= LC_MAX; i++) { + for(i = LC_MIN+1; i <= LC_MAX; i++) { + todo_wine { ok(l->locinfo->lc_category[i].locale != l2->locinfo->lc_category[i].locale, "same locale name pointers for category %d\n", i); ok(l->locinfo->lc_category[i].refcount != l2->locinfo->lc_category[i].refcount, "same refcount pointers for category %d\n", i); - ok(!!l->locinfo->lc_category[i].refcount, "null refcount pointer for category %d\n", i); - if(l->locinfo->lc_category[i].refcount) - ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n", - *l->locinfo->lc_category[i].refcount, i); - ok(!!l2->locinfo->lc_category[i].refcount, "null refcount pointer for category %d\n", i); - if(l2->locinfo->lc_category[i].refcount) - ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n", - *l2->locinfo->lc_category[i].refcount, i); + ok(*l2->locinfo->lc_category[i].refcount == 2, "refcount = %d for category %d\n", + *l2->locinfo->lc_category[i].refcount, i); } + ok(*l->locinfo->lc_category[i].refcount == 1, "refcount = %d for category %d\n", + *l->locinfo->lc_category[i].refcount, i); }
todo_wine { diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index b24871b9cd7..4b20f097758 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -1247,8 +1247,12 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, free_locinfo(locinfo); return NULL; } - } else - locinfo->lc_category[MSVCRT_LC_COLLATE].locale = MSVCRT__strdup("C"); + } else { + if(!init_category_name("C", 1, locinfo, MSVCRT_LC_COLLATE)) { + free_locinfo(locinfo); + return NULL; + } + }
if(locale_name[MSVCRT_LC_CTYPE] && !init_category_name(locale_name[MSVCRT_LC_CTYPE], @@ -1325,7 +1329,10 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lc_clike = 1; locinfo->mb_cur_max = 1; locinfo->pctype = MSVCRT__ctype+1; - locinfo->lc_category[MSVCRT_LC_CTYPE].locale = MSVCRT__strdup("C"); + if(!init_category_name("C", 1, locinfo, MSVCRT_LC_CTYPE)) { + free_locinfo(locinfo); + return NULL; + }
for(i=0; i<256; i++) { if(locinfo->pctype[i] & MSVCRT__LEADBYTE) @@ -1617,7 +1624,10 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lconv->_W_negative_sign[0] = '\0'; #endif
- locinfo->lc_category[MSVCRT_LC_MONETARY].locale = MSVCRT__strdup("C"); + if(!init_category_name("C", 1, locinfo, MSVCRT_LC_MONETARY)) { + free_locinfo(locinfo); + return NULL; + } }
if(locale_name[MSVCRT_LC_NUMERIC] && @@ -1735,7 +1745,10 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, locinfo->lconv->_W_thousands_sep[0] = '\0'; #endif
- locinfo->lc_category[MSVCRT_LC_NUMERIC].locale = MSVCRT__strdup("C"); + if (!init_category_name("C", 1, locinfo, MSVCRT_LC_NUMERIC)) { + free_locinfo(locinfo); + return NULL; + } }
if(locale_name[MSVCRT_LC_TIME] && @@ -1767,7 +1780,10 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, return NULL; } } else { - locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C"); + if(!init_category_name("C", 1, locinfo, MSVCRT_LC_TIME)) { + free_locinfo(locinfo); + return NULL; + } locinfo->lc_time_curr = &cloc_time_data; }