Changelog
Source:NEWS.md
zuffi 0.0.0.9000
ffi_dlopen()opens a shared library by path or by stem, with each platform’s naming and never the working directory;ffi_dlsym()looks up a symbol andffi_close()unloads the library.Calls to scalar C functions through a vendored libffi 3.8.2: every integer type,
float,double,boolandconst char *, converted exactly or with a classedzuffi_error. 64-bit and 128-bit integers can arrive as zuint values (ffi_dlopen(int64 = "zuint")).Variadic functions take typed arguments made with
ffi_arg().ffi_errno()andffi_last_error()returnerrnoand Windows’GetLastError()as the latest declared call left them.Pointers are
zuffi_ptrobjects carrying their C type, their size when known and who frees them.ffi_new()allocates C memory R owns;p$xandp[i]read and write members and elements within the known size;ffi_cast(),ffi_string(),ffi_own()andffi_free()work on any pointer. A freed pointer is cleared, a forked child frees nothing, andffi_close()refuses while an owned pointer still needs the library.Structs, unions, fixed arrays and nested structs are laid out as the C compiler lays them out,
packed,alignedand#pragma packincluded;ffi_sizeof()andffi_offsetof()report the layout. Structs cross by value as arguments and results; unions and packed structs do not.R vectors pass as C buffers: a
constpointer reads the vector in place, andffi_in(),ffi_out(),ffi_inout()andffi_owned()give other pointers a direction or an owner. Integer buffers are always checked forNA.ffi_cdef()declares functions, structs, unions, enums, typedefs and#defineconstants from C text, as a header writes them, and lays out structs as the C compiler does. It does not preprocess. What zuffi cannot lay out or call (a bit-field,_Complex,_Atomic, a function with a body,long doubleby value) is declared anyway and refused where it is used, with the reason;ffi_functions()lists every function and whether it can be called. An error gives its line and column and leaves the handle as it was.A
#definewith along doubleoperand is not bound, on any platform;ffi_constants()lists it as skipped with the reason (#44).Enum results and members are integers of class
zuffi_enum, printed by name; enum arguments take an integer or an enumerator’s name.zuffi_info()reports the package and libffi versions, libffi’s target and the UniFFI contract version the runtime reads (33).A runtime for Rust crates built with UniFFI 0.33: its C half lowers R values into UniFFI’s wire format and lifts results out of it, exactly or with a classed error, for scalars, strings, owned and borrowed bytes,
Option,Vec,HashMapwith string keys, records, enums, errors, custom types and objects. Rust errors arrive as conditions of class<crate>_<Error>anduniffi_error, and panics aszuffi_panic_error. A library whose contract version or checksums differ from its bindings’ is refused at load. Objects hold their handle whole, clone it for every call and free it once;ffi_free()frees one at once.uniffi_load()loads a UniFFI crate’s library with the R bindings that uniffi-bindgen-r generates from it, found by default beside the library and named after the crate. A library and bindings from different builds refuse to load, naming the functions whose checksums differ. Rust and cargo build the crate and its bindings; R needs neither.ffi_callback()makes an R function a C function pointer, for aqsort()comparator or a handler a library keeps (lib =keeps it untilffi_close()). Its arguments and result convert as a call’s do. An error, interrupt or restart in it never jumps across the library’s frames: the callback returnsdefault, and the condition carries on once the library has returned. A callback called from another thread returnsdefaultwithout touching R, and the next call raises azuffi_thread_error.ffi_cast()to a function-pointer type makes an R function that calls the pointer.zuffi_info()$closuressays whether callbacks can be made.ffi_include()declares a library from its header: the C compiler R builds packages with (R CMD config CC) preprocesses it, withincludedirectories anddefines, and theffi_cdef()parser reads the result. Every object-like macro the header defines is expanded and bound as a constant where it is one.ffi_constants()lists the enumerators and constants a handle bound, and the macros it skipped with the reason. Macros of a file the compiler includes on its own, such as glibc’s<stdc-predef.h>, are not the header’s and are left out. Preprocessed headers are cached for the session. Without a compiler, or with a header missing, the error says what is missing.zuffi_info()$preprocessorslists the preprocessors found. Each type’s text is read once a session, soffi_include("sqlite3.h")takes about 390 ms the first time, down from 650 (#37).ffi_cdef()reads Apple’s block pointers (making what holds them incomplete), enums with a fixed underlying type,typeofand aarch64’s vector types (as unsupported), does not check a static assertion on a type it does not lay out, gives a bare__attribute__((aligned))16 bytes wherever zuffi was built, and binds a 64-bit constant that a double holds exactly, such asLLONG_MIN, instead of refusing it.A typedef with its own
alignedattribute has that alignment, as C’s_Alignofgives it:ffi_new()allocates at it, where before it used the alignment of the type the typedef names. An array whose element size is not a multiple of its alignment is refused, as gcc and clang refuse it (#33).A README for a first-time reader, and a Get started vignette that runs: declarations, refused conversions, structs, a
qsort()callback and a header, with the Rust crate shown but not run.zuffi passes
R CMD checkon platforms without a libffi target (Windows on ARM, WebAssembly): the examples, vignette chunks and tests that call C are skipped there, and the rest run.On R 4.6 and older, a regular expression that runs out of memory while matching only warns, and returns a wrong value. Wherever zuffi reads text with one (type text, member paths, library names, headers, UniFFI bindings, and the version checks of loading zuint) that warning is now a
zuffi_memory_error. Before,int[3]could read with two dimensions, or a pointer type with the wrong depth, and stay so for the session, andffi_dlopen("./libm.so.6")could open a library of that name in another directory (#49).Initial CRAN submission.