abi_stable/docs/unsafe_code_guidelines.rs
1/*!
2
3This document describes all the things that are unsafe to do with abi_stable.
4
5# De/allocation,and other global state,without going through a vtable.
6
7It is unsafe to rely on allocators being the same across dynamic libraries,
8because Rust allows changing the allocator when building a dynamic library/binary.
9
10The way this library handles allocation is by creating a vtable (virtual dispatch table)
11for each type that directly allocates/deallocates (ie:`RVec`,`RBox`),
12and storing a pointer to the vtable as a field in the type.
13Any method that needs it calls vtable functions to do the allocation/deallocation.
14
15# Relating to global constructors in dynamic libraries
16
17It is unsound to do load a library developed with abi_stable or
18checking the layout of types with
19`abi_stable::abi_stability::check_layout_compatibility` in global constructors,
20because `abi_stable` relies on initializing its global global state in the binary
21and passing that global state to dynamic libraries before loading any module.
22
23It is **safe** however to use anything else from `abi_stable` in global constructors,
24
25"Global constructor" is any code that runs before any library symbol can be loaded,
26including those of abi_stable modules.
27
28*/