[petsc-dev] CHKERRXX() to propagate errors from C

Jed Brown jedbrown at mcs.anl.gov
Wed Oct 19 14:39:30 CDT 2011


#define CHKERRXX(n)            do {if (PetscUnlikely(n))
{PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_IN_CXX,0);}}
while(0)

Inside PetscError():

  if (p == PETSC_ERROR_IN_CXX) {
    const char *str;
    if (eh->ctx) {
      std::ostringstream *msg;
      msg = (std::ostringstream*) eh->ctx;
      str = msg->str().c_str();
    } else {
      str = "Error detected in C PETSc";
    }
    throw PETSc::Exception(str);
  }

This causes SEGV because eh is NULL when propagating an error from C (the
caller checks a return code using CHKERRXX). This seems like a logic error,
but I don't know what was intended.

I changed this to if (eh && eh->ctx) which fixes the SEGV, but I don't know
if something else was intended. I only pushed this to petsc-dev, but once we
decide on the "right" fix, it should be ported to petsc-3.2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20111019/dbdc13cb/attachment.html>


More information about the petsc-dev mailing list