Skip to content

Commit

Permalink
Fix wxString::GetCache() compilation in UTF-8 DLL build with MSVS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vadz committed Mar 26, 2023
1 parent 52e5561 commit 133fd7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/wx/string.h
Expand Up @@ -447,8 +447,8 @@ class WXDLLIMPEXP_BASE wxString
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; }
Expand Down
7 changes: 6 additions & 1 deletion src/common/string.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 133fd7f

Please sign in to comment.