Blame view

src/Parameters/Demangle.cc 921 Bytes
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
/*
 * Demangle.cc
 *
 *  Created on: Nov 16, 2012
 *      Author: f.casimir
 */
46ca92d0   Elena.Budnik   add / move header...
7
#include <cxxabi.h>
fbe3c2bb   Benjamin Renard   First commit
8
9
10
11
12
13
14
15
16
17
#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?

fbe3c2bb   Benjamin Renard   First commit
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 */