use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
#[no_mangle]
#[inline(always)]
pub extern "C" fn __alloc(size: i32) -> *mut u8 {
let mut buf = Vec::with_capacity(size as usize);
let ptr = buf.as_mut_ptr();
std::mem::forget(buf);
ptr
}
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
#[no_mangle]
#[inline(always)]
pub extern "C" fn __free(ptr: *mut u8, size: i32) -> i32 {
let data = unsafe { Vec::from_raw_parts(ptr, size as usize, size as usize) };
std::mem::drop(data);
0 as _
}
#[doc(hidden)]
#[cfg(all(target_arch = "wasm32", feature = "layout_alloc"))]
#[no_mangle]
#[inline(always)]
pub unsafe fn __alloc(size: usize) -> usize {
let layout = match Layout::from_size_align(size as usize, std::mem::align_of::<u8>()) {
Ok(layout) => layout,
Err(_) => return 0 as _,
};
unsafe { global_alloc(layout) as _ }
}
#[doc(hidden)]
#[cfg(all(target_arch = "wasm32", feature = "layout_alloc"))]
#[no_mangle]
#[inline(always)]
pub unsafe fn __free(ptr: *mut u8, size: usize) {
let layout = match Layout::from_size_align(size as usize, std::mem::align_of::<u8>()) {
Ok(layout) => layout,
Err(_) => return 0 as _,
};
unsafe {
global_dealloc(ptr, layout);
}
0 as _
}