wit-bindgen
wit-bindgen copied to clipboard
How do I return list from C code?
I have wit file like this:
package my:demo;
world demo {
record preset {
id: u16,
len: u16,
offset: u16
}
export get-presets: func() -> list<preset>;
}
How do I return that list in function void exports_demo_get_presets(demo_list_preset_t *ret); implementation?
I do something like this:
void exports_demo_get_presets(demo_list_preset_t *ret) {
ret.ptr = malloc(sizeof(struct demo_preset_t) * 2);
ret.len = 2;
}
but who is responsible for free the ret.ptr? Will that happen automatically?
Some excellent documentation was just written up at https://github.com/bytecodealliance/wit-bindgen/blob/main/crates/c/README.md quite recently, mind reading that over and seeing if it answers your question?