Bugzilla – Attachment #383: Demangling for bug #507
ATTRIBUTE_CHECKER_IMPLEMENT (Callback);
// Demangling calls based on __cxa_demangle - Author: Timo Bingmann, 2009
#if (__GNUC__ >= 3)
#include <cxxabi.h>
#include "log.h"
std::string
CallbackBase::Demangle(const std::string& mangled)
{
int status;
char* demangled = abi::__cxa_demangle(mangled.c_str(),
NULL, NULL, &status);
std::string ret;
if (status == 0) {
NS_ASSERT(demangled);
ret = demangled;
}
else if (status == -1) {
NS_LOG_UNCOND("Callback demangling failed: Memory allocation failure occured.");
ret = mangled;
else if (status == -2) {
NS_LOG_UNCOND("Callback demangling failed: Mangled name is not a valid under the C++ ABI mangling rules.");
else if (status == -3) {
NS_LOG_UNCOND("Callback demangling failed: One of the arguments is invalid.");
else {
NS_LOG_UNCOND("Callback demangling failed: status " << status);
if (demangled) {
free(demangled);
return ret;
#else
return mangled;
#endif
// End of demangling
} // namespace ns3
protected:
CallbackBase (Ptr<CallbackImplBase> impl) : m_impl (impl) {}
Ptr<CallbackImplBase> m_impl;
static std::string Demangle(const std::string& mangled);
};
/**
void DoAssign (Ptr<const CallbackImplBase> other) {
if (!DoCheckType (other))
NS_FATAL_ERROR ("Incompatible types. (feed to \"c++filt -t\")"
NS_FATAL_ERROR ("Incompatible types. (feed to \"c++filt -t\" if needed)" << std::endl <<
" got=" << typeid (*other).name () <<
"got=" << Demangle ( typeid (*other).name () ) << std::endl <<
", expected=" << typeid (CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> *).name ());
"expected=" << Demangle ( typeid (CallbackImpl<R,T1,T2,T3,T4,T5,T6,T7,T8,T9> *).name () ));
m_impl = const_cast<CallbackImplBase *> (PeekPointer (other));