Merge pull request #1 from Lastique/develop

Re-enable type name demangling (thanks Lastique)
This commit is contained in:
zajo
2014-06-04 23:29:56 -07:00
3 changed files with 42 additions and 13 deletions

View File

@ -21,9 +21,9 @@
#include <boost/exception/diagnostic_information.hpp> #include <boost/exception/diagnostic_information.hpp>
#include <boost/exception/detail/type_info.hpp> #include <boost/exception/detail/type_info.hpp>
#include <boost/exception/detail/clone_current_exception.hpp> #include <boost/exception/detail/clone_current_exception.hpp>
//#ifndef BOOST_NO_RTTI #ifndef BOOST_NO_RTTI
//#include <boost/units/detail/utility.hpp> #include <boost/exception/detail/type_info.hpp> // exception_detail::demangle()
//#endif #endif
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <stdexcept> #include <stdexcept>
#include <new> #include <new>
@ -92,7 +92,7 @@ boost
std::string std::string
to_string( original_exception_type const & x ) to_string( original_exception_type const & x )
{ {
return /*units::detail::demangle*/(x.value()->name()); return exception_detail::demangle(x.value()->name());
} }
#endif #endif

View File

@ -15,14 +15,43 @@
#include <boost/detail/sp_typeinfo.hpp> #include <boost/detail/sp_typeinfo.hpp>
#include <boost/current_function.hpp> #include <boost/current_function.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
//#ifndef BOOST_NO_TYPEID
//#include <boost/units/detail/utility.hpp>
//#endif
#include <string> #include <string>
#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
#include <cxxabi.h>
#include <stdlib.h>
#include <stddef.h>
#define BOOST_EXCEPTION_HAS_CXXABI_H
#endif
namespace namespace
boost boost
{ {
namespace
exception_detail
{
inline
std::string
demangle(const char* name)
{
#ifdef BOOST_EXCEPTION_HAS_CXXABI_H
struct auto_free
{
explicit auto_free(char* ptr) : p(ptr) {}
~auto_free() { free(p); }
char* p;
};
int status = 0;
size_t size = 0;
auto_free demangled(abi::__cxa_demangle(name, NULL, &size, &status));
if (demangled.p)
return demangled.p;
#endif
return name;
}
}
template <class T> template <class T>
inline inline
std::string std::string
@ -31,7 +60,7 @@ boost
#ifdef BOOST_NO_TYPEID #ifdef BOOST_NO_TYPEID
return BOOST_CURRENT_FUNCTION; return BOOST_CURRENT_FUNCTION;
#else #else
return /*units::detail::demangle*/(typeid(T*).name()); return exception_detail::demangle(typeid(T*).name());
#endif #endif
} }
@ -43,7 +72,7 @@ boost
#ifdef BOOST_NO_TYPEID #ifdef BOOST_NO_TYPEID
return BOOST_CURRENT_FUNCTION; return BOOST_CURRENT_FUNCTION;
#else #else
return /*units::detail::demangle*/(typeid(T).name()); return exception_detail::demangle(typeid(T).name());
#endif #endif
} }

View File

@ -16,9 +16,9 @@
#include <boost/exception/get_error_info.hpp> #include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp> #include <boost/exception/info.hpp>
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>
//#ifndef BOOST_NO_RTTI #ifndef BOOST_NO_RTTI
//#include <boost/units/detail/utility.hpp> #include <boost/exception/detail/type_info.hpp> // exception_detail::demangle()
//#endif #endif
#include <exception> #include <exception>
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -151,7 +151,7 @@ boost
#ifndef BOOST_NO_RTTI #ifndef BOOST_NO_RTTI
if ( verbose ) if ( verbose )
tmp << std::string("Dynamic exception type: ") << tmp << std::string("Dynamic exception type: ") <<
/*units::detail::demangle*/((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n'; exception_detail::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n';
#endif #endif
if( with_what && se && verbose ) if( with_what && se && verbose )
tmp << "std::exception::what: " << wh << '\n'; tmp << "std::exception::what: " << wh << '\n';