1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
use memalloc; use std::ffi::{CString}; use std::os::raw::{c_char}; #[no_mangle] pub fn alloc(size: usize) -> *mut u8 { unsafe { let ptr = memalloc::allocate(size); ptr } } #[no_mangle] pub fn dealloc(ptr: *mut u8, size: usize) { unsafe { memalloc::deallocate(ptr as *mut u8, size); } } #[no_mangle] pub fn dealloc_str(ptr: *mut c_char) { unsafe { let _ = CString::from_raw(ptr); } }