Fix wxString::GetCache() compilation in UTF-8 DLL build with MSVS

Don't declare static Cache variable inside wxString declaration itself
because it is implicitly DLL-exported, due to the use of
__declspec(dllexport) for the entire wxString class, but thread-specific
variables can't be exported, so this resulted in a compilation error.

Avoid this by using a static thread-specific variable inside GetCache(),
which had to be moved out of line.
This commit is contained in:
Vadim Zeitlin 2023-03-26 17:51:56 +01:00
parent 52e5561ca5
commit 133fd7faa1
2 changed files with 8 additions and 3 deletions

View file

@ -447,8 +447,8 @@ private:
unsigned lastUsed;
};
static wxTHREAD_SPECIFIC_DECL Cache ms_cache;
static Cache& GetCache() { return ms_cache; }
// Implemented out of line because per-thread variable can't be DLL exported.
static Cache& GetCache();
static Cache::Element *GetCacheBegin() { return GetCache().cached; }
static Cache::Element *GetCacheEnd() { return GetCacheBegin() + Cache::SIZE; }

View file

@ -75,7 +75,12 @@ const wxStringCharType WXDLLIMPEXP_BASE *wxEmptyStringImpl = "";
const wxChar WXDLLIMPEXP_BASE *wxEmptyString = wxT("");
#if wxUSE_STRING_POS_CACHE
wxTHREAD_SPECIFIC_DECL wxString::Cache wxString::ms_cache;
/* static */
wxString::Cache& wxString::GetCache()
{
static wxTHREAD_SPECIFIC_DECL Cache s_cache;
return s_cache;
}
// gdb seems to be unable to display thread-local variables correctly, at least
// not my 6.4.98 version under amd64, so provide this debugging helper to do it