Add wasmtime-specific C APIs for tables (#1654)
This commit adds a suite of `wasmtime_funcref_table_*` APIs which mirror the standard APIs but have a few differences: * More errors are returned. For example error messages are communicated through `wasmtime_error_t` and out-of-bounds vs load of null can be differentiated in the `get` API. * APIs take `wasm_func_t` instead of `wasm_ref_t`. Given the recent decision to remove subtyping from the anyref proposal it's not clear how the C API for tables will be affected, so for now these APIs are all specialized to only funcref tables. * Growth now allows access to the previous size of the table, if desired, which mirrors the `table.grow` instruction. This was originally motivated by bytecodealliance/wasmtime-go#5 where the current APIs we have for working with tables don't quite work. We don't have a great way to take an anyref constructed from a `Func` and get the `Func` back out, so for now this sidesteps those concerns while we sort out the anyref story. It's intended that once the anyref story has settled and the official C API has updated we'll likely delete these wasmtime-specific APIs or implement them as trivial wrappers around the official ones.
This commit is contained in:
@@ -254,6 +254,32 @@ WASM_API_EXTERN own wasmtime_error_t *wasmtime_module_validate(
|
||||
const wasm_byte_vec_t *binary
|
||||
);
|
||||
|
||||
|
||||
// Similar to `wasm_table_*`, except these explicitly operate on funcref tables
|
||||
// and work with `wasm_func_t` values instead of `wasm_ref_t`.
|
||||
WASM_API_EXTERN own wasmtime_error_t *wasmtime_funcref_table_new(
|
||||
wasm_store_t *store,
|
||||
const wasm_tabletype_t *element_ty,
|
||||
wasm_func_t *init,
|
||||
own wasm_table_t **table
|
||||
);
|
||||
WASM_API_EXTERN bool wasmtime_funcref_table_get(
|
||||
const wasm_table_t *table,
|
||||
wasm_table_size_t index,
|
||||
own wasm_func_t **func
|
||||
);
|
||||
WASM_API_EXTERN own wasmtime_error_t *wasmtime_funcref_table_set(
|
||||
wasm_table_t *table,
|
||||
wasm_table_size_t index,
|
||||
const wasm_func_t *value
|
||||
);
|
||||
WASM_API_EXTERN wasmtime_error_t *wasmtime_funcref_table_grow(
|
||||
wasm_table_t *table,
|
||||
wasm_table_size_t delta,
|
||||
const wasm_func_t *init,
|
||||
wasm_table_size_t *prev_size
|
||||
);
|
||||
|
||||
#undef own
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user