From 045de24c9ce6458c31477103688beb143b2636c2 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 11 Apr 2021 02:44:53 +0100 Subject: [PATCH] Revert "Windows: Use TLS to avoid sharing buffers for FS2OTTD, OTTD2FS, GetCurrentLocale" This reverts commit 0a61671ff15e3c05835632a447421597f618348b. # Conflicts: # src/os/windows/win32.cpp --- src/os/windows/win32.cpp | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index fd990fbd4f..3746dd4f33 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -44,24 +44,6 @@ static bool _has_console; static bool _cursor_disable = true; static bool _cursor_visible = true; -static DWORD _tlsdata_key; - -struct TLSData { - char utf8_buf[512]; - wchar_t system_buf[512]; - char locale_retbuf[6]; -}; - -TLSData *GetTLSData() -{ - TLSData *data = (TLSData *) TlsGetValue(_tlsdata_key); - if (data == nullptr) { - data = CallocT(1); - TlsSetValue(_tlsdata_key, data); - } - return data; -} - bool MyShowCursor(bool show, bool toggle) { if (toggle) _cursor_disable = !_cursor_disable; @@ -428,8 +410,6 @@ void ShowInfo(const char *str) int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - _tlsdata_key = TlsAlloc(); - int argc; char *argv[64]; // max 64 command line arguments @@ -591,8 +571,8 @@ bool GetClipboardContents(char *buffer, const char *last) */ const char *FS2OTTD(const wchar_t *name) { - TLSData *data = GetTLSData(); - return convert_from_fs(name, data->utf8_buf, lengthof(data->utf8_buf)); + static char utf8_buf[512]; + return convert_from_fs(name, utf8_buf, lengthof(utf8_buf)); } /** @@ -606,8 +586,8 @@ const char *FS2OTTD(const wchar_t *name) */ const wchar_t *OTTD2FS(const char *name, bool console_cp) { - TLSData *data = GetTLSData(); - return convert_to_fs(name, data->system_buf, lengthof(data->system_buf), console_cp); + static TCHAR system_buf[512]; + return convert_to_fs(name, system_buf, lengthof(system_buf), console_cp); } @@ -659,14 +639,8 @@ const char *GetCurrentLocale(const char *) return nullptr; } /* Format it as 'en_us'. */ - TLSData *data = GetTLSData(); - data->locale_retbuf[0] = lang[0]; - data->locale_retbuf[1] = lang[1]; - data->locale_retbuf[2] = '_'; - data->locale_retbuf[3] = country[0]; - data->locale_retbuf[4] = country[1]; - data->locale_retbuf[5] = 0; - return data->locale_retbuf; + static char retbuf[6] = {lang[0], lang[1], '_', country[0], country[1], 0}; + return retbuf; }