difftreelog
feat(bindings) realloc
in: master
1 file changed
bindings/jsonnet/src/lib.rsdiffbeforeafterboth181 todo!()181 todo!()182}182}183183184/// # Safety185///186/// This function is most definitely broken, but it works somehow, see TODO inside184#[no_mangle]187#[no_mangle]185pub extern "C" fn jsonnet_realloc(_vm: &EvaluationState, _buf: *const u8, _sz: usize) -> *const u8 {188pub unsafe extern "C" fn jsonnet_realloc(189 _vm: &EvaluationState,190 buf: *mut u8,191 sz: usize,192) -> *mut u8 {193 if buf.is_null() {186 todo!()194 assert!(sz != 0);195 return std::alloc::alloc(Layout::from_size_align(sz, std::mem::align_of::<u8>()).unwrap());196 }197 // TODO: Somehow store size of allocation, because its real size is probally not 16 :D198 // OR (Alternative way of fixing this TODO)199 // TODO: Standard allocator uses malloc, and it doesn't uses allocation size,200 // TODO: so it should work in normal cases. Maybe force allocator for this library?201 let old_layout = Layout::from_size_align(16, std::mem::align_of::<u8>()).unwrap();202 if sz == 0 {203 std::alloc::dealloc(buf, old_layout);204 return std::ptr::null_mut();205 }206 std::alloc::realloc(buf, old_layout, sz)187}207}188208189#[no_mangle]209#[no_mangle]