[cffi-devel] Converting foreign structures with CFFI generic functions
Liam Healy
lnp at healy.washington.dc.us
Sat Aug 27 21:11:53 UTC 2011
On Sat, Aug 27, 2011 at 4:10 PM, Luís Oliveira <luismbo at gmail.com> wrote:
> 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?
>
So you're suggesting retaining the :constructor and :deconstructor arguments
to defcstruct? It seems like a custom translate-*-foreign may be more
compatible with existing CFFI, though I guess a compatibility expansion
might be convenient.
For a default conversion assuming a structure on the lisp side, I'm not sure
how to iterate over the structure. Maybe MOP has something? I do have
iterate-foreign-structure. If I assume a list or vector on the lisp side,
then I could iterate through it.
If I define a specializer for a particular cstruct, what should the class
be? This looks like a type name, not the actual object that's passed as the
second argument 'type, so I presume it should be an eql specializer on the
name, but I admit I'm getting confused by this. In any case I think the
:class option to defcstruct won't always work because it does a defclass, I
need something like :existing-class that would just do a find-class.
Does any of this make sense?
Liam
--
> Luís Oliveira
> http://r42.eu/~luis/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20110827/f00f368e/attachment.html>
More information about the cffi-devel
mailing list