While working to get more tests passing for the C# binding generator, I've hit some todo!() cases for Instruction::GuestDeallocate and friends. They need to do the opposite of cabi_realloc, i.e. pass a realloc'd pointer to free. How can I call free from C# code?
We drop down to realloc currently, so free would be appropriate. https://github.com/bytecodealliance/wit-bindgen/blob/118e96f0ef4df353d2e917c6e53fb8de6199f93d/crates/csharp/src/lib.rs#L478-L496
Sure, I understand that part. What I'm wondering is how to call free from C#.
We support NativeAOT's DirectPinvoke function, an example is https://github.com/dotnet/runtimelab/tree/feature/NativeAOT-LLVM/src/tests/nativeaot/SmokeTests/PInvoke
Thanks, I'll experiment with that
Would we need to do something different for Mono?
I dont _think_ so as the c# is standard, but I'm not sure :-)
Scott Waye said:
I dont _think_ so as the c# is standard, but I'm not sure :-)
If there are differences, we can resolve them.
Last updated: Dec 06 2025 at 06:05 UTC