<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br><div><div>  #define PetscStackPop_Private(stack__, func__) \</div><div>    do { \</div><div>      PetscCheckAbort(!stack__.check || stack__.currentsize > 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid stack size %d, pop %s %s:%d.\n", stack__.currentsize, func__, __FILE__, __LINE__); \</div><div>      if (--stack__.currentsize < PETSCSTACKSIZE) { \</div><div>        PetscCheckAbort(!stack__.check || stack__.petscroutine[stack__.currentsize] != 1 || stack__.function[stack__.currentsize] == (const char *)(func__), PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid stack: push from %s %s:%d. Pop from %s %s:%d.\n", \</div><div>                        stack__.function[stack__.currentsize], stack__.file[stack__.currentsize], stack__.line[stack__.currentsize], func__, __FILE__, __LINE__); \</div><div><br></div><div><br></div><div>  It is checking on each pop (return) that the current function it is in is the same function that the begin was called in. </div><div><br></div><div>  You do not have to call through PetscCall() to have this stuff work (though we strong recommend adding them).</div><div><br></div><div>  Even if you have a return and no outstanding begins it should not crash</div><div><br></div><div>  Maybe you need to see a couple of crashes so we try to figure out what is going on.</div><div><br></div><div><br></div><blockquote type="cite"><div>On Jul 11, 2023, at 11:29 PM, Aagaard, Brad T via petsc-users <petsc-users@mcs.anl.gov> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">PETSc developers,<o:p></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">When I fail to have matching PetscFunctionBeginUser() and PetscFunctionReturn() in my code, I get segfaults and valgrind reports invalid writes at places in PETSc where memory is freed. As a result, it is difficult to track down the actual source of the error. I know there used to be a command line argument for checking for mismatches in PetscFunctionBeginUser() and PetscFunctionReturn(), but Matt said it is no longer implemented and the reporting is supposed to be automatic when debugging is turned on. This automatic reporting does not seem to be working for me.<o:p></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">Is there a test in PETSc of this automatic reporting that I can run to verify it works in my build?<o:p></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">Are there any additional requirements for this automatic reporting of mismatched PetscFunctionBeginUser() and PetscFunctionReturn() in my code? Must I wrap all PETSc function calls with PetscCall()?<o:p></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">Thanks,<o:p></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;">Brad</div></div></div></blockquote></div><br></body></html>