Expand description
§cdyn — COM-style C function-table loading (ABI-stable)
Load Copy-sized vtable/descriptor structs from dynamic libraries using
plain C function tables — no Rust trait objects, no named-based access,
purely positional dispatch. This is the COM+-like emulated vtable system
(formerly the separate cdyn-loader crate).
Unlike crate::dyn_mod, this mode is ABI-stable across languages:
the C++ SDK (cdyn-loader-sdks/cpp) and Zig SDK (cdyn-loader-sdks/zig)
build plugins that match these layouts exactly.
§Cross-module memory ownership model
The core of every cross-module boundary is who manages memory. Every pointer crossing the boundary must be paired with a deallocation function that lives in the module which allocated the memory (allocators are not guaranteed to match across module/CRT boundaries). This crate provides three ownership tiers, all following that rule:
| Tier | Type | Ownership | Free function |
|---|---|---|---|
| Stateless | VTablePlugin<T> | none (static vtable) | — |
| Instance (multi-owner) | CdynHandle<T> | ref-counted via retain/release fn ptrs in AbiStableDynRef | provided by the plugin |
| Data (single-owner) | CdynBox / CdynBoxHandle | move-only, exactly one owner | free fn ptr in the box, provided by the allocating module |
Cross-module safety rules enforced by construction:
- Allocator symmetry —
free/releasealways execute inside the module that allocated (the function pointer belongs to that module’s code, e.g.CdynBox::from_vecpairs with a Rust-plugin allocator). - Library lifetime —
CdynBoxHandleandCdynHandle<T>own aDynLib(Arc-shared), so the library cannot be unloaded while a handle (and thus a free/release fn ptr) still exists.
§Usage
#[repr(C)]
struct MyVtable {
add: unsafe extern "C" fn(i32, i32) -> i32,
name: unsafe extern "C" fn() -> *const std::ffi::c_char,
}
let plugin = unsafe { VTablePlugin::<MyVtable>::load("libmy.so", b"my_get_vtable\0")? };
let n = unsafe { (plugin.vtable().add)(1, 2) };Structs§
- CdynBox
- A cross-module data box: memory allocated and freed by the same module.
- Cdyn
BoxHandle - Host-side owning handle over a
CdynBoxreceived from a foreign module. - Cdyn
Handle - Ref-counted handle to a foreign plugin object exposed through a
*_get_dynstyle entry point returning anAbiStableDynRef. - Generated
Function - Descriptor for a generated math function (matches C++ GeneratedFunction)
- Math
Module Vtable - Vtable struct matching C++ MathModuleVtable layout exactly
- VTable
Plugin - Load a Copy-sized vtable/descriptor struct from a dynamic library.
Functions§
- cdyn_
box_ ⚠free_ rust - Rust plugin free function paired with
CdynBox::from_vec.
Type Aliases§
- Math
Session - Opaque handle for a C++ MathSession
- Plugin
DynEntry Point - Type of the dyn entry point that foreign plugins export
(C++
CDYN_EXPORT AbiStableDynRef name_get_dyn(), ZigdeclareDynEntry).