Skip to main content

Module object

Module object 

Source
Expand description

Reference-counted interface objects: the producer half of the ABI’s object model.

An interface value crosses the C ABI as a {tag}* that is really an Arc<T> turned into a raw pointer with Arc::into_raw. The count lives inside the producer’s allocation, so every consumer wrapper, every value buffer holding an object token, and every in-flight async call can own its own strong reference: {tag}_clone bumps the count and {tag}_destroy releases one reference. The object is dropped when the last reference goes.

The #[weaveffi::module] expansion calls these helpers from its generated thunks; producers never touch them directly. They exist so every unsafe pointer-to-Arc conversion has one audited home.

Functions§

lower_object
Hand one strong reference to the consumer.
lower_object_opt
Lower an optional object: None becomes null, Some transfers one strong reference exactly like lower_object.
object_arc⚠
Take a new strong reference to a borrowed object, so the producer can retain it past the call. Null yields None.
object_clone⚠
The body of every {tag}_clone symbol: return a new strong reference to the same object. The pointer value is unchanged; null is a no-op returning null.
object_destroy⚠
The body of every {tag}_destroy symbol: release one strong reference. The object is dropped when the last reference goes. Null is a no-op, and a panicking Drop is swallowed because a destructor has no out_err slot and must never unwind into C.
object_from_token⚠
Adopt the strong reference carried by an object token read from a value buffer. A zero token is a contract violation and yields None.
object_ref⚠
Borrow an object for the duration of a call without touching its count. Null yields None.
object_to_token
The object token an interface value takes inside a value buffer: the lower_object pointer widened to u64. The token carries one strong reference; whoever decodes it adopts that reference.