Re-implemented type name demangling.

The new implementation does not depend on Boost.Units and is fully contained in Boost.Exception.
This commit is contained in:
Andrey Semashev
2014-05-31 21:54:52 +04:00
parent b2221bf92d
commit 7062572c8f
3 changed files with 42 additions and 13 deletions

View File

@ -21,9 +21,9 @@
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception/detail/type_info.hpp>
#include <boost/exception/detail/clone_current_exception.hpp>
//#ifndef BOOST_NO_RTTI
//#include <boost/units/detail/utility.hpp>
//#endif
#ifndef BOOST_NO_RTTI
#include <boost/exception/detail/type_info.hpp> // exception_detail::demangle
#endif
#include <boost/shared_ptr.hpp>
#include <stdexcept>
#include <new>
@ -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

View File

@ -15,14 +15,43 @@
#include <boost/detail/sp_typeinfo.hpp>
#include <boost/current_function.hpp>
#include <boost/config.hpp>
//#ifndef BOOST_NO_TYPEID
//#include <boost/units/detail/utility.hpp>
//#endif
#include <string>
#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
#include <cxxabi.h>
#include <stdlib.h>
#include <stddef.h>
#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 <class T>
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
}