Stream: wit-bindgen

Topic: Calling libc functions from C#


view this post on Zulip Joel Dice (Apr 25 2024 at 19:43):

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?

view this post on Zulip Scott Waye (Apr 25 2024 at 20:46):

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

A language binding generator for WebAssembly interface types - bytecodealliance/wit-bindgen

view this post on Zulip Joel Dice (Apr 25 2024 at 20:47):

Sure, I understand that part. What I'm wondering is how to call free from C#.

view this post on Zulip Scott Waye (Apr 25 2024 at 20:58):

We support NativeAOT's DirectPinvoke function, an example is https://github.com/dotnet/runtimelab/tree/feature/NativeAOT-LLVM/src/tests/nativeaot/SmokeTests/PInvoke

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo. - dotnet/runtimelab

view this post on Zulip Joel Dice (Apr 25 2024 at 21:01):

Thanks, I'll experiment with that

view this post on Zulip Joel Dice (Apr 25 2024 at 21:02):

Would we need to do something different for Mono?

view this post on Zulip Scott Waye (Apr 25 2024 at 21:12):

I dont _think_ so as the c# is standard, but I'm not sure :-)

view this post on Zulip Larry Ewing (Apr 25 2024 at 23:23):

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 23 2024 at 12:05 UTC