Fix wml_exception getting thrown.

This commit is contained in:
Pentarctagon 2022-08-03 10:00:46 -05:00 committed by Pentarctagon
parent 1c0a41100b
commit a6fedd1847
4 changed files with 49 additions and 27 deletions

View file

@ -32,3 +32,4 @@ serialization/unicode.cpp
serialization/validator.cpp
server/common/simple_wml.cpp
tstring.cpp
utils/general.cpp

View file

@ -52,6 +52,7 @@ struct mp_connect_fixture {
hotkey_manager(),
config_manager()
{
test_utils::get_fake_display(1000, 500);
config_manager.reset(new game_config_manager(cmdline_opts));
config_manager->init_game_config(game_config_manager::NO_FORCE_RELOAD);

43
src/utils/general.cpp Normal file
View file

@ -0,0 +1,43 @@
/*
Copyright (C) 2003 - 2022
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "utils/general.hpp"
#if defined(__clang__) || defined(__GNUG__)
#include <cxxabi.h>
#endif
namespace utils
{
std::string get_unknown_exception_type()
{
#if defined(__clang__) || defined(__GNUG__)
std::string to_demangle = __cxxabiv1::__cxa_current_exception_type()->name();
int status = 0;
char* buff = __cxxabiv1::__cxa_demangle(to_demangle.c_str(), NULL, NULL, &status);
if(status == 0)
{
std::string demangled = buff;
std::free(buff);
return demangled;
}
else
{
return to_demangle;
}
#else
return "";
#endif
}
}

View file

@ -19,10 +19,6 @@
#include <functional>
#include <string>
#if defined(__clang__) || defined(__GNUG__)
#include <cxxabi.h>
#endif
namespace utils
{
inline bool chars_equal_insensitive(char a, char b) { return tolower(a) == tolower(b); }
@ -91,30 +87,11 @@ inline bool contains(const Container& container, const Value& value)
}
/**
* For the GCC/clang compilers, return the unmangled name of an unknown exception that was caught.
* Meaning something caught with `catch(...)`.
* Utility function for finding the type of thing caught with `catch(...)`.
* Not implemented for other compilers at this time.
*
* @return std::string
* @return For the GCC/clang compilers, the unmangled name of an unknown exception that was caught.
*/
inline std::string get_unknown_exception_type()
{
#if defined(__clang__) || defined(__GNUG__)
std::string to_demangle = __cxxabiv1::__cxa_current_exception_type()->name();
int status = 0;
char* buff = __cxxabiv1::__cxa_demangle(to_demangle.c_str(), NULL, NULL, &status);
if(status == 0)
{
std::string demangled = buff;
std::free(buff);
return demangled;
}
else
{
return to_demangle;
}
#else
return "";
#endif
}
std::string get_unknown_exception_type();
} // namespace utils