From 7062572c8f38c7b15181bd352d5f606091d31317 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 31 May 2014 21:54:52 +0400 Subject: [PATCH 1/4] Re-implemented type name demangling. The new implementation does not depend on Boost.Units and is fully contained in Boost.Exception. --- .../boost/exception/detail/exception_ptr.hpp | 8 ++-- include/boost/exception/detail/type_info.hpp | 39 ++++++++++++++++--- .../exception/diagnostic_information.hpp | 8 ++-- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/include/boost/exception/detail/exception_ptr.hpp b/include/boost/exception/detail/exception_ptr.hpp index a15bfc4..f9329a0 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 6e5942d..a66c747 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 2f5cb88..181822a 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'; From 8f097eb241169082bb85b6e89670d55a2a62bb37 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 31 May 2014 21:57:51 +0400 Subject: [PATCH 2/4] Comment fix. --- include/boost/exception/detail/exception_ptr.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/exception/detail/exception_ptr.hpp b/include/boost/exception/detail/exception_ptr.hpp index f9329a0..c57c38e 100644 --- a/include/boost/exception/detail/exception_ptr.hpp +++ b/include/boost/exception/detail/exception_ptr.hpp @@ -22,7 +22,7 @@ #include #include #ifndef BOOST_NO_RTTI -#include // exception_detail::demangle +#include // exception_detail::demangle() #endif #include #include From a129725e3e6c5a7de3de93a77f726dff6c0cab5f Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 5 Jun 2014 00:50:04 +0400 Subject: [PATCH 3/4] Switched from BOOST_ATTRIBUTE_NORETURN to BOOST_NORETURN. --- include/boost/exception/detail/exception_ptr.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/exception/detail/exception_ptr.hpp b/include/boost/exception/detail/exception_ptr.hpp index c57c38e..9bbcc73 100644 --- a/include/boost/exception/detail/exception_ptr.hpp +++ b/include/boost/exception/detail/exception_ptr.hpp @@ -34,7 +34,7 @@ namespace boost { class exception_ptr; - BOOST_ATTRIBUTE_NORETURN void rethrow_exception( exception_ptr const & ); + BOOST_NORETURN void rethrow_exception( exception_ptr const & ); exception_ptr current_exception(); class @@ -454,7 +454,7 @@ boost return ret; } - BOOST_ATTRIBUTE_NORETURN + BOOST_NORETURN inline void rethrow_exception( exception_ptr const & p ) From 5dea76a30133f6111331b7f76ff6bae713d63c82 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 11 Jun 2014 22:02:59 +0400 Subject: [PATCH 4/4] Port to Boost.Core demangle() and typeinfo. --- .../boost/exception/detail/exception_ptr.hpp | 4 +- include/boost/exception/detail/type_info.hpp | 45 +++---------------- .../exception/diagnostic_information.hpp | 4 +- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/include/boost/exception/detail/exception_ptr.hpp b/include/boost/exception/detail/exception_ptr.hpp index 5605ca0..cac64e6 100644 --- a/include/boost/exception/detail/exception_ptr.hpp +++ b/include/boost/exception/detail/exception_ptr.hpp @@ -22,7 +22,7 @@ #include #include #ifndef BOOST_NO_RTTI -#include // exception_detail::demangle() +#include #endif #include #include @@ -92,7 +92,7 @@ boost std::string to_string( original_exception_type const & x ) { - return exception_detail::demangle(x.value()->name()); + return core::demangle(x.value()->name()); } #endif diff --git a/include/boost/exception/detail/type_info.hpp b/include/boost/exception/detail/type_info.hpp index d82e22f..b8c7d48 100644 --- a/include/boost/exception/detail/type_info.hpp +++ b/include/boost/exception/detail/type_info.hpp @@ -12,46 +12,15 @@ #pragma warning(push,1) #endif -#include +#include +#include #include #include #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 @@ -60,7 +29,7 @@ boost #ifdef BOOST_NO_TYPEID return BOOST_CURRENT_FUNCTION; #else - return exception_detail::demangle(typeid(T*).name()); + return core::demangle(typeid(T*).name()); #endif } @@ -72,7 +41,7 @@ boost #ifdef BOOST_NO_TYPEID return BOOST_CURRENT_FUNCTION; #else - return exception_detail::demangle(typeid(T).name()); + return core::demangle(typeid(T).name()); #endif } @@ -82,10 +51,10 @@ boost struct type_info_ { - detail::sp_typeinfo const * type_; + core::typeinfo const * type_; explicit - type_info_( detail::sp_typeinfo const & type ): + type_info_( core::typeinfo const & type ): type_(&type) { } @@ -100,7 +69,7 @@ boost } } -#define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::exception_detail::type_info_(BOOST_SP_TYPEID(T)) +#define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::exception_detail::type_info_(BOOST_CORE_TYPEID(T)) #ifndef BOOST_NO_RTTI #define BOOST_EXCEPTION_DYNAMIC_TYPEID(x) ::boost::exception_detail::type_info_(typeid(x)) diff --git a/include/boost/exception/diagnostic_information.hpp b/include/boost/exception/diagnostic_information.hpp index 0d2cfc2..305e8ed 100644 --- a/include/boost/exception/diagnostic_information.hpp +++ b/include/boost/exception/diagnostic_information.hpp @@ -17,7 +17,7 @@ #include #include #ifndef BOOST_NO_RTTI -#include // exception_detail::demangle() +#include #endif #include #include @@ -151,7 +151,7 @@ boost #ifndef BOOST_NO_RTTI if ( verbose ) tmp << std::string("Dynamic exception type: ") << - exception_detail::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n'; + core::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';