This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: Closures without VA-stuff
- From: William Ahern <william at 25thandClement dot com>
- To: Jonathan Schmidt-Domin? - Developer <devel at the-user dot org>
- Cc: libffi-discuss at sources dot redhat dot com
- Date: Sat, 19 Dec 2009 17:47:57 -0800
- Subject: Re: Closures without VA-stuff
- References: <200912200220.24184.devel@the-user.org>
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.