From 899f5105b9aa3cd660f4b25b8779d2dd034c86e2 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Wed, 6 Jul 2011 21:19:59 +0000 Subject: [PATCH] Fix glwprintf errors on OS X with non-ASCII strings, by setting LC_CTYPE to UTF-8 This was SVN commit r9768. --- source/ps/GameSetup/GameSetup.cpp | 17 +++++++++++++---- source/test_setup.cpp | 9 +++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 70ac83541a..970abbbfad 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -675,10 +675,19 @@ void Shutdown(int UNUSED(flags)) } #if OS_UNIX -void SetDefaultIfLocaleInvalid() +static void FixLocales() { +#if OS_MACOSX + // OS X requires a UTF-8 locale in LC_CTYPE so that *wprintf can handle + // wide characters. Peculiarly the string "UTF-8" seems to be acceptable + // despite not being a real locale, and it's conveniently language-agnostic, + // so use that. + setlocale(LC_CTYPE, "UTF-8"); +#endif + + // On misconfigured systems with incorrect locale settings, we'll die - // with a C++ exception when some code tries to use locales. + // with a C++ exception when some code (e.g. Boost) tries to use locales. // To avoid death, we'll detect the problem here and warn the user and // reset to the default C locale. @@ -723,7 +732,7 @@ void SetDefaultIfLocaleInvalid() } } #else -void SetDefaultIfLocaleInvalid() +static void FixLocales() { // Do nothing on Windows } @@ -744,7 +753,7 @@ void EarlyInit() timer_LatchStartTime(); - SetDefaultIfLocaleInvalid(); + FixLocales(); // Because we do GL calls from a secondary thread, Xlib needs to // be told to support multiple threads safely. diff --git a/source/test_setup.cpp b/source/test_setup.cpp index d1239dbf5a..5a83253172 100644 --- a/source/test_setup.cpp +++ b/source/test_setup.cpp @@ -65,20 +65,25 @@ class LeakReporter : public CxxTest::GlobalFixture }; -class TimerSetup : public CxxTest::GlobalFixture +class MiscSetup : public CxxTest::GlobalFixture { virtual bool setUpWorld() { // Timer must be initialised, else things will break when tests do IO timer_LatchStartTime(); +#if OS_MACOSX + // See comment in GameSetup.cpp FixLocales + setlocale(LC_CTYPE, "UTF-8"); +#endif + return true; } }; static LeakReporter leakReporter; -static TimerSetup timerSetup; +static MiscSetup miscSetup; // Definition of functions from lib/self_test.h