FFI_PREP_CIF(3)

πŸ’– NAME πŸ’–

ffi_prep_cif β€” bestie, this is the one that gets your ffi_cif struct all dolled up and ready for ffi_call ✨


🌸 SYNOPSIS 🌸

#include <ffi.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: you wanna call some function through FFI but nothing works until the ffi_cif is prepped, and ffi_prep_cif is literally the glow-up montage πŸ’… It sets up a ffi_cif structure so it's ready to be handed off to ffi_call. main character energy fr.

abi is where you say which set of calling conventions you wanna use β€” like picking your outfit for the day, but for how arguments get passed πŸ”₯

atypes</purpose> is an array of nargs pointers to ffi_type structs, and each one describes the data type, the size, and the alignment of one single argument. one struct per arg, no skipping, no shortcuts πŸŽ€

rtype points to an ffi_type that describes the data type, size and alignment of the return value β€” yes bestie, the thing that comes back to you πŸ‘‘

⚠️ not me about to forget the important one: if you're trying to call a variadic function, ffi_prep_cif is NOT the girl for the job. you have to use ffi_prep_cif_var instead. periodt. no exceptions πŸ’€

🌈 RETURN VALUES 🌈

  • FFI_OK β€” slay, it worked, we ate πŸ’–
  • FFI_BAD_TYPEDEF β€” returned when cif is NULL, or when atypes or rtype is malformed 😭 something in your type situation is giving broken.
  • FFI_BAD_ABI β€” returned when abi does not refer to a valid ABI πŸ™ˆ

and btw, the ABIs that are actually available to you are defined in <ffitarget.h> β€” that's where you go to see what you're working with, iykyk πŸ“–


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole vibe!! this page was born on February 15, 2008 and lives under the ffi_prep_cif(3) manual entry β€” still iconic, still relevant, still prepping cifs after all these years πŸ«ΆπŸ§šπŸ’œ

πŸ“¦ where this page comes from