diff --git a/include/boost/exception/detail/exception_ptr.hpp b/include/boost/exception/detail/exception_ptr.hpp index 530a6bd..5605ca0 100644 --- a/include/boost/exception/detail/exception_ptr.hpp +++ b/include/boost/exception/detail/exception_ptr.hpp @@ -21,9 +21,9 @@ #include #include #include -//#ifndef BOOST_NO_RTTI -//#include -//#endif +#ifndef BOOST_NO_RTTI +#include // exception_detail::demangle() +#endif #include #include #include @@ -92,7 +92,7 @@ boost std::string to_string( original_exception_type const & x ) { - return /*units::detail::demangle*/(x.value()->name()); + return exception_detail::demangle(x.value()->name()); } #endif diff --git a/include/boost/exception/detail/type_info.hpp b/include/boost/exception/detail/type_info.hpp index 0af8ef5..d82e22f 100644 --- a/include/boost/exception/detail/type_info.hpp +++ b/include/boost/exception/detail/type_info.hpp @@ -15,14 +15,43 @@ #include #include #include -//#ifndef BOOST_NO_TYPEID -//#include -//#endif #include +#if defined(__GLIBCXX__) || defined(__GLIBCPP__) +#include +#include +#include +#define BOOST_EXCEPTION_HAS_CXXABI_H +#endif namespace 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 inline std::string @@ -31,7 +60,7 @@ boost #ifdef BOOST_NO_TYPEID return BOOST_CURRENT_FUNCTION; #else - return /*units::detail::demangle*/(typeid(T*).name()); + return exception_detail::demangle(typeid(T*).name()); #endif } @@ -43,7 +72,7 @@ boost #ifdef BOOST_NO_TYPEID return BOOST_CURRENT_FUNCTION; #else - return /*units::detail::demangle*/(typeid(T).name()); + return exception_detail::demangle(typeid(T).name()); #endif } diff --git a/include/boost/exception/diagnostic_information.hpp b/include/boost/exception/diagnostic_information.hpp index 7889c8f..0d2cfc2 100644 --- a/include/boost/exception/diagnostic_information.hpp +++ b/include/boost/exception/diagnostic_information.hpp @@ -16,9 +16,9 @@ #include #include #include -//#ifndef BOOST_NO_RTTI -//#include -//#endif +#ifndef BOOST_NO_RTTI +#include // exception_detail::demangle() +#endif #include #include #include @@ -151,7 +151,7 @@ boost #ifndef BOOST_NO_RTTI if ( verbose ) 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 if( with_what && se && verbose ) tmp << "std::exception::what: " << wh << '\n';