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

Expose bounds checking failure for wasm_table_get

Open AndrewScheidecker opened this issue 5 years ago • 2 comments

The API for getting a table element doesn't directly expose the possibility for the access to fail due to bounds checking:

own wasm_ref_t* wasm_table_get(const wasm_table_t*, wasm_table_size_t index);

Perhaps it should be something like this:

bool wasm_table_get(const wasm_table_t*, wasm_table_size_t index, own wasm_ref_t** out);

AndrewScheidecker avatar Jun 21 '19 12:06 AndrewScheidecker

it currently returns null in that case, but that's not distinguishable from a null reference. So I agree this should probably be changed somehow.

rossberg avatar Jun 21 '19 13:06 rossberg

Thinking about this some more I believe the current interface is fine. Bounds checks are a safety mechanism, not something that is intended to be used programmatically. In C land, getting null in the error case seems like reasonable behaviour.

rossberg avatar Jul 30 '19 08:07 rossberg