Piotr Caban : msvcp90: Fixed default locale constructor implementation.

Alexandre Julliard julliard at winehq.org
Tue Jun 12 13:36:33 CDT 2012


Module: wine
Branch: master
Commit: 1d0b072d0f1d5adf3229eca282ce42de11a231d9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1d0b072d0f1d5adf3229eca282ce42de11a231d9

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue Jun 12 18:12:12 2012 +0200

msvcp90: Fixed default locale constructor implementation.

---

 dlls/msvcp90/locale.c       |   78 +++++++++++++++++++++++++++++++------------
 dlls/msvcp90/msvcp90.h      |    1 +
 dlls/msvcp90/msvcp90_main.c |    1 +
 3 files changed, 58 insertions(+), 22 deletions(-)

diff --git a/dlls/msvcp90/locale.c b/dlls/msvcp90/locale.c
index 54c2eaf..49d864a 100644
--- a/dlls/msvcp90/locale.c
+++ b/dlls/msvcp90/locale.c
@@ -163,6 +163,9 @@ typedef struct _istreambuf_iterator_wchar
 /* ?_Id_cnt at id@locale at std@@0HA */
 int locale_id__Id_cnt = 0;
 
+static locale__Locimp *global_locale;
+static locale classic_locale;
+
 /* ?_Clocptr at _Locimp@locale at std@@0PAV123 at A */
 /* ?_Clocptr at _Locimp@locale at std@@0PEAV123 at EA */
 locale__Locimp *locale__Locimp__Clocptr = NULL;
@@ -2606,7 +2609,6 @@ codecvt_char* __thiscall codecvt_char_ctor(codecvt_char *this)
     return codecvt_char_ctor_locinfo(this, NULL, 0);
 }
 
-/* ?_Getcat@?$codecvt at DDH@std@@SAIPAPBVfacet at locale@2 at PBV42@@Z */
 /* ??1?$codecvt at DDH@std@@MAE at XZ */
 /* ??1?$codecvt at DDH@std@@MEAA at XZ */
 DEFINE_THISCALL_WRAPPER(codecvt_char_dtor, 4)
@@ -2636,6 +2638,7 @@ codecvt_char* __thiscall MSVCP_codecvt_char_vector_dtor(codecvt_char *this, unsi
     return this;
 }
 
+/* ?_Getcat@?$codecvt at DDH@std@@SAIPAPBVfacet at locale@2 at PBV42@@Z */
 /* ?_Getcat@?$codecvt at DDH@std@@SA_KPEAPEBVfacet at locale@2 at PEBV42@@Z */
 MSVCP_size_t __cdecl codecvt_char__Getcat(const locale_facet **facet, const locale *loc)
 {
@@ -4338,6 +4341,41 @@ locale* __thiscall locale_ctor_locimp(locale *this, locale__Locimp *locimp)
     return this;
 }
 
+/* ?_Init at locale@std@@CAPAV_Locimp at 12@XZ */
+/* ?_Init at locale@std@@CAPEAV_Locimp at 12@XZ */
+locale__Locimp* __cdecl locale__Init(void)
+{
+    _Lockit lock;
+
+    TRACE("\n");
+
+    _Lockit_ctor_locktype(&lock, _LOCK_LOCALE);
+    if(global_locale) {
+        _Lockit_dtor(&lock);
+        return global_locale;
+    }
+
+    global_locale = MSVCRT_operator_new(sizeof(locale__Locimp));
+    if(!global_locale) {
+        _Lockit_dtor(&lock);
+        ERR("Out of memory\n");
+        throw_exception(EXCEPTION_BAD_ALLOC, NULL);
+        return NULL;
+    }
+
+    locale__Locimp_ctor(global_locale);
+    global_locale->catmask = (1<<(LC_MAX+1))-1;
+    MSVCP_basic_string_char_dtor(&global_locale->name);
+    MSVCP_basic_string_char_ctor_cstr(&global_locale->name, "C");
+
+    locale__Locimp__Clocptr = global_locale;
+    global_locale->facet.refs++;
+    locale_ctor_locimp(&classic_locale, locale__Locimp__Clocptr);
+    _Lockit_dtor(&lock);
+
+    return global_locale;
+}
+
 /* ??0locale at std@@QAE at ABV01@0H at Z */
 /* ??0locale at std@@QEAA at AEBV01@0H at Z */
 DEFINE_THISCALL_WRAPPER(locale_ctor_locale_locale, 16)
@@ -4392,14 +4430,8 @@ DEFINE_THISCALL_WRAPPER(locale_ctor, 4)
 locale* __thiscall locale_ctor(locale *this)
 {
     TRACE("(%p)\n", this);
-    this->ptr = MSVCRT_operator_new(sizeof(locale__Locimp));
-    if(!this->ptr) {
-        ERR("Out of memory\n");
-        throw_exception(EXCEPTION_BAD_ALLOC, NULL);
-        return NULL;
-    }
-
-    locale__Locimp_ctor(this->ptr);
+    this->ptr = locale__Init();
+    locale_facet__Incref(&this->ptr->facet);
     return this;
 }
 
@@ -4497,35 +4529,29 @@ const locale_facet* __thiscall locale__Getfacet(const locale *this, MSVCP_size_t
     return NULL;
 }
 
-/* ?_Init at locale@std@@CAPAV_Locimp at 12@XZ */
-/* ?_Init at locale@std@@CAPEAV_Locimp at 12@XZ */
-locale__Locimp* __cdecl locale__Init(void)
-{
-    FIXME("stub\n");
-    return NULL;
-}
-
 /* ?_Getgloballocale at locale@std@@CAPAV_Locimp at 12@XZ */
 /* ?_Getgloballocale at locale@std@@CAPEAV_Locimp at 12@XZ */
 locale__Locimp* __cdecl locale__Getgloballocale(void)
 {
-    FIXME("stub\n");
-    return NULL;
+    TRACE("\n");
+    return global_locale;
 }
 
 /* ?_Setgloballocale at locale@std@@CAXPAX at Z */
 /* ?_Setgloballocale at locale@std@@CAXPEAX at Z */
 void __cdecl locale__Setgloballocale(void *locimp)
 {
-    FIXME("(%p) stub\n", locimp);
+    TRACE("(%p)\n", locimp);
+    global_locale = locimp;
 }
 
 /* ?classic at locale@std@@SAABV12 at XZ */
 /* ?classic at locale@std@@SAAEBV12 at XZ */
 const locale* __cdecl locale_classic(void)
 {
-    FIXME("stub\n");
-    return NULL;
+    TRACE("\n");
+    locale__Init();
+    return &classic_locale;
 }
 
 /* ?name at locale@std@@QBE?AV?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@2 at XZ */
@@ -4682,3 +4708,11 @@ void __asm_dummy_vtables(void) {
 #ifndef __GNUC__
 }
 #endif
+
+void free_locale(void)
+{
+    if(global_locale) {
+        locale__Locimp_dtor(global_locale);
+        locale_dtor(&classic_locale);
+    }
+}
diff --git a/dlls/msvcp90/msvcp90.h b/dlls/msvcp90/msvcp90.h
index f15e832..47bcc26 100644
--- a/dlls/msvcp90/msvcp90.h
+++ b/dlls/msvcp90/msvcp90.h
@@ -267,6 +267,7 @@ locale* __thiscall locale_ctor(locale*);
 locale* __thiscall locale_copy_ctor(locale*, const locale*);
 locale* __thiscall locale_operator_assign(locale*, const locale*);
 void __thiscall locale_dtor(locale*);
+void free_locale(void);
 
 /* class _Lockit */
 typedef struct {
diff --git a/dlls/msvcp90/msvcp90_main.c b/dlls/msvcp90/msvcp90_main.c
index 6a1d4d2..de036e5 100644
--- a/dlls/msvcp90/msvcp90_main.c
+++ b/dlls/msvcp90/msvcp90_main.c
@@ -92,6 +92,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
             init_lockit();
             break;
         case DLL_PROCESS_DETACH:
+            free_locale();
             free_lockit();
             break;
     }




More information about the wine-cvs mailing list