[petsc-dev] FFI-wrapping PETSc structs that contain macros

Marco Zocca zocca.marco at gmail.com
Thu May 14 13:45:13 CDT 2015


Dear all,

I am trying to write a petsc foreign-function wrapper for a different language.
What I don't understand at the moment is the role of macros in setting
up structs. For example, in the implementation of Vec summarised
below, when and how is PETSCHEADER expanded?
What's the scope and purpose of hdr and ops ?

Thank you in advance

________________________________

### petscvec.h

typedef struct _p_Vec* Vec;

### petscimpl.h

#define PETSCHEADER(ObjectOps) \
  _p_PetscObject hdr;          \
  ObjectOps      *ops

### vecimpl.h

struct _p_Vec {
  PETSCHEADER(struct _VecOps);
  PetscLayout            map;
  void                   *data;     /* implementation-specific data */
  ...

typedef struct _VecOps *VecOps;
struct _VecOps {
  PetscErrorCode (*duplicate)(Vec,Vec*);         /* get single vector */
  PetscErrorCode (*duplicatevecs)(Vec,PetscInt,Vec**);     /* get
array of vectors */
...



More information about the petsc-dev mailing list