Skip to content

Commit c9e022b

Browse files
dexX7laanwj
authored andcommitted
Initialization: set Boost path locale in main thread
The path locale is lazy initialized and to avoid deinitialization errors in multithreading environments, it is set explicitly by the main thread. Conflicts: src/util.cpp Rebased-From: 317e66c Github-Pull: #5877
1 parent 10c09f9 commit c9e022b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/util.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -713,19 +713,18 @@ void RenameThread(const char* name)
713713

714714
void SetupEnvironment()
715715
{
716-
#ifndef WIN32
717-
try
718-
{
719-
#if BOOST_FILESYSTEM_VERSION == 3
720-
boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid
721-
#else // boost filesystem v2
722-
std::locale(); // Raises runtime error if current locale is invalid
723-
#endif
724-
} catch(std::runtime_error &e)
725-
{
726-
setenv("LC_ALL", "C", 1); // Force C locale
716+
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
717+
// may be invalid, in which case the "C" locale is used as fallback.
718+
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
719+
try {
720+
std::locale(""); // Raises a runtime error if current locale is invalid
721+
} catch (const std::runtime_error&) {
722+
std::locale::global(std::locale("C"));
727723
}
728724
#endif
725+
// The path locale is lazy initialized and to avoid deinitialization errors
726+
// in multithreading environments, it is set explicitly by the main thread.
727+
boost::filesystem::path::imbue(std::locale());
729728
}
730729

731730
void SetThreadPriority(int nPriority)

0 commit comments

Comments
 (0)