This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: Variadic functions and libffi
- From: Chung-Lin Tang <cltang at codesourcery dot com>
- To: David Gilbert <david dot gilbert at linaro dot org>
- Cc: libffi-discuss at sourceware dot org, Marcus dot Shawcroft at arm dot com
- Date: Thu, 06 Jan 2011 03:28:38 +0800
- Subject: Re: Variadic functions and libffi
- References: <AANLkTi=LT1mzE4HVxJ1mkACpew9O-4fLPipw6urBp1JO@mail.gmail.com>
On 2011/1/6 01:47, David Gilbert wrote:
> 'ffi_prep_cif_variadic'
>
> 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).
> For all architectures that don't care this can just call ffi_prep_cif
> and lose the extra arg, this should mean it won't break anything else,
> but any architecture that did need to know which were variadic args
> would have that information.
That sounds like a reasonable design, although it seems possible to do
away with the 'nnamedargs', and treat ffi_prep_cif_variadic() as
effectively just "adding an ellipse (...)", and leave the variable
argument issues to ffi_call().
This will effectively delay some of the normal ffi_prep_cif() work to
ffi_call() (things like laying out the regs/stack for the variable
arguments), and may be slower when doing the calling, but should be a
more intuitive API design; users just create the needed arg-list at each
call, rather than creating a new ffi_cif instance for each variable
argument set.
That said, I think the proposed 'nnamedargs' style is still fine, for it
should be more straightforward to implement :)
Chung-Lin