FFI & External Interface
Use extern declarations to call external symbols such as C library functions or system APIs. When using FFI, make sure your parameter types, memory layout, and resource cleanup match the external API.
Extern Blocks
Section titled “Extern Blocks”Single declarations can use top-level modifiers:
C Strings
Section titled “C Strings”C APIs represent strings as UInt8*. A string literal passed in that context is emitted as
null-terminated read-only data:
Borrowed sentinel string views use UInt8[:0]&. Use $.ptr() when a C API needs a raw pointer.
Use view.slice() or view$.as(UInt8[]&) when Jiang code needs to treat a
non-literal sentinel view as a plain byte slice:
When a C API needs a pointer plus a length, model the pointer and length explicitly:
Raw Pointers
Section titled “Raw Pointers”T* is a raw pointer for FFI, ABI, and low-level code:
Writing through a single-object raw pointer requires a mutable pointee:
Raw Buffer Pointers
Section titled “Raw Buffer Pointers”T* is also the unbounded raw contiguous-memory view used by C buffer parameters:
Indexing raw pointers is unsafe because they carry no length. T* can be indexed for reads, while
T*! also permits writes. Wrap the pointer with a length field or use T[]& when Jiang code needs a
borrowed length-bearing view. T[*] and T[*:S] have been removed.
Resource Boundaries
Section titled “Resource Boundaries”When wrapping external resources, make ownership explicit: