wasm-c-api icon indicating copy to clipboard operation
wasm-c-api copied to clipboard

`vec<T>::make_nt` may not be so helpful

Open jiahaog opened this issue 1 year ago • 1 comments

I refer to vec<T>::make_nt:

https://github.com/WebAssembly/wasm-c-api/blob/2ce1367c9d1271c83fb63bef26d896a2f290cd23/include/wasm.hh#L154-L158

This is implemented using std::strcpy, which stops copying when it encounters \0. It seems like more often than not, it's used to hold bytes of a Wasm binary (as a vec<byte_t>). But Wasm binaries start with \0asm, so nothing will be copied.

I'm not sure if there are other specializations where stopping at the first \0 makes sense. Considering that we already have vec::make(std::string), perhaps vec::make_nt isn't so helpful and we may want to consider removing it.

https://github.com/WebAssembly/wasm-c-api/issues/149 is also related.

jiahaog avatar Nov 30 '23 06:11 jiahaog

Hm, it would probably make more sense for this to take a const char*.

As for use case, byte vectors aren't just used for module binaries, names are the relevant case for this.

rossberg avatar Nov 30 '23 07:11 rossberg