/* * Demangle.cc * * Created on: Nov 16, 2012 * Author: f.casimir */ #include "Demangle.hh" namespace AMDA { namespace Helpers { // KeithB's solution is good, but has one serious flaw in that unless buf is static // it'll get trashed from the stack before it is returned in res - and will point who-knows-where // Here's that problem fixed, but the code is still non-re-entrant and not thread-safe. // Anyone care to improve it? #include const char* Demangle(const char* name) { static char buf[1024]; size_t size = sizeof(buf); int status; char* res = abi::__cxa_demangle (name, buf, &size, &status); buf[sizeof(buf) - 1] = 0; // I'd hope __cxa_demangle does this when the name is huge, but just in case. return res; } } /* namespace Helpers */ } /* namespace AMDA */