A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Clarify that wasm_valtype_kind cannot represent v128 (#15235)
Christopher Onyiuke94b2600c4fd2
diff --git a/crates/c-api/include/doc-wasm.h b/crates/c-api/include/doc-wasm.hindex a364d6d51d..1b431f9a2c 100644--- a/crates/c-api/include/doc-wasm.h+++ b/crates/c-api/include/doc-wasm.h@@ -295,6 +295,11 @@* \fn wasm_valtype_t* wasm_valtype_new(wasm_valkind_t);* \brief Creates a new value type from the specified kind.*+ * Aborts the process if the kind is not `i32`, `i64`, `f32`, `f64`, `externref`+ * or `funcref`, since #wasm_valkind_t cannot represent any other value type.+ * Use #wasmtime_wasm_valtype_v128 for `v128` types and #wasmtime_valtype_to_wasm+ * for other reference types.+ ** The caller is responsible for deleting the returned value.** \fn wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t *);@@ -302,6 +307,9 @@** Aborts the process if this is a `v128` type or a reference type other than* `externref` and `funcref`, which have no #wasm_valkind_t.+ *+ * Use #wasmtime_valtype_t, created with #wasmtime_valtype_new, to inspect a+ * value type that #wasm_valkind_t cannot represent.*//**diff --git a/crates/c-api/include/wasmtime/types/val.h b/crates/c-api/include/wasmtime/types/val.hindex 9b455d9411..42517a9046 100644--- a/crates/c-api/include/wasmtime/types/val.h+++ b/crates/c-api/include/wasmtime/types/val.h@@ -133,6 +133,11 @@ typedef struct wasmtime_valtype {} wasmtime_valtype_t;/// \brief Creates a new type in `out` from the type in `ty`.+///+/// #wasmtime_valtype_t can represent every value type Wasmtime supports, while+/// #wasm_valtype_kind aborts for `v128` and for reference types other than+/// `externref` and `funcref`. Use this function to inspect the latter through+/// the `WASMTIME_VALTYPE_KIND_*` constants.WASM_API_EXTERN void wasmtime_valtype_new(const wasm_valtype_t *ty,wasmtime_valtype_t *out);diff --git a/crates/c-api/src/lib.rs b/crates/c-api/src/lib.rsindex 507dfc19c7..5d51729bb9 100644--- a/crates/c-api/src/lib.rs+++ b/crates/c-api/src/lib.rs@@ -150,3 +150,12 @@ pub(crate) fn abort(name: &str) -> ! {eprintln!("`{name}` is not implemented");std::process::abort();}++/// Aborts the process after printing `message` to stderr.+///+/// Unlike [`abort`], which reports a function that is not implemented, this is+/// for functions that are implemented but cannot represent their input.+pub(crate) fn abort_unsupported(message: &str) -> ! {+ eprintln!("{message}");+ std::process::abort();+}diff --git a/crates/c-api/src/types/val.rs b/crates/c-api/src/types/val.rsindex 57a37d999c..a02b3a8aca 100644--- a/crates/c-api/src/types/val.rs+++ b/crates/c-api/src/types/val.rs@@ -34,13 +34,16 @@ pub extern "C" fn wasm_valtype_kind(vt: &wasm_valtype_t) -> wasm_valkind_t {ValType::I64 => WASM_I64,ValType::F32 => WASM_F32,ValType::F64 => WASM_F64,- // TODO- ValType::V128 => crate::abort("support for v128 "),+ ValType::V128 => crate::abort_unsupported(+ "`wasm_valtype_kind` cannot represent `v128`, use `wasmtime_valtype_new` instead",+ ),ValType::Ref(r) => match (r.is_nullable(), r.heap_type()) {(true, HeapType::Extern) => WASM_EXTERNREF,(true, HeapType::Func) => WASM_FUNCREF,- // TODO- _ => crate::abort("support for non-externref and non-funcref references"),+ _ => crate::abort_unsupported(+ "`wasm_valtype_kind` cannot represent reference types other than \+ `externref` and `funcref`, use `wasmtime_valtype_new` instead",+ ),},}}