wasm-c-api
wasm-c-api copied to clipboard
Expose bounds checking failure for wasm_table_get
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);
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.
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.