From: Piotr Caban Subject: [PATCH 2/2] msvcp100: Fix basic_string class definition Message-Id: <5440EA61.1070301@codeweavers.com> Date: Fri, 17 Oct 2014 12:07:29 +0200 --- dlls/msvcp90/memory.c | 4 ++-- dlls/msvcp90/msvcp90.h | 14 ++++++++++++-- dlls/msvcp90/string.c | 24 ++++++++++++++++-------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/dlls/msvcp90/memory.c b/dlls/msvcp90/memory.c index c5cae50..5d43910 100644 --- a/dlls/msvcp90/memory.c +++ b/dlls/msvcp90/memory.c @@ -111,7 +111,7 @@ void __thiscall MSVCP_allocator_char_destroy(void *this, char *ptr) /* ?max_size@?$allocator@D@std@@QBEIXZ */ /* ?max_size@?$allocator@D@std@@QEBA_KXZ */ DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_max_size, 4) -MSVCP_size_t __thiscall MSVCP_allocator_char_max_size(void *this) +MSVCP_size_t __thiscall MSVCP_allocator_char_max_size(const void *this) { return UINT_MAX/sizeof(char); } @@ -208,7 +208,7 @@ void __thiscall MSVCP_allocator_wchar_destroy(void *this, char *ptr) /* ?max_size@?$allocator@_W@std@@QBEIXZ */ /* ?max_size@?$allocator@_W@std@@QEBA_KXZ */ DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_max_size, 4) -MSVCP_size_t __thiscall MSVCP_allocator_wchar_max_size(void *this) +MSVCP_size_t __thiscall MSVCP_allocator_wchar_max_size(const void *this) { return UINT_MAX/sizeof(wchar_t); } diff --git a/dlls/msvcp90/msvcp90.h b/dlls/msvcp90/msvcp90.h index 3fb6790..0a60d46 100644 --- a/dlls/msvcp90/msvcp90.h +++ b/dlls/msvcp90/msvcp90.h @@ -74,13 +74,18 @@ extern MSVCP_bool (__thiscall *critical_section_trylock)(critical_section*); #define BUF_SIZE_CHAR 16 typedef struct { +#if _MSVCP_VER <= 90 void *allocator; +#endif union { char buf[BUF_SIZE_CHAR]; char *ptr; } data; MSVCP_size_t size; MSVCP_size_t res; +#if _MSVCP_VER == 100 + char allocator; +#endif } basic_string_char; basic_string_char* __thiscall MSVCP_basic_string_char_ctor(basic_string_char*); @@ -97,13 +102,18 @@ basic_string_char* __thiscall MSVCP_basic_string_char_assign(basic_string_char*, #define BUF_SIZE_WCHAR 8 typedef struct { +#if _MSVCP_VER <= 90 void *allocator; +#endif union { wchar_t buf[BUF_SIZE_WCHAR]; wchar_t *ptr; } data; MSVCP_size_t size; MSVCP_size_t res; +#if _MSVCP_VER == 100 + char allocator; +#endif } basic_string_wchar; basic_string_wchar* __thiscall MSVCP_basic_string_wchar_ctor(basic_string_wchar*); @@ -117,10 +127,10 @@ MSVCP_size_t __thiscall MSVCP_basic_string_wchar_length(const basic_string_wchar char* __thiscall MSVCP_allocator_char_allocate(void*, MSVCP_size_t); void __thiscall MSVCP_allocator_char_deallocate(void*, char*, MSVCP_size_t); -MSVCP_size_t __thiscall MSVCP_allocator_char_max_size(void*); +MSVCP_size_t __thiscall MSVCP_allocator_char_max_size(const void*); wchar_t* __thiscall MSVCP_allocator_wchar_allocate(void*, MSVCP_size_t); void __thiscall MSVCP_allocator_wchar_deallocate(void*, wchar_t*, MSVCP_size_t); -MSVCP_size_t __thiscall MSVCP_allocator_wchar_max_size(void*); +MSVCP_size_t __thiscall MSVCP_allocator_wchar_max_size(const void*); typedef struct { diff --git a/dlls/msvcp90/string.c b/dlls/msvcp90/string.c index ce05613..810fb5a 100644 --- a/dlls/msvcp90/string.c +++ b/dlls/msvcp90/string.c @@ -29,6 +29,14 @@ #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(msvcp); +#if _MSVCP_VER <= 90 +#define STRING_ALLOCATOR(this) ((this)->allocator) +#elif _MSVCP_VER == 100 +#define STRING_ALLOCATOR(this) (&(this)->allocator) +#else +#define STRING_ALLOCATOR(this) NULL +#endif + /* size_t_noverify structure */ typedef struct { MSVCP_size_t val; @@ -546,7 +554,7 @@ void __thiscall basic_string_char_tidy(basic_string_char *this, if(new_size > 0) MSVCP_char_traits_char__Copy_s(this->data.buf, BUF_SIZE_CHAR, ptr, new_size); - MSVCP_allocator_char_deallocate(this->allocator, ptr, this->res+1); + MSVCP_allocator_char_deallocate(STRING_ALLOCATOR(this), ptr, this->res+1); } this->res = BUF_SIZE_CHAR-1; @@ -577,9 +585,9 @@ MSVCP_bool __thiscall basic_string_char_grow( if(new_res/3 < this->res/2) new_res = this->res + this->res/2; - ptr = MSVCP_allocator_char_allocate(this->allocator, new_res+1); + ptr = MSVCP_allocator_char_allocate(STRING_ALLOCATOR(this), new_res+1); if(!ptr) - ptr = MSVCP_allocator_char_allocate(this->allocator, new_size+1); + ptr = MSVCP_allocator_char_allocate(STRING_ALLOCATOR(this), new_size+1); else new_size = new_res; if(!ptr) { @@ -988,7 +996,7 @@ DEFINE_THISCALL_WRAPPER(basic_string_char_max_size, 4) MSVCP_size_t __thiscall basic_string_char_max_size(const basic_string_char *this) { TRACE("%p\n", this); - return MSVCP_allocator_char_max_size(this->allocator)-1; + return MSVCP_allocator_char_max_size(STRING_ALLOCATOR(this))-1; } /* ?empty@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE_NXZ */ @@ -2228,7 +2236,7 @@ void __thiscall basic_string_wchar_tidy(basic_string_wchar *this, if(new_size > 0) MSVCP_char_traits_wchar__Copy_s(this->data.buf, BUF_SIZE_WCHAR, ptr, new_size); - MSVCP_allocator_wchar_deallocate(this->allocator, ptr, this->res+1); + MSVCP_allocator_wchar_deallocate(STRING_ALLOCATOR(this), ptr, this->res+1); } this->res = BUF_SIZE_WCHAR-1; @@ -2252,9 +2260,9 @@ MSVCP_bool __thiscall basic_string_wchar_grow( if(new_res/3 < this->res/2) new_res = this->res + this->res/2; - ptr = MSVCP_allocator_wchar_allocate(this->allocator, new_res+1); + ptr = MSVCP_allocator_wchar_allocate(STRING_ALLOCATOR(this), new_res+1); if(!ptr) - ptr = MSVCP_allocator_wchar_allocate(this->allocator, new_size+1); + ptr = MSVCP_allocator_wchar_allocate(STRING_ALLOCATOR(this), new_size+1); else new_size = new_res; if(!ptr) { @@ -2733,7 +2741,7 @@ DEFINE_THISCALL_WRAPPER(basic_string_wchar_max_size, 4) MSVCP_size_t __thiscall basic_string_wchar_max_size(const basic_string_wchar *this) { TRACE("%p\n", this); - return MSVCP_allocator_wchar_max_size(this->allocator)-1; + return MSVCP_allocator_wchar_max_size(STRING_ALLOCATOR(this))-1; } /* ?empty@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBE_NXZ */