WebAssembly / wasm-c-api

Wasm C API prototype
Apache License 2.0
534 stars 77 forks source link

feat: `wasm_name_new_from_string*` owns `s` #155

Open Hywan opened 3 years ago

Hywan commented 3 years ago

wasm_name_new is an alias to wasm_byte_vec_new, which owns the ptr_or_none argument, which is in this case s.

This patch adds the own market to wasm_name_new_from_string and wasm_name_new_from_string_nt.

rossberg commented 3 years ago

Oh, ouch. I see there is an inconsistency there. Unfortunately, I think this is the wrong fix. These constructors don't take ownership of the string in the implementation, nor should they -- you wouldn't be able to create a name form a string literal, for example.

It's the definition of WASM_DECLARE_VEC that is wrong here. The own on wasm_byte_vec_new doesn't actually make sense when ptr_or_none is empty.

I think the right fix would be to move the own from the macro's definition to its invocations, passing own* for ptr_or_none where it currently passes just *. Or to split the macro in three, analogous to the implementation in wasm-c.cc.