Actual source code: demangle.cxx

  1: #if !defined(PETSC_SKIP_COMPLEX)
  2:   #define PETSC_SKIP_COMPLEX
  3: #endif
  4: #include <petscsys.h>
  5: #include <petsc/private/petscimpl.h>

  7: #if defined(PETSC_HAVE_CXXABI_H)
  8:   #include <cxxabi.h>
  9: #endif

 11: PetscErrorCode PetscDemangleSymbol(const char mangledName[], char **name)
 12: {
 13:   PetscFunctionBegin;
 14:   if (mangledName) PetscAssertPointer(mangledName, 1);
 15:   PetscAssertPointer(name, 2);

 17:   *name = nullptr;
 18:   if (!mangledName) PetscFunctionReturn(PETSC_SUCCESS);
 19: #if defined(PETSC_HAVE_CXXABI_H)
 20:   char *newname;
 21:   int   status;

 23:   newname = __cxxabiv1::__cxa_demangle(mangledName, nullptr, nullptr, &status);
 24:   if (status) {
 25:     PetscCheck(status != -1, PETSC_COMM_SELF, PETSC_ERR_MEM, "Failed to allocate memory for symbol %s", mangledName);
 26:     PetscCheck(status == -2, PETSC_COMM_SELF, PETSC_ERR_LIB, "Demangling failed for symbol %s", mangledName);
 27:     /* Mangled name is not a valid name under the C++ ABI mangling rules */
 28:     PetscCall(PetscStrallocpy(mangledName, name));
 29:     PetscFunctionReturn(PETSC_SUCCESS);
 30:   }
 31:   PetscCall(PetscStrallocpy(newname, name));
 32:   free(newname);
 33: #else
 34:   PetscCall(PetscStrallocpy(mangledName, name));
 35: #endif
 36:   PetscFunctionReturn(PETSC_SUCCESS);
 37: }