This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Closures without VA-stuff


On Sun, Dec 20, 2009 at 02:20:22AM +0100, Jonathan Schmidt-Domin? - Developer wrote:
> Hi!
> 
> I am seeking a library providing a very simple feature like this:
> int test(void *d, int x);
> int main()
> {
>   struct data
>   {
>     int a, b;
>   };
>   data d;
>   int(*fun)(int) = create_closure(test, &d);
>   fun(4); // invokes test(d, 4)
> }
> So I have found two libraries: ffcall and libffi.
> Such things are possible with libffi (and even ffcall), but there is no way to 
> do simply that, you always need this "varaidic stuff". Why isn't there any 
> simple function to create closures? Any suggestions what I should try to do?
> I am asking you, because libffi looks promising. ;)

While not providing exactly that, you may be able to get some ideas and
working code from this:

	http://www.25thandclement.com/~william/projects/delegate.c.html

It uses libffi underneath, and provides the convenience that you're
expecting by using GCC's extensive build-time typing and conditional
built-ins. To get the ability to pass the dynamic "4" you'll need to hack it
a little to recognize "placeholder" values (I need to add this eventually
myself). Also delegate.c doesn't use FFI's closure abilities, but this
shouldn't be difficult to add as a layer above the stuff that delegate.c
does.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]