[cffi-devel] Converting foreign structures with CFFI generic functions

Liam Healy lnp at healy.washington.dc.us
Fri Sep 9 13:27:29 UTC 2011


On Fri, Sep 9, 2011 at 2:50 AM, Jean-Claude Beaudoin
<jean.claude.beaudoin at gmail.com> wrote:
>
> Has anyone of you given a look at what Franz did on this very subject for
> their Allegro 8.2
> (http://www.franz.com/support/documentation/8.2/doc/contents.htm#foreign-functions)
> (http://www.franz.com/support/documentation/8.2/doc/foreign-functions.htm#structs-by-value-1)
> They added a keyword argument to their def-foreign-call form and also added
> a global variable ff:*pass-structs-by-value* that controls the default value
> of the keyword arg.
>
> What do you think of that?
>
> Cheers,
>
> Jean-Claude Beaudoin
>

I like their approach, and I think we should follow a similar path
with the argument passing determined by declaration (:pointer for call
by reference and the stucture type name for call by value), but I
would be a little stronger on the default behavior.  I would make an
"notification-interpretation" global variable that determines what the
compiler will do (notification and possible conversion) if it
encounters a structure name declaration to a function argument or
return.   Options could be (:warn :pointer), (:error), (:accept
:pointer), (:accept :value), etc., :value meaning call by value and
:pointer meaning call by reference.  The current CFFI has (:accept
:pointer).  The default on release could be (:warn :pointer) if FSBV
is not loaded, and (:warn :value) if it is.  After a while (succeeding
release, say), we should change this to (:warn :pointer) and (:accept
:value), respectively.  Ultimately, I think it should be (:error) and
(:accept :value) respectively.

Liam




More information about the cffi-devel mailing list