-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I wanted to write down something that irks me when working with Wasmtime's C/C++ API that I've noticed recently. It boils down to basically the handling of lists throughout the API is pretty inconsistent and varies place-to-place in terms of ownership, semantics, representation, and performance. For example:
wasm_module_importsfills outwasm_importtype_vec_t*which the caller needs to deallocate.wasm_functype_paramsreturnsconst wasm_valtype_vec_t*owned by the callee.wasmtime_instance_export_nthis an iterator-style API of walking over a list (as opposed to returning a list)wasm_module_newtakes a byte list parameter asconst wasm_byte_vec_t*wasmtime_module_newtakes a byte list parameter as a ptr/len combowasm_func_callback_ttakes arguments asconst wasm_val_vec_t*and fills outwasm_val_vec_t*as a returnwasmtime_func_callback_ttakes arguments/results as ptr/len combos
Much, if not most, of this is wasm.h idioms clashing with what's natural to implement in Wasmtime. Wasmtime internally has some inconsistencies too, however -- in #11937 the wasmtime Rust API for getting the types of a function's parameters means that the result looks quite different than other C APIs.
On one hand this is wasm.h-vs-not, but the way we've designed the C API right now is that it's not possible to avoid using wasm.h so users are forced to deal with this no matter what. That's not great, in my opinion, so I wanted to file this issue.