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:     if (status == -2) {
     21:       /* Mangled name is not a valid name under the C++ ABI mangling rules */
     22:       PetscCall(PetscStrallocpy(mangledName, name));
     23:       PetscFunctionReturn(PETSC_SUCCESS);
     24:     } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Demangling failed for symbol %s", mangledName);
     25:   }
     26:   PetscCall(PetscStrallocpy(newname, name));
     27:   free(newname);
     28: #else
     29:   PetscCall(PetscStrallocpy(mangledName, name));
     30: #endif
     31:   PetscFunctionReturn(PETSC_SUCCESS);
     32: }