Skip to content

Commit

Permalink
Only use GNU cxxabi demangler for debug printing
Browse files Browse the repository at this point in the history
Unfortunately, the cxxabi demangler utility causes an error in
the serialization code. Until that is resolved (see also issue #811)
use the normal typeid string for serialization and cxxabi
for debug printing.
  • Loading branch information
biddisco committed Oct 10, 2018
1 parent e7f4f5e commit d4c022d
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions hpx/util/debug/demangle_helper.hpp
Expand Up @@ -10,25 +10,42 @@
#include <hpx/config.hpp>
#include <string>
#include <type_traits>
#include <typeinfo>

// --------------------------------------------------------------------
// Always present regardless of compiler : used by serialization code
// --------------------------------------------------------------------
namespace hpx { namespace util { namespace debug
{
template <typename T>
struct demangle_helper
{
char const* type_id() const
{
return typeid(T).name();
}
};
}}}

#if defined(__GNUG__)

#if defined(__GNUC__)
#include <cxxabi.h>
#include <stdlib.h>

// --------------------------------------------------------------------
// if available : demangle an arbitrary c++ type using gnu utility
// --------------------------------------------------------------------
namespace hpx { namespace util { namespace debug
{
// --------------------------------------------------------------------
// demangle an arbitrary c++ type using gnu utility
// --------------------------------------------------------------------
template <typename T>
class demangle_helper
class cxxabi_demangle_helper
{
public:
demangle_helper()
cxxabi_demangle_helper()
: demangled_(abi::__cxa_demangle(typeid(T).name(), 0, 0, 0))
{}

~demangle_helper()
~cxxabi_demangle_helper()
{
free(demangled_);
}
Expand All @@ -46,18 +63,10 @@ namespace hpx { namespace util { namespace debug

#else

#include <typeinfo>

namespace hpx { namespace util { namespace debug
{
template <typename T>
struct demangle_helper
{
char const* type_id() const
{
return typeid(T).name();
}
};
using cxxabi_demangle_helper = demangle_helper<T>;
}}}

#endif
Expand All @@ -74,6 +83,20 @@ namespace hpx { namespace util { namespace debug
template <typename T>
demangle_helper<T> type_id<T>::typeid_ = demangle_helper<T>();

#if defined(__GNUG__)
template <typename T>
struct cxx_type_id
{
static cxxabi_demangle_helper<T> typeid_;
};

template <typename T>
cxxabi_demangle_helper<T> cxx_type_id<T>::typeid_ = cxxabi_demangle_helper<T>();
#else
template <typename T>
using cxx_type_id = type_id<T>;
#endif

// --------------------------------------------------------------------
// print type information
// usage : std::cout << print_type<args...>("separator")
Expand All @@ -82,7 +105,7 @@ namespace hpx { namespace util { namespace debug
template <typename T=void>
inline std::string print_type(const char *delim="")
{
return std::string(hpx::util::debug::type_id<T>::typeid_.type_id());
return std::string(cxx_type_id<T>::typeid_.type_id());
}

template <>
Expand All @@ -95,7 +118,7 @@ namespace hpx { namespace util { namespace debug
inline typename std::enable_if<sizeof...(Args)!=0, std::string>::type
print_type(const char *delim="")
{
std::string temp(hpx::util::debug::type_id<T>::typeid_.type_id());
std::string temp(cxx_type_id<T>::typeid_.type_id());
return temp + delim + print_type<Args...>(delim);
}
}}}
Expand Down

0 comments on commit d4c022d

Please sign in to comment.