This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: RFC: variadic closures in x86/x86_64
- From: Philip Ashmore <contact at philipashmore dot com>
- To: libffi-discuss at sourceware dot org
- Date: Thu, 05 Dec 2013 13:03:22 +0000
- Subject: Re: RFC: variadic closures in x86/x86_64
- Authentication-results: sourceware.org; auth=none
- References: <F023C084BCC16446BDA5B664305741E8090811 at ALPMBAPA05 dot e2k dot ad dot ge dot com> <52931854 dot 6080007 at redhat dot com> <20131125093715 dot GU892 at tucnak dot redhat dot com> <5293221D dot 4010505 at redhat dot com> <20131126142723 dot GD9211 at bubble dot grove dot modra dot org> <F023C084BCC16446BDA5B664305741E8091C7D at ALPMBAPA05 dot e2k dot ad dot ge dot com> <529F0C88 dot 3000604 at philipashmore dot com> <F023C084BCC16446BDA5B664305741E8091E8B at ALPMBAPA05 dot e2k dot ad dot ge dot com>
On 05/12/13 00:54, Hogan, D. (GE Power & Water) wrote:
> Hi Philip,
>
>> I may be talking through my hat but if there's a format argument then
>> couldn't you provide a function to parse it and then prepare other cifs
>> on an as-needed basis? The key would be the concatenation of all the
>> types in the format argument.
>
> Do you mean inside of a closure? I could access the assumed type
> information from the formatting string. The problem would be with
> ffi_call(). I can't send in a value for a variadic argument since
> I don't have a pointer to it.
>
No, I mean inside a regular function, as libffi doesn't (yet) support
variadic closures.
I don't know if it's possible to portably get pointers to variadic
arguments using va_arg, but if it is then you build up a list of
variadic arguments, synthesize a call using libffi by constructing a cif
with prep_cif_var if you don't already have an identical one, then call
the "real" function.
But then why not just call the "real" function?
I was (in my own convoluted way) trying to suggest a possible libffi
variadic closure implementation.
Any approach needs some hint as to the number and types of arguments to
unpack, like a format string.
Then it can do what it wants, like provide the arguments as a type/value
list, to the psuedo-variadic closure function to process.
The psuedo-variadic closure function could then have extra arguments - a
count and a type/value array pointer (or a pointer in libffi type-speak)
so you wouldn't even need a cif to call it.
Regards,
Philip Ashmore