Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Compat Helpers

Some C interfaces are macros or platform-specific symbols rather than plain functions. On the source side, cpp2rust rewrites them into ordinary calls (see Compat Shims); the compat module is the runtime side of that rewrite.

errno expands to a platform-specific function call (__errno_location on Linux, __error on macOS).

In the unsafe model, cpp2rust_errno_unsafe binds both platform symbols under one name and returns the real libc errno location:

#![allow(unused)]
fn main() {
pub unsafe fn cpp2rust_errno_unsafe() -> *mut i32;
}

In the refcount model, errno is a thread-local refcounted i32 that the runtime maintains itself:

#![allow(unused)]
fn main() {
pub fn cpp2rust_errno() -> Ptr<i32>;
}

Refcount code reaches the operating system through the libc shims and nix, so libc’s errno is never read by this model. Keeping the cell current is a discipline of the rules: every rule that translates a call that can fail must write the error code into cpp2rust_errno() on the failure path (see Compat Shims); nothing enforces this, and a rule that skips the write breaks programs that check errno.

malloc_usable_size is bound under one name for both platforms (the symbol is malloc_size on macOS).