Skip to content

How do I return list from C code? #1329

Open
@hellozyemlya

Description

@hellozyemlya

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-cRelated to the C code generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions