Skip to main content

luaur_code_gen/functions/
destroy_shared_code_gen_context.rs

1use crate::records::shared_code_gen_context::SharedCodeGenContext;
2
3/// # Safety
4///
5/// This function is native-only and performs a manual memory deallocation.
6/// The caller must ensure that `code_gen_context` was created by a matching
7/// allocation function and that it is not used after this call.
8#[no_mangle]
9pub unsafe extern "C" fn destroy_shared_code_gen_context(
10    code_gen_context: *const SharedCodeGenContext,
11) {
12    if !code_gen_context.is_null() {
13        let ptr = code_gen_context as *mut SharedCodeGenContext;
14        unsafe {
15            core::ptr::drop_in_place(ptr);
16            alloc::alloc::dealloc(
17                ptr as *mut u8,
18                core::alloc::Layout::new::<SharedCodeGenContext>(),
19            );
20        }
21    }
22}