Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supertux/main: add try-catch for locale initialization. #1601

Merged
merged 2 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/supertux/error_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

#include "supertux/error_handler.hpp"

// apparently this is exclusive to glibc as of 2020, keep checking for
// llvm/msvc equivalent from time to time ~ Semphris
#ifdef __GLIBCXX__
// execinfo.h as a built-in libc feature is exclusive to glibc as of 2020.
// On FreeBSD and musl systems, an external libexecinfo is available, but
// it has to be explicitly linked into the final executable.
// This is a *libc* feature, not a compiler one; furthermore, it's possible
// to verify its availability in CMakeLists.txt, if one is so inclined.
#ifdef __GLIBC__
#include <execinfo.h>
#include <signal.h>
#include <unistd.h>
Expand All @@ -29,7 +32,7 @@ bool ErrorHandler::m_handing_error = false;
void
ErrorHandler::set_handlers()
{
#ifdef __GLIBCXX__
#ifdef __GLIBC__
signal(SIGSEGV, handle_error);
#endif
}
Expand All @@ -56,7 +59,7 @@ ErrorHandler::handle_error(int sig)
void
ErrorHandler::print_stack_trace()
{
#ifdef __GLIBCXX__
#ifdef __GLIBC__
void *array[10];
size_t size;

Expand Down
18 changes: 14 additions & 4 deletions src/supertux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,20 @@ Main::run(int argc, char** argv)
_wfreopen(w_errpath.c_str(), L"a", stderr);
#endif

// Create and install global locale
std::locale::global(boost::locale::generator().generate(""));
// Make boost.filesystem use it
boost::filesystem::path::imbue(std::locale());
// Create and install global locale - this can fail on some situations:
// - with bad values for env vars (LANG, LC_ALL, ...)
// - targets where libstdc++ uses its generic locales code (https://gcc.gnu.org/legacy-ml/libstdc++/2003-02/msg00345.html)
// NOTE: when moving to C++ >= 17, keep the try-catch block, but use std::locale:global(std::locale(""));
try
{
std::locale::global(boost::locale::generator().generate(""));
// Make boost.filesystem use it
boost::filesystem::path::imbue(std::locale());
}
catch(const std::runtime_error& err)
{
std::cout << "Warning: " << err.what() << std::endl;
}

int result = 0;

Expand Down