Actual source code: demangle.cxx
1: #if !defined(PETSC_SKIP_COMPLEX)
2: #define PETSC_SKIP_COMPLEX
3: #endif
4: #include <petscsys.h>
6: #if defined(PETSC_HAVE_CXXABI_H)
7: #include <cxxabi.h>
8: #endif
10: PetscErrorCode PetscDemangleSymbol(const char mangledName[], char **name)
11: {
12: PetscFunctionBegin;
13: #if defined(PETSC_HAVE_CXXABI_H)
14: char *newname;
15: int status;
17: newname = __cxxabiv1::__cxa_demangle(mangledName, NULL, NULL, &status);
18: if (status) {
19: PetscCheck(status != -1, PETSC_COMM_SELF, PETSC_ERR_MEM, "Failed to allocate memory for symbol %s", mangledName);
20: PetscCheck(status == -2, PETSC_ERR_LIB, "Demangling failed for symbol %s", mangledName);
21: /* Mangled name is not a valid name under the C++ ABI mangling rules */
22: PetscCall(PetscStrallocpy(mangledName, name));
23: PetscFunctionReturn(PETSC_SUCCESS);
24: }
25: PetscCall(PetscStrallocpy(newname, name));
26: free(newname);
27: #else
28: PetscCall(PetscStrallocpy(mangledName, name));
29: #endif
30: PetscFunctionReturn(PETSC_SUCCESS);
31: }