use core::default::Default;
use core::ptr;
use crate::mlvalues::{field, Size, Value};
#[repr(C)]
#[derive(Debug, Clone)]
pub struct CamlRootsBlock {
pub next: *mut CamlRootsBlock,
pub ntables: isize,
pub nitems: isize,
pub tables: [*mut Value; 5],
}
impl Default for CamlRootsBlock {
fn default() -> CamlRootsBlock {
CamlRootsBlock {
next: ptr::null_mut(),
ntables: 0,
nitems: 0,
tables: [ptr::null_mut(); 5],
}
}
}
extern "C" {
pub fn caml_modify(addr: *mut Value, value: Value);
pub fn caml_initialize(addr: *mut Value, value: Value);
}
macro_rules! store_field {
($block:expr, $offset:expr, $val:expr) => {
let offset = $offset;
let val = $val;
let block = $block;
$crate::memory::caml_modify(field(block, offset), val);
};
}
pub unsafe fn store_field(block: Value, offset: Size, value: Value) {
store_field!(block, offset, value);
}
extern "C" {
pub fn caml_enter_blocking_section();
pub fn caml_leave_blocking_section();
pub fn caml_register_global_root(value: *mut Value);
pub fn caml_remove_global_root(value: *mut Value);
pub fn caml_register_generational_global_root(value: *mut Value);
pub fn caml_remove_generational_global_root(value: *mut Value);
pub fn caml_modify_generational_global_root(value: *mut Value, newval: Value);
}