#![allow(clippy::inline_always)]
use core::ffi::c_void;
use crate::consts::LEAN_EXTERNAL;
use crate::repr::LeanExternalObjectRepr;
use crate::types::{lean_obj_res, lean_object};
pub type lean_external_finalize_proc = unsafe extern "C" fn(*mut c_void);
pub type lean_external_foreach_proc = unsafe extern "C" fn(*mut c_void, *mut lean_object);
unsafe extern "C" {
pub fn lean_register_external_class(
finalize: lean_external_finalize_proc,
foreach: lean_external_foreach_proc,
) -> *mut c_void;
}
#[inline(always)]
pub unsafe fn lean_alloc_external(cls: *mut c_void, data: *mut c_void) -> lean_obj_res {
unsafe {
let raw = crate::object::lean_alloc_object(core::mem::size_of::<LeanExternalObjectRepr>());
let repr = raw.cast::<LeanExternalObjectRepr>();
(*repr).header.m_rc = 1;
(*repr).header.m_tag = LEAN_EXTERNAL;
(*repr).header.m_other = 0;
(*repr).header.m_cs_sz = 0;
(*repr).class = cls;
(*repr).data = data;
raw
}
}
#[inline(always)]
pub unsafe fn lean_get_external_class(o: *mut lean_object) -> *mut c_void {
unsafe { (*o.cast::<LeanExternalObjectRepr>()).class }
}
#[inline(always)]
pub unsafe fn lean_get_external_data(o: *mut lean_object) -> *mut c_void {
unsafe { (*o.cast::<LeanExternalObjectRepr>()).data }
}