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

feat: `wasm_name_new_from_string*` owns `s`

Open Hywan opened this issue 5 years ago • 1 comments

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.

Hywan avatar Oct 09 '20 12:10 Hywan

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.

rossberg avatar Oct 12 '20 16:10 rossberg