[petsc-dev] Why do we use void* instead of PetscObject in PETSc?

Jed Brown jed at jedbrown.org
Mon Mar 4 15:47:19 CST 2019


Dave May <dave.mayhem23 at gmail.com> writes:

> On Mon, 4 Mar 2019 at 21:30, Jed Brown <jed at jedbrown.org> wrote:
>
>> If reusing, would the interface require
>> casting the function pointers to void(*)(void) instead of what is
>> currently type-safe for most function pointers?
>
>
> No. I don't see that casting a function pointer would be required.
> We would have
>
> SNESSetJacobian(SNES snes,Mat Amat,Mat Pmat,PetscErrorCode
> (*J)(SNES,Vec,Mat,Mat,PetscObject),PetscObject ctx)

Oh, the PetscObject would only contain the context, not the function
pointer (at least not publicly).  What does user code look like?

  PetscErrorCode f(..., PetscObject ctx) {
    User user;
    ierr = PetscContainerGetPointer((PetscContainer)ctx,&user);CHKERRQ(ierr);
    ...
  }


More information about the petsc-dev mailing list