#[macro_export]
macro_rules! ic_memory_key {
($stable_key:literal, $label:path, $id:expr) => {{
const _: () = {
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __canic_declare_memory_slot() {
$crate::memory::registry::defer_register_with_key(
$id,
env!("CARGO_PKG_NAME"),
stringify!($label),
$stable_key,
)
.expect("memory id declaration validation failed");
}
};
let _type_check: Option<$label> = None;
$crate::memory::open_validated_memory(stringify!($label), $id)
}};
}
#[macro_export]
macro_rules! ic_memory_range {
($start:expr, $end:expr) => {{
$crate::memory::registry::defer_reserve_range(env!("CARGO_PKG_NAME"), $start, $end)
.expect("memory range reservation validation failed");
$crate::memory::runtime::registry::MemoryRegistryRuntime::commit_pending_if_initialized()
.expect("late memory range registration commit failed");
}};
}
#[macro_export]
macro_rules! eager_init {
($body:block) => {
const _: () = {
fn __canic_registered_eager_init_body() {
$body
}
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __canic_register_eager_init() {
$crate::memory::runtime::defer_eager_init(__canic_registered_eager_init_body);
}
};
};
}
#[macro_export]
macro_rules! eager_static {
($vis:vis static $name:ident : $ty:ty = $init:expr;) => {
thread_local! {
$vis static $name: $ty = $init;
}
const _: () = {
fn __canic_touch_tls() {
$name.with(|_| {});
}
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __canic_register_eager_tls() {
$crate::memory::runtime::defer_tls_initializer(__canic_touch_tls);
}
};
};
}