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