bloqade_lanes_bytecode/ffi/memory.rs
1use std::ffi::CString;
2use std::os::raw::c_char;
3
4/// Free a Rust-allocated C string (from `blqd_program_to_text`, etc.)
5#[unsafe(no_mangle)]
6pub unsafe extern "C" fn blqd_free_string(ptr: *mut c_char) {
7 if !ptr.is_null() {
8 drop(unsafe { CString::from_raw(ptr) });
9 }
10}
11
12/// Free a Rust-allocated byte buffer (from `blqd_program_to_binary`).
13/// `len` must be the value returned by the producing function.
14#[unsafe(no_mangle)]
15pub unsafe extern "C" fn blqd_free_bytes(ptr: *mut u8, len: usize) {
16 if !ptr.is_null() {
17 drop(unsafe { Box::from_raw(std::ptr::slice_from_raw_parts_mut(ptr, len)) });
18 }
19}