Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef HAVE_CXA_DEMANGLE
- const char* demangle(const char* name)
- {
- char buf[1024];
- unsigned int size=1024;
- int status;
- char* res = abi::__cxa_demangle (name,
- buf,
- &size,
- &status);
- return res;
- }
- #else
- const char* demangle(const char* name)
- {
- return name;
- }
- #endif
- __FUNCTION__
- __FILE__
- __LINE__
- e.g.:
- log(__FILE__, __LINE__, __FUNCTION__, mymessage);
- const string demangle(const char* name) {
- int status = -4;
- char* res = abi::__cxa_demangle(name, NULL, NULL, &status);
- const char* const demangled_name = (status==0)?res:name;
- string ret_val(demangled_name);
- free(res);
- return ret_val;
- }
- virtual bool mutex::do_unlock()
- // 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 <cxxabi.h>
- // todo: javadoc this properly
- const char* demangle(const char* name)
- {
- static char buf[1024];
- size_t size = sizeof(buf);
- int status;
- // todo:
- 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;
- }
Add Comment
Please, Sign In to add comment