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

Marco Zocca zocca.marco at gmail.com
Thu May 14 15:55:11 CDT 2015


The host language is Haskell; so far I've managed to wrap Petsc
structures made up of elementary types and with no macros inside (e.g.
_n_PetscLayout ), and Petsc functions that operate on typedefs of
elementary types (e.g. PetscInitialize() ).
_p_Vec and similar are proving harder to implement. (Haskell requires
one to write instances of a certain typeclass Storable,  that add
pointer-like functionality to the instanced datatypes)
On the other hand, I cannot treat Vec, Mat etc. simply as a opaque
pointers because Petsc uses them both by value and by reference.



On 14 May 2015 at 22:26, Jed Brown <jed at jedbrown.org> wrote:
> Marco Zocca <zocca.marco at gmail.com> writes:
>
>> 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?
>
> It's expanded by the C Preprocessor.  But why are you looking at this?
> Those are private headers not even available to C callers.  Why do you
> feel compelled to access these from a different language?



More information about the petsc-dev mailing list