1 #![expect(unsafe_op_in_unsafe_fn, reason = "old code, not worth updating yet")]
2 
3 //! `wit-component` handles modules which export `cabi_realloc` in a special way, using it instead of `memory.grow`
4 //! to allocate the adapter stack, hence this test.
5 
6 #[unsafe(export_name = "cabi_realloc")]
cabi_realloc( old_ptr: *mut u8, old_len: usize, align: usize, new_len: usize, ) -> *mut u87 unsafe extern "C" fn cabi_realloc(
8     old_ptr: *mut u8,
9     old_len: usize,
10     align: usize,
11     new_len: usize,
12 ) -> *mut u8 {
13     use std::alloc::{self, Layout};
14 
15     let layout;
16     let ptr = if old_len == 0 {
17         if new_len == 0 {
18             return align as *mut u8;
19         }
20         layout = Layout::from_size_align_unchecked(new_len, align);
21         alloc::alloc(layout)
22     } else {
23         debug_assert_ne!(new_len, 0, "non-zero old_len requires non-zero new_len!");
24         layout = Layout::from_size_align_unchecked(old_len, align);
25         alloc::realloc(old_ptr, layout, new_len)
26     };
27     if ptr.is_null() {
28         #[cfg(target_arch = "wasm32")]
29         core::arch::wasm32::unreachable();
30     }
31     return ptr;
32 }
33 
main()34 fn main() {
35     println!("hello, world");
36 }
37