msvcrt: Share __lc_time_data between threadlocinfo instances.

My testing shows that unk[1] is some sort of refcount.

Signed-off-by: Chip Davis <cdavis@codeweavers.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Chip Davis 2020-11-18 17:26:15 +01:00 committed by Alexandre Julliard
parent 10cac0a08f
commit 898abfc18f
3 changed files with 14 additions and 7 deletions

View File

@ -2084,7 +2084,7 @@ static void test__get_current_locale(void)
todo_wine ok(*l->locinfo->lconv_mon_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
todo_wine ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
todo_wine ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
p__free_locale(l2);
@ -2159,7 +2159,7 @@ static void test__get_current_locale(void)
todo_wine ok(*l->locinfo->lconv_mon_refcount == 3, "refcount = %d\n", *l->locinfo->lconv_mon_refcount);
ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
todo_wine ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
todo_wine ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
p__free_locale(l2);
@ -2240,7 +2240,7 @@ static void test__get_current_locale(void)
ok(!l2->locinfo->lconv_mon_refcount, "nonnull refcount pointer for C locale\n");
ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
todo_wine ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
todo_wine ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
p__free_locale(l2);
@ -2322,7 +2322,7 @@ static void test__get_current_locale(void)
ok(!l2->locinfo->lconv_mon_refcount, "nonnull refcount pointer for C locale\n");
ok(l->locinfo->lc_time_curr == l2->locinfo->lc_time_curr, "different lc_time_curr pointers\n");
todo_wine ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
ok(l->locinfo->lc_time_curr->unk == 1, "unk = %d\n", l->locinfo->lc_time_curr->unk);
todo_wine ok(l->locinfo->lc_time_curr->refcount == 3, "refcount = %d\n", l->locinfo->lc_time_curr->refcount);
p__free_locale(l2);

View File

@ -109,7 +109,7 @@ MSVCRT___lc_time_data cloc_time_data =
#if _MSVCR_VER < 110
MAKELCID(LANG_ENGLISH, SORT_DEFAULT),
#endif
{1, 0},
1, 0,
{{sun, mon, tue, wed, thu, fri, sat,
sunday, monday, tuesday, wednesday, thursday, friday, saturday,
jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec,
@ -1103,7 +1103,8 @@ void free_locinfo(MSVCRT_pthreadlocinfo locinfo)
MSVCRT_free((void*)locinfo->pcumap);
}
if(locinfo->lc_time_curr != &cloc_time_data)
if(locinfo->lc_time_curr && locinfo->lc_time_curr != &cloc_time_data
&& !InterlockedDecrement(&locinfo->lc_time_curr->refcount))
MSVCRT_free(locinfo->lc_time_curr);
MSVCRT_free(locinfo);
@ -1237,6 +1238,8 @@ static MSVCRT___lc_time_data* create_time_data(LCID lcid)
#else
cur->lcid = lcid;
#endif
cur->unk = 1;
cur->refcount = 1;
return cur;
}
@ -1889,6 +1892,9 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
if(!category_needs_update(MSVCRT_LC_TIME, category, old_locinfo,
lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME])) {
copy_threadlocinfo_category(locinfo, old_locinfo, MSVCRT_LC_TIME);
locinfo->lc_time_curr = old_locinfo->lc_time_curr;
if(locinfo->lc_time_curr != &cloc_time_data)
InterlockedIncrement(&locinfo->lc_time_curr->refcount);
} else if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) {
if(!update_threadlocinfo_category(lcid[MSVCRT_LC_TIME],
cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) {

View File

@ -149,7 +149,8 @@ typedef struct {
#if _MSVCR_VER < 110
LCID lcid;
#endif
int unk[2];
int unk;
int refcount;
union {
const MSVCRT_wchar_t *wstr[43];
struct {