Skip to contents

C's types do not say which pointer arguments a function reads, which it writes, how long a buffer is, or who frees a pointer it returns. These annotations say it, for the declarations they are given to (design §4.3).

Usage

ffi_in(len = NULL)

ffi_out(len)

ffi_inout(len = NULL)

ffi_owned(free_fn)

Arguments

len

For ffi_in() and ffi_inout(), the name of the length argument, or NULL. For ffi_out(), a number of elements, or the name of the argument that gives it.

free_fn

The name of the library function that frees the result.

Value

An annotation, of class zuffi_annotation.

Details

  • ffi_in(len): an R vector the function reads. For a non-const pointer it is copied, so the function may write into the copy and the vector stays as it was; a const pointer is passed with no copy.

  • ffi_out(len): a buffer the function fills. zuffi allocates len elements, the function writes them, and the call returns them.

  • ffi_inout(len): an R vector copied into a buffer that the function reads and writes; the call returns the buffer.

  • ffi_owned(free_fn): the result is a pointer that free_fn, a function of the same library, frees: zuffi frees it when the pointer is collected, or at ffi_free().

For ffi_in() and ffi_inout(), len names the argument that holds the buffer's length: the caller no longer gives it, and zuffi passes the vector's length. For ffi_out(), len is the number of elements, or the name of the argument the caller gives it in. Lengths count elements; bytes for void *.

A function with ffi_out() or ffi_inout() arguments returns a list: value, its result, and one element per such argument. Buffers of void, char, unsigned char and uint8_t come back as raw vectors, the others as their type's R vector (design §6).

Examples

ffi_out(len = "n")
#> <zuffi_annotation> ffi_out(len = "n")
ffi_owned("free")
#> <zuffi_annotation> ffi_owned("free")