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

Luís Oliveira luismbo at gmail.com
Sat Aug 27 20:10:08 UTC 2011


On Sat, Aug 27, 2011 at 7:39 PM, Liam Healy <lhealy at common-lisp.net> wrote:
>> What kind of translation do you need these methods to do on
>> FOREIGN-STRUCT-TYPE?
>>
> They should take the lisp object, allocate the foreign structure, then
> define the slots correctly (recursively if necessary), and return the
> pointer.  For the return pointer, they should read the contents and generate
> the lisp equivalent.  I suppose the calls to libffi functions should invoke
> translate-*-foreign just like it now invokes the functions on the properties
> fsbv::foreign-object-components and fsbv::setf-foreign-object-components.

That seems to fit the translation-*-foreign pretty well. Moreover, it
seems like there should be no default conversion, i.e., you could pass
structures by value using the same code you currently use for passing
structures by reference:

  (with-foreign-object (foo 'some-struct-type)
    (bar foo))

The only difference is that BAR's first argument would be defined to
be a structure argument passed by value. It's a bit subtle. Not sure
how sensible it would be. An alternative would be represent structure
values (as opposed to structure pointers) using some kind of wrapper
object. Any thoughts?

-- 
Luís Oliveira
http://r42.eu/~luis/




More information about the cffi-devel mailing list