From 133fd7faa131a36073fba2dfeeba005eaf024859 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 26 Mar 2023 17:51:56 +0100 Subject: [PATCH] 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. --- include/wx/string.h | 4 ++-- src/common/string.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/wx/string.h b/include/wx/string.h index b5cc276113..b434f9f8f0 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -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; } diff --git a/src/common/string.cpp b/src/common/string.cpp index 009cd2abea..1e0b893a3f 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -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