From 65116a209f725f638737f886ba4df1ad179d867d Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 13 Apr 2015 08:04:32 +0200 Subject: [PATCH] Prevent boost from throwing an exception when env's locale is invalid. --- CMakeLists.txt | 2 +- src/tomahawk/CMakeLists.txt | 1 + src/tomahawk/main.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 287a6d546..318062661 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,7 +266,7 @@ endif() macro_optional_find_package(Echonest 2.2.0) macro_log_feature(ECHONEST_FOUND "Echonest" "Qt library for communicating with The Echo Nest" "http://projects.kde.org/libechonest" TRUE "" "libechonest 2.2.0 is needed for dynamic playlists and the infosystem") -find_package(Boost REQUIRED COMPONENTS system) +find_package(Boost REQUIRED COMPONENTS filesystem system) macro_log_feature(Boost_FOUND "Boost" "Provides free peer-reviewed portable C++ source libraries" "http://www.boost.org" TRUE "" "") #FIXME: give useful explanation macro_optional_find_package(Lucene++ 3.0.0) diff --git a/src/tomahawk/CMakeLists.txt b/src/tomahawk/CMakeLists.txt index 66d170f0f..0197e2cdb 100644 --- a/src/tomahawk/CMakeLists.txt +++ b/src/tomahawk/CMakeLists.txt @@ -194,6 +194,7 @@ TARGET_LINK_LIBRARIES( tomahawk_bin ${MAC_EXTRA_LIBS} ${ECHONEST_LIBRARIES} ${TAGLIB_LIBRARIES} + ${Boost_LIBRARIES} ) IF( APPLE ) diff --git a/src/tomahawk/main.cpp b/src/tomahawk/main.cpp index 14b770f09..dbcbee32d 100644 --- a/src/tomahawk/main.cpp +++ b/src/tomahawk/main.cpp @@ -43,6 +43,30 @@ #endif #include +#include + + +void +checkLocales() +{ +#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) + std::locale l( "C" ); + try + { + // Check if env's locale is valid + l = std::locale( "" ); + } + catch ( const std::runtime_error& ) + { + // env's locale is invalid. Prevent boost from throwing an exception + setenv( "LC_ALL", "C", 1 ); + } + + // Needs be set by main thread + boost::filesystem::path::imbue( l ); +#endif +} + #ifdef Q_OS_WIN #include @@ -131,6 +155,8 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine int main( int argc, char *argv[] ) { + checkLocales(); + QCA::Initializer init; Q_UNUSED( init )