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: Variadic functions and libffi


On 01/06/2011 11:34 AM, Marcus Shawcroft wrote:

that is just like ffi_prep_cif but also takes a 'nnamedargs' to say
the number of fixed args (and hence which arg is the 1st variadic).

I don't think this is such a great design, because you'd be doing the calculation about where to put the args at the time of the call. IMO it makes more sense to do as much precomputation as possible, by calling ffi_prep_cif_variadic with the actual number of fixed args and the actual number of varargs you intend to pass. In almost all usages of libffi you really will know the number of arguments to be passed when preparing the CIF. If you can precompute all this stuff you can even use a JIT to generate code for the call.

The prototype David and I discussed has the form:


ffi_status ffi_prep_cif_variadic(ffi_cif *cif, ffi_abi abi, unsigned int
nargs, unsigned int nnamedargs, ffi_type *rtype, ffi_type **atypes);

Which makes available the total number of arguments, the number of named
arguments and hence the number of anonymous arguments up front.

Ah, OK. That seems reasonable.


Paging Anthony Green: I never understood why libffi didn't deal with
varargs -- was it a conscious design decision, or just something you
never got around to?

Andrew.


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