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: [PATCH] Add variadic support


On 23 February 2011 12:40, Anthony Green <green@redhat.com> wrote:
> "Dr. David Alan Gilbert" <david.gilbert@linaro.org> writes:
>
>> Hi,
>> ? As discussed a couple of months ago, I've added explicit support
>> for calling variadic functions to libffi. ?This work is required
>> for ARM hard float (aka VFP) systems to call variadic functions
>> (by switching away from the vfp abi).
>>
>> ? I'm assuming this is too late for the 3.0.10 cycle but I thought
>> I'd get the patch out for discussion anyway.
>
> Thanks David. ?This sounds promising, but it looks like the patch is not
> complete. ?Where is ffi_prep_cif_var?

It's only small and it is there (I checked the mail list archive!) ;
it's in the prep_cif.c diff:

+ffi_status ffi_prep_cif_var(ffi_cif *cif,
+                            ffi_abi abi,
+                            unsigned int nfixedargs,
+                            unsigned int ntotalargs,
+                            ffi_type *rtype,
+                            ffi_type **atypes)
+{
+  FFI_ASSERT(cif != NULL);
+  /* There should always be at least one fixed arg */
+  FFI_ASSERT(nfixedargs >= 1);
+  FFI_ASSERT(nfixedargs <= ntotalargs);
+#ifdef FFI_TARGET_SPECIFIC_VARIADIC
+  cif->nfixedargs = nfixedargs;
+#endif
+  return ffi_prep_cif_core(cif, abi, ntotalargs, rtype, atypes);
+}
+

What I'm doing is that I've renamed ffi_prep_cif to ffi_prep_cif_core and then
ffi_prep_cif and ffi_prep_cif_var are wrappers around _core that set
cif->nfixedargs
which acts as a flag as to whether it's a variadic function that the
backend code can
decide what to do.

The result is that there are no changes to any of the backends that
don't care about it.

In ARM's ffi_prep_cif_machdep I have:

+#ifdef __ARM_PCS_VFP
+  /* VFP uses the standard ABI for variadic functions */
+  if ((cif->abi == FFI_VFP) && (cif->nfixedargs != 0))
+    cif->abi = FFI_SYSV;
+#endif

and that's the only active change that's needed.

Dave


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