Passing structures to callbacks by-value

Bug #1828643 reported by Ekaterina Vaartis
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
CFFI
In Progress
Wishlist
Angel Peralta

Bug Description

Theres seems to be no way to pass structures to callbacks by value, even with libffi, although all other things support that with libffi.

Tags: libffi
Revision history for this message
Luís Oliveira (luismbo) wrote :

This is indeed a big oversight. Is this something you'd be interested to work on?

Changed in cffi:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Ekaterina Vaartis (vaartis) wrote :

If you can give me some guidance on how to actually do this, i could do it. I have no experience with libffi though.

Revision history for this message
Luís Oliveira (luismbo) wrote :

So, the first step is to learn how to set up callbacks using libffi. I'm guessing their Closure API is the way to go. You could do this in C first and then translate that to CFFI, or start with CFFI, depending on how familiar you are with CFFI. You definitely need to be familiar with C, I think. :-)

Revision history for this message
Ekaterina Vaartis (vaartis) wrote :

I'll try to check it out and will write back later.

Revision history for this message
Ekaterina Vaartis (vaartis) wrote :

Although it'd be nice to also know how libffi integrates with CFFI, since the libffi system is pretty small and i don't see direct places that explain passing strcutures by-value.

Revision history for this message
Luís Oliveira (luismbo) wrote : Re: [Bug 1828643] Re: Passing structures to callbacks by-value

foreign-funcall-form/fsbv-with-libffi (
https://github.com/cffi/cffi/blob/master/libffi/funcall.lisp#L82) is the
main entry point.

Revision history for this message
Alexey Egorov (alexey-e-egorov) wrote :

It seems that `cffi:defcallback` doesn't currently use libffi for creation callbacks.
E.g. in case of sbcl, it calls `%defcallback`, that is defined in `cffi-sbcl.lisp` and calls SBCL's own `alien-sap`.

That means, if we want to add support for libffi callbacks, we need to define a new macro, like `cffi:defcallback-libffi` or something.

Revision history for this message
Luís Oliveira (luismbo) wrote :

Alexey, that shouldn't be necessary. Have a look at how DEFCFUN (and FOREIGN-FUNCALL, etc) decides to use libffi when needed without resorting to an auxiliar DEFCFUN-LIBFFI.

Revision history for this message
Angel Peralta (acort3255) wrote :

I have a PR up that should address this issue. Just awaiting review/feedback: https://github.com/cffi/cffi/pull/351

Changed in cffi:
assignee: nobody → Angel Peralta (acort3255)
status: Triaged → In Progress
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.