<div dir="ltr">On Wed, Feb 6, 2013 at 10:07 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
<br>
While I'm busy converting macro functions to C functions, others (unnamed, but Jed knows how to find them using the revision control system) are adding new ones like there is no tomorrow.<br>
<br>
For example below.<br>
<br>
Yes CPP is unfairly useful and some of the uses below do pass types that cannot trivially be handled with pure C code, please try to restrict your love of CPP to only when absolutely necessary; for example the first one below doesn't need to be a macro I think.<br>
</blockquote><div><br></div><div style>The first example below was added by Barry in 2008 and can soon be deleted.</div><div style><br></div><div style><a href="https://bitbucket.org/petsc/petsc-dev/commits/2c4d80a83ccb656c1ab09c5dcec9c685c121655f">https://bitbucket.org/petsc/petsc-dev/commits/2c4d80a83ccb656c1ab09c5dcec9c685c121655f</a></div>
<div style><br></div><div style>The second is like PetscTryMethod in that it really needs to be a macro.</div><div style> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Barry<br>
<br>
/*<br>
Allocates enough space to store Fortran function pointers in PETSc object<br>
that are needed by the Fortran interface.<br>
*/<br>
#define PetscObjectAllocateFortranPointers(obj,N) do { \<br>
if (!((PetscObject)(obj))->fortran_func_pointers) { \<br>
*ierr = PetscMalloc((N)*sizeof(void(*)(void)),&((PetscObject)(obj))->fortran_func_pointers);if (*ierr) return; \<br>
*ierr = PetscMemzero(((PetscObject)(obj))->fortran_func_pointers,(N)*sizeof(void(*)(void)));if (*ierr) return; \<br>
((PetscObject)obj)->num_fortran_func_pointers = (N); \<br>
} \<br>
} while (0)<br>
<br>
/* Entire function body, _ctx is a "special" variable that can be passed along */<br>
#define PetscObjectUseFortranCallback_Private(obj,cid,types,args,cbclass) { \<br>
PetscErrorCode ierr; \<br>
void (PETSC_STDCALL *func) types,*_ctx; \<br>
PetscFunctionBegin; \<br>
ierr = PetscObjectGetFortranCallback((PetscObject)(obj),(cbclass),(cid),(PetscVoidFunction*)&func,&_ctx);CHKERRQ(ierr); \<br>
(*func)args;CHKERRQ(ierr); \<br>
PetscFunctionReturn(0); \<br>
}<br>
#define PetscObjectUseFortranCallback(obj,cid,types,args) PetscObjectUseFortranCallback_Private(obj,cid,types,args,PETSC_FORTRAN_CALLBACK_CLASS)<br>
#define PetscObjectUseFortranCallbackSubType(obj,cid,types,args) PetscObjectUseFortranCallback_Private(obj,cid,types,args,PETSC_FORTRAN_CALLBACK_SUBTYPE)<br>
<br>
</blockquote></div><br></div></div>