diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index 1760a1ac670..38ec0e1353d 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -675,7 +675,7 @@ @ varargs _fwscanf_s_l(ptr wstr ptr) msvcrt._fwscanf_s_l @ cdecl _gcvt(double long str) msvcrt._gcvt @ cdecl _gcvt_s(ptr long double long) msvcrt._gcvt_s -@ stub _get_current_locale +@ cdecl _get_current_locale() msvcrt._get_current_locale @ stub _get_daylight @ cdecl _get_doserrno(ptr) msvcrt._get_doserrno @ stub _get_dstbias diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec index 503864f368d..a083053229c 100644 --- a/dlls/msvcr80/msvcr80.spec +++ b/dlls/msvcr80/msvcr80.spec @@ -517,7 +517,7 @@ @ cdecl _gcvt(double long str) msvcrt._gcvt @ cdecl _gcvt_s(ptr long double long) msvcrt._gcvt_s @ stub _get_amblksiz -@ stub _get_current_locale +@ cdecl _get_current_locale() msvcrt._get_current_locale @ stub _get_daylight @ cdecl _get_doserrno(ptr) msvcrt._get_doserrno @ stub _get_dstbias diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec index 7976a0fd727..475e3a932bc 100644 --- a/dlls/msvcr90/msvcr90.spec +++ b/dlls/msvcr90/msvcr90.spec @@ -512,7 +512,7 @@ @ cdecl _gcvt(double long str) msvcrt._gcvt @ cdecl _gcvt_s(ptr long double long) msvcrt._gcvt_s @ stub _get_amblksiz -@ stub _get_current_locale +@ cdecl _get_current_locale() msvcrt._get_current_locale @ stub _get_daylight @ cdecl _get_doserrno(ptr) msvcrt._get_doserrno @ stub _get_dstbias diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index 44fdf7c6084..6bb6162a1be 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -603,6 +603,9 @@ void free_locinfo(MSVCRT_pthreadlocinfo locinfo) if(!locinfo) return; + if(InterlockedDecrement(&locinfo->refcount)) + return; + for(i=MSVCRT_LC_MIN+1; i<=MSVCRT_LC_MAX; i++) { MSVCRT_free(locinfo->lc_category[i].locale); MSVCRT_free(locinfo->lc_category[i].refcount); @@ -640,9 +643,26 @@ void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo) if(!mbcinfo) return; + if(InterlockedDecrement(&mbcinfo->refcount)) + return; + MSVCRT_free(mbcinfo); } +/* _get_current_locale - not exported in native msvcrt */ +MSVCRT__locale_t CDECL MSVCRT__get_current_locale(void) +{ + MSVCRT__locale_t loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct)); + if(!loc) + return NULL; + + loc->locinfo = get_locinfo(); + loc->mbcinfo = get_mbcinfo(); + InterlockedIncrement(&loc->locinfo->refcount); + InterlockedIncrement(&loc->mbcinfo->refcount); + return loc; +} + /* _free_locale - not exported in native msvcrt */ void CDECL MSVCRT__free_locale(MSVCRT__locale_t locale) { @@ -747,6 +767,8 @@ MSVCRT__locale_t CDECL MSVCRT__create_locale(int category, const char *locale) } memset(loc->locinfo, 0, sizeof(MSVCRT_threadlocinfo)); + loc->locinfo->refcount = 1; + loc->mbcinfo->refcount = 1; loc->locinfo->lconv = MSVCRT_malloc(sizeof(struct MSVCRT_lconv)); if(!loc->locinfo->lconv) { @@ -762,8 +784,6 @@ MSVCRT__locale_t CDECL MSVCRT__create_locale(int category, const char *locale) return NULL; } - loc->locinfo->refcount = 1; - if(lcid[MSVCRT_LC_COLLATE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_COLLATE)) { if(update_threadlocinfo_category(lcid[MSVCRT_LC_COLLATE], loc, MSVCRT_LC_COLLATE)) { MSVCRT__free_locale(loc); diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index dfd3a07f015..75a3b354d7f 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -1490,6 +1490,7 @@ @ cdecl -arch=i386 __control87_2(long long ptr ptr) @ cdecl _configthreadlocale(long) @ cdecl _create_locale(long str) MSVCRT__create_locale +@ cdecl _get_current_locale() MSVCRT__get_current_locale @ cdecl _dupenv_s(ptr ptr str) @ cdecl _free_locale(ptr) MSVCRT__free_locale @ cdecl _get_invalid_parameter_handler()