bytecodealliance / bytecodealliance/wit-bindgen

How do I return list from C code?

Open
#1,329 1 comment 0 reactions 0 assignees View on GitHub
gen-c
Dominant language
Rust
Stars
1.5k
Forks
286
Avg merge
6h 32m
Merged PRs (30d)
19

Description

I have wit file like this:
```
package my:demo;

world demo {
record preset {
id: u16,
len: u16,
offset: u16
}
export get-presets: func() -> list;
}
```
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.