Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Some miscellaneous C API improvements (#13191)

Alex Crichton9c0346ac6df9
diff --git a/crates/c-api/include/wasmtime/_eqref_class.hh b/crates/c-api/include/wasmtime/_eqref_class.hh
index 6665dbee15..e3cba1d51e 100644
--- a/crates/c-api/include/wasmtime/_eqref_class.hh
+++ b/crates/c-api/include/wasmtime/_eqref_class.hh
@@ -1,6 +1,7 @@
#ifndef WASMTIME_EQREF_CLASS_HH
#define WASMTIME_EQREF_CLASS_HH
+#include <optional>
#include <wasmtime/conf.h>
#ifdef WASMTIME_FEATURE_GC
@@ -74,12 +75,12 @@ public:
/// Downcast this `eqref` into a `structref`.
//
// as_struct() defined after StructRef below.
- StructRef as_struct(Store::Context cx) const;
+ std::optional<StructRef> as_struct(Store::Context cx) const;
/// Downcast this `eqref` into an `arrayref`.
//
// as_array() defined after ArrayRef below.
- ArrayRef as_array(Store::Context cx) const;
+ std::optional<ArrayRef> as_array(Store::Context cx) const;
};
} // namespace wasmtime
diff --git a/crates/c-api/include/wasmtime/async.h b/crates/c-api/include/wasmtime/async.h
index 9ac7588888..d65dedd089 100644
--- a/crates/c-api/include/wasmtime/async.h
+++ b/crates/c-api/include/wasmtime/async.h
@@ -65,7 +65,7 @@ extern "C" {
* For more information see the Rust documentation at
* https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.async_stack_size
*/
-WASMTIME_CONFIG_PROP(void, async_stack_size, uint64_t)
+WASMTIME_CONFIG_PROP(void, async_stack_size, size_t)
/**
* \brief Configures a Store to yield execution of async WebAssembly code
@@ -184,7 +184,7 @@ typedef struct wasmtime_call_future wasmtime_call_future_t;
WASM_API_EXTERN bool wasmtime_call_future_poll(wasmtime_call_future_t *future);
/**
- * /brief Frees the underlying memory for a future.
+ * \brief Frees the underlying memory for a future.
*
* All wasmtime_call_future_t are owned by the caller and should be deleted
* using this function.
diff --git a/crates/c-api/include/wasmtime/component/component.h b/crates/c-api/include/wasmtime/component/component.h
index de22e7fd2b..ae79a334fb 100644
--- a/crates/c-api/include/wasmtime/component/component.h
+++ b/crates/c-api/include/wasmtime/component/component.h
@@ -106,7 +106,7 @@ wasmtime_component_clone(const wasmtime_component_t *component);
/**
* \brief Returns the type of this component.
*
- * The returned pointer must be deallocatd with
+ * The returned pointer must be deallocated with
* `wasmtime_component_type_delete`.
*/
WASM_API_EXTERN wasmtime_component_type_t *
diff --git a/crates/c-api/include/wasmtime/component/component.hh b/crates/c-api/include/wasmtime/component/component.hh
index 10df55abb0..76e36ef912 100644
--- a/crates/c-api/include/wasmtime/component/component.hh
+++ b/crates/c-api/include/wasmtime/component/component.hh
@@ -153,8 +153,8 @@ class Component {
* The `instance` argument is an optionally provided index which is the
* instance under which the `name` should be looked up.
*/
- std::optional<ExportIndex> export_index(ExportIndex *instance,
- std::string_view name) {
+ std::optional<ExportIndex> export_index(const ExportIndex *instance,
+ std::string_view name) const {
auto ret = wasmtime_component_get_export_index(
capi(), instance ? instance->capi() : nullptr, name.data(),
name.size());
diff --git a/crates/c-api/include/wasmtime/component/func.hh b/crates/c-api/include/wasmtime/component/func.hh
index 12437787d2..539b8e1cab 100644
--- a/crates/c-api/include/wasmtime/component/func.hh
+++ b/crates/c-api/include/wasmtime/component/func.hh
@@ -19,7 +19,7 @@ namespace wasmtime {
namespace component {
/**
- * \brief Class representing an instantiated WebAssembly component.
+ * \brief Class representing a WebAssembly component function.
*/
class Func {
wasmtime_component_func_t func;
@@ -67,4 +67,4 @@ public:
#endif // WASMTIME_FEATURE_COMPONENT_MODEL
-#endif // WASMTIME_COMPONENT_FUNC_H
+#endif // WASMTIME_COMPONENT_FUNC_HH
diff --git a/crates/c-api/include/wasmtime/component/instance.hh b/crates/c-api/include/wasmtime/component/instance.hh
index 07f7f91c89..da35f965af 100644
--- a/crates/c-api/include/wasmtime/component/instance.hh
+++ b/crates/c-api/include/wasmtime/component/instance.hh
@@ -67,4 +67,4 @@ public:
#endif // WASMTIME_FEATURE_COMPONENT_MODEL
-#endif // WASMTIME_COMPONENT_INSTANCE_H
+#endif // WASMTIME_COMPONENT_INSTANCE_HH
diff --git a/crates/c-api/include/wasmtime/component/linker.hh b/crates/c-api/include/wasmtime/component/linker.hh
index f0f847ed51..b65ff8639b 100644
--- a/crates/c-api/include/wasmtime/component/linker.hh
+++ b/crates/c-api/include/wasmtime/component/linker.hh
@@ -31,7 +31,8 @@ class LinkerInstance {
/**
* \brief Adds a module to this linker instance under the specified name.
*/
- Result<std::monostate> add_module(std::string_view name, Module &module) {
+ Result<std::monostate> add_module(std::string_view name,
+ const Module &module) {
wasmtime_error_t *error = wasmtime_component_linker_instance_add_module(
ptr.get(), name.data(), name.size(), module.capi());
if (error != nullptr) {
@@ -188,7 +189,7 @@ class Linker {
}
/// \brief Instantiates the given component within this linker.
- Result<Instance> instantiate(Store::Context cx, Component &component) {
+ Result<Instance> instantiate(Store::Context cx, const Component &component) {
wasmtime_component_instance_t ret;
wasmtime_error_t *error = wasmtime_component_linker_instantiate(
ptr.get(), cx.capi(), component.capi(), &ret);
@@ -277,4 +278,4 @@ class Linker {
#endif // WASMTIME_FEATURE_COMPONENT_MODEL
-#endif // WASMTIME_COMPONENT_LINKER_H
+#endif // WASMTIME_COMPONENT_LINKER_HH
diff --git a/crates/c-api/include/wasmtime/component/types/component.h b/crates/c-api/include/wasmtime/component/types/component.h
index 246495ab10..aea22f4178 100644
--- a/crates/c-api/include/wasmtime/component/types/component.h
+++ b/crates/c-api/include/wasmtime/component/types/component.h
@@ -23,8 +23,8 @@ typedef struct wasmtime_component_type_t wasmtime_component_type_t;
/// \brief Clones a component type.
///
-/// The returned pointer must be deallocated wit
-/// h`wasmtime_component_type_delete`.
+/// The returned pointer must be deallocated with
+/// `wasmtime_component_type_delete`.
WASM_API_EXTERN
wasmtime_component_type_t *
wasmtime_component_type_clone(const wasmtime_component_type_t *ty);
diff --git a/crates/c-api/include/wasmtime/component/types/func.h b/crates/c-api/include/wasmtime/component/types/func.h
index db49f0af80..a9a6ba016b 100644
--- a/crates/c-api/include/wasmtime/component/types/func.h
+++ b/crates/c-api/include/wasmtime/component/types/func.h
@@ -25,7 +25,7 @@ WASM_API_EXTERN
wasmtime_component_func_type_t *
wasmtime_component_func_type_clone(const wasmtime_component_func_type_t *ty);
-/// \brief Deallocates a component instance type.
+/// \brief Deallocates a component function type.
WASM_API_EXTERN
void wasmtime_component_func_type_delete(wasmtime_component_func_type_t *ty);
diff --git a/crates/c-api/include/wasmtime/component/types/module.h b/crates/c-api/include/wasmtime/component/types/module.h
index 117d9a413d..456b75e902 100644
--- a/crates/c-api/include/wasmtime/component/types/module.h
+++ b/crates/c-api/include/wasmtime/component/types/module.h
@@ -24,7 +24,7 @@ WASM_API_EXTERN
wasmtime_module_type_t *
wasmtime_module_type_clone(const wasmtime_module_type_t *ty);
-/// \brief Deallocates a component instance type.
+/// \brief Deallocates a module type.
WASM_API_EXTERN
void wasmtime_module_type_delete(wasmtime_module_type_t *ty);
diff --git a/crates/c-api/include/wasmtime/component/val.hh b/crates/c-api/include/wasmtime/component/val.hh
index 1ff5c9a5be..93a55e7689 100644
--- a/crates/c-api/include/wasmtime/component/val.hh
+++ b/crates/c-api/include/wasmtime/component/val.hh
@@ -992,4 +992,4 @@ inline WitResult WitResult::err(std::optional<Val> v) {
#endif // WASMTIME_FEATURE_COMPONENT_MODEL
-#endif // WASMTIME_COMPONENT_VAL_H
+#endif // WASMTIME_COMPONENT_VAL_HH
diff --git a/crates/c-api/include/wasmtime/config.h b/crates/c-api/include/wasmtime/config.h
index adbe89be37..1aa02912a7 100644
--- a/crates/c-api/include/wasmtime/config.h
+++ b/crates/c-api/include/wasmtime/config.h
@@ -206,6 +206,8 @@ WASMTIME_CONFIG_PROP(void, shared_memory, bool)
*/
WASMTIME_CONFIG_PROP(void, wasm_tail_call, bool)
+#ifdef WASMTIME_FEATURE_GC
+
/**
* \brief Configures whether the WebAssembly reference types proposal is
* enabled.
@@ -229,6 +231,8 @@ WASMTIME_CONFIG_PROP(void, wasm_function_references, bool)
*/
WASMTIME_CONFIG_PROP(void, wasm_gc, bool)
+#endif // WASMTIME_FEATURE_GC
+
/**
* \brief Enables or disables GC support in Wasmtime entirely.
*
@@ -301,6 +305,8 @@ WASMTIME_CONFIG_PROP(void, wasm_memory64, bool)
*/
WASMTIME_CONFIG_PROP(void, wasm_wide_arithmetic, bool)
+#ifdef WASMTIME_FEATURE_GC
+
/**
* \brief Configures whether the WebAssembly exceptions proposal is enabled.
*
@@ -308,6 +314,8 @@ WASMTIME_CONFIG_PROP(void, wasm_wide_arithmetic, bool)
*/
WASMTIME_CONFIG_PROP(void, wasm_exceptions, bool)
+#endif // WASMTIME_FEATURE_GC
+
/**
* \brief Configures whether the WebAssembly custom-page-sizes proposal is
* enabled.
diff --git a/crates/c-api/include/wasmtime/config.hh b/crates/c-api/include/wasmtime/config.hh
index ba5d6c9770..601100d971 100644
--- a/crates/c-api/include/wasmtime/config.hh
+++ b/crates/c-api/include/wasmtime/config.hh
@@ -397,6 +397,7 @@ class Config {
void wasm_gc(bool enable) { wasmtime_config_wasm_gc_set(ptr.get(), enable); }
#endif // WASMTIME_FEATURE_GC
+#ifdef WASMTIME_FEATURE_GC
/// \brief Configures whether the WebAssembly function references proposal
/// will be enabled
///
@@ -404,6 +405,7 @@ class Config {
void wasm_function_references(bool enable) {
wasmtime_config_wasm_function_references_set(ptr.get(), enable);
}
+#endif // WASMTIME_FEATURE_GC
/// \brief Configures whether the WebAssembly wide arithmetic proposal will be
/// enabled
@@ -524,7 +526,7 @@ class Config {
/// \brief Configures the size of the initial linear memory allocation.
///
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.memory_reservation
- void memory_reservation(size_t size) {
+ void memory_reservation(uint64_t size) {
wasmtime_config_memory_reservation_set(ptr.get(), size);
}
@@ -532,14 +534,14 @@ class Config {
/// linear memory to grow into.
///
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.memory_reservation_for_growth
- void memory_reservation_for_growth(size_t size) {
+ void memory_reservation_for_growth(uint64_t size) {
wasmtime_config_memory_reservation_for_growth_set(ptr.get(), size);
}
/// \brief Configures the size of memory's guard region
///
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.memory_guard_size
- void memory_guard_size(size_t size) {
+ void memory_guard_size(uint64_t size) {
wasmtime_config_memory_guard_size_set(ptr.get(), size);
}
@@ -668,6 +670,7 @@ public:
}
#endif // WASMTIME_FEATURE_POOLING_ALLOCATOR
+#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
/**
* \brief Specifies whether support for concurrent execution of WebAssembly is
* supported within this store.
@@ -678,6 +681,38 @@ public:
void concurrency_support(bool enable) {
wasmtime_config_concurrency_support_set(ptr.get(), enable);
}
+#endif // WASMTIME_FEATURE_COMPONENT_MODEL
+
+#ifdef WASMTIME_FEATURE_COMPONENT_MODEL_ASYNC
+ /**
+ * \brief Configures whether component-model async support is enabled.
+ *
+ * https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_component_model_async
+ */
+ void wasm_component_model_async(bool enable) {
+ wasmtime_config_wasm_component_model_async_set(ptr.get(), enable);
+ }
+
+ /**
+ * \brief Configures whether async built-in intrinsics are enabled for the
+ * component model.
+ *
+ * https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_component_model_async_builtins
+ */
+ void wasm_component_model_async_builtins(bool enable) {
+ wasmtime_config_wasm_component_model_async_builtins_set(ptr.get(), enable);
+ }
+
+ /**
+ * \brief Configures whether stackful coroutine support is enabled for async
+ * components.
+ *
+ * https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_component_model_async_stackful
+ */
+ void wasm_component_model_async_stackful(bool enable) {
+ wasmtime_config_wasm_component_model_async_stackful_set(ptr.get(), enable);
+ }
+#endif // WASMTIME_FEATURE_COMPONENT_MODEL_ASYNC
};
} // namespace wasmtime
diff --git a/crates/c-api/include/wasmtime/engine.h b/crates/c-api/include/wasmtime/engine.h
index 4695b59271..e198fcf2a1 100644
--- a/crates/c-api/include/wasmtime/engine.h
+++ b/crates/c-api/include/wasmtime/engine.h
@@ -19,7 +19,8 @@ extern "C" {
* This function clones the reference-counted pointer to the internal object,
* and must be freed using #wasm_engine_delete.
*/
-WASM_API_EXTERN wasm_engine_t *wasmtime_engine_clone(wasm_engine_t *engine);
+WASM_API_EXTERN wasm_engine_t *
+wasmtime_engine_clone(const wasm_engine_t *engine);
/**
* \brief Increments the engine-local epoch variable.
@@ -33,13 +34,14 @@ WASM_API_EXTERN wasm_engine_t *wasmtime_engine_clone(wasm_engine_t *engine);
*
* See also #wasmtime_config_epoch_interruption_set.
*/
-WASM_API_EXTERN void wasmtime_engine_increment_epoch(wasm_engine_t *engine);
+WASM_API_EXTERN void
+wasmtime_engine_increment_epoch(const wasm_engine_t *engine);
/**
* \brief Returns whether this engine is using the Pulley interpreter to execute
* WebAssembly code.
*/
-WASM_API_EXTERN bool wasmtime_engine_is_pulley(wasm_engine_t *engine);
+WASM_API_EXTERN bool wasmtime_engine_is_pulley(const wasm_engine_t *engine);
#ifdef __cplusplus
} // extern "C"
diff --git a/crates/c-api/include/wasmtime/engine.hh b/crates/c-api/include/wasmtime/engine.hh
index ab9f8ac2fc..c8682c22f0 100644
--- a/crates/c-api/include/wasmtime/engine.hh
+++ b/crates/c-api/include/wasmtime/engine.hh
@@ -37,7 +37,7 @@ class Engine {
void increment_epoch() const { wasmtime_engine_increment_epoch(ptr.get()); }
/// \brief Returns whether this engine is using Pulley for execution.
- void is_pulley() const { wasmtime_engine_is_pulley(ptr.get()); }
+ bool is_pulley() const { return wasmtime_engine_is_pulley(ptr.get()); }
};
} // namespace wasmtime
diff --git a/crates/c-api/include/wasmtime/eqref.hh b/crates/c-api/include/wasmtime/eqref.hh
index 5ac8e9fe7f..938aedac82 100644
--- a/crates/c-api/include/wasmtime/eqref.hh
+++ b/crates/c-api/include/wasmtime/eqref.hh
@@ -15,16 +15,18 @@
namespace wasmtime {
-inline StructRef EqRef::as_struct(Store::Context cx) const {
+inline std::optional<StructRef> EqRef::as_struct(Store::Context cx) const {
wasmtime_structref_t out;
- wasmtime_eqref_as_struct(cx.capi(), &raw, &out);
- return StructRef(out);
+ if (wasmtime_eqref_as_struct(cx.capi(), &raw, &out))
+ return StructRef(out);
+ return std::nullopt;
}
-inline ArrayRef EqRef::as_array(Store::Context cx) const {
+inline std::optional<ArrayRef> EqRef::as_array(Store::Context cx) const {
wasmtime_arrayref_t out;
- wasmtime_eqref_as_array(cx.capi(), &raw, &out);
- return ArrayRef(out);
+ if (wasmtime_eqref_as_array(cx.capi(), &raw, &out))
+ return ArrayRef(out);
+ return std::nullopt;
}
inline AnyRef EqRef::to_anyref() const {
diff --git a/crates/c-api/include/wasmtime/error.hh b/crates/c-api/include/wasmtime/error.hh
index 91c9bae12a..447d08ae9c 100644
--- a/crates/c-api/include/wasmtime/error.hh
+++ b/crates/c-api/include/wasmtime/error.hh
@@ -96,16 +96,16 @@ public:
const T &ok_ref() const { return std::get<T>(data); }
/// \brief Returns the error, if present, aborts if this is not an error.
- E &err_ref() { return std::get<T>(data); }
+ E &err_ref() { return std::get<E>(data); }
/// \brief Returns the error, if present, aborts if this is not an error.
- const E &err_ref() const { return std::get<T>(data); }
+ const E &err_ref() const { return std::get<E>(data); }
/// \brief Returns the success, if present, aborts if this is an error.
T unwrap() {
- if (*this) {
- return this->ok();
+ if (!*this) {
+ unwrap_failed();
}
- unwrap_failed();
+ return this->ok();
}
private:
diff --git a/crates/c-api/include/wasmtime/extern.h b/crates/c-api/include/wasmtime/extern.h
index 113d1e22e9..4c7d976f3b 100644
--- a/crates/c-api/include/wasmtime/extern.h
+++ b/crates/c-api/include/wasmtime/extern.h
@@ -156,15 +156,15 @@ typedef struct wasmtime_extern {
} wasmtime_extern_t;
/// \brief Deletes a #wasmtime_extern_t.
-void wasmtime_extern_delete(wasmtime_extern_t *val);
+WASM_API_EXTERN void wasmtime_extern_delete(wasmtime_extern_t *val);
/// \brief Returns the type of the #wasmtime_extern_t defined within the given
/// store.
///
/// Does not take ownership of `context` or `val`, but the returned
/// #wasm_externtype_t is an owned value that needs to be deleted.
-wasm_externtype_t *wasmtime_extern_type(wasmtime_context_t *context,
- wasmtime_extern_t *val);
+WASM_API_EXTERN wasm_externtype_t *
+wasmtime_extern_type(wasmtime_context_t *context, const wasmtime_extern_t *val);
#ifdef __cplusplus
} // extern "C"
diff --git a/crates/c-api/include/wasmtime/global.h b/crates/c-api/include/wasmtime/global.h
index 8b20af9150..e851d0c7d7 100644
--- a/crates/c-api/include/wasmtime/global.h
+++ b/crates/c-api/include/wasmtime/global.h
@@ -70,7 +70,7 @@ WASM_API_EXTERN void wasmtime_global_get(wasmtime_context_t *store,
* This function may return an error if `global` is not mutable or if `val` has
* the wrong type for `global`.
*
- * THis does not take ownership of any argument but returns ownership of the
+ * This does not take ownership of any argument but returns ownership of the
* error.
*/
WASM_API_EXTERN wasmtime_error_t *
diff --git a/crates/c-api/include/wasmtime/instance.h b/crates/c-api/include/wasmtime/instance.h
index db65ea87c7..4900112839 100644
--- a/crates/c-api/include/wasmtime/instance.h
+++ b/crates/c-api/include/wasmtime/instance.h
@@ -160,7 +160,7 @@ WASM_API_EXTERN wasmtime_error_t *wasmtime_instance_pre_instantiate(
* delete it via `wasmtime_module_delete`.
*/
WASM_API_EXTERN wasmtime_module_t *
-wasmtime_instance_pre_module(wasmtime_instance_pre_t *instance_pre);
+wasmtime_instance_pre_module(const wasmtime_instance_pre_t *instance_pre);
#ifdef __cplusplus
} // extern "C"
diff --git a/crates/c-api/include/wasmtime/linker.h b/crates/c-api/include/wasmtime/linker.h
index e58dcadfb5..f3bb0a19de 100644
--- a/crates/c-api/include/wasmtime/linker.h
+++ b/crates/c-api/include/wasmtime/linker.h
@@ -52,7 +52,7 @@ WASM_API_EXTERN wasmtime_linker_t *wasmtime_linker_new(wasm_engine_t *engine);
* is expected to delete the returned linker.
*/
WASM_API_EXTERN wasmtime_linker_t *
-wasmtime_linker_clone(wasmtime_linker_t *linker);
+wasmtime_linker_clone(const wasmtime_linker_t *linker);
/**
* \brief Deletes a linker
@@ -73,8 +73,8 @@ WASM_API_EXTERN void wasmtime_linker_allow_shadowing(wasmtime_linker_t *linker,
* all functions otherwise missing from this linker to trap.
*/
WASM_API_EXTERN wasmtime_error_t *
-wasmtime_linker_define_unknown_imports_as_traps(wasmtime_linker_t *linker,
- wasmtime_module_t *module);
+wasmtime_linker_define_unknown_imports_as_traps(
+ wasmtime_linker_t *linker, const wasmtime_module_t *module);
/**
* \brief Ensures that `module` can be instantiated with this linker by defining
@@ -84,7 +84,7 @@ wasmtime_linker_define_unknown_imports_as_traps(wasmtime_linker_t *linker,
WASM_API_EXTERN wasmtime_error_t *
wasmtime_linker_define_unknown_imports_as_default_values(
wasmtime_linker_t *linker, wasmtime_context_t *store,
- wasmtime_module_t *module);
+ const wasmtime_module_t *module);
/**
* \brief Defines a new item in this linker.
diff --git a/crates/c-api/include/wasmtime/linker.hh b/crates/c-api/include/wasmtime/linker.hh
index d0caca235e..86f93f8d0f 100644
--- a/crates/c-api/include/wasmtime/linker.hh
+++ b/crates/c-api/include/wasmtime/linker.hh
@@ -180,7 +180,7 @@ class Linker {
/// \brief Defines any import of `module` previously unknown to this linker
/// as a trap.
- Result<std::monostate> define_unknown_imports_as_traps(Module &module) {
+ Result<std::monostate> define_unknown_imports_as_traps(const Module &module) {
auto *error = wasmtime_linker_define_unknown_imports_as_traps(
ptr.get(), module.capi());
if (error != nullptr) {
@@ -193,7 +193,8 @@ class Linker {
/// as the "default" value for that import, for example a function that
/// returns zeros.
Result<std::monostate>
- define_unknown_imports_as_default_values(Store::Context cx, Module &module) {
+ define_unknown_imports_as_default_values(Store::Context cx,
+ const Module &module) {
auto *error = wasmtime_linker_define_unknown_imports_as_default_values(
ptr.get(), cx.ptr, module.capi());
if (error != nullptr) {
diff --git a/crates/c-api/include/wasmtime/memory.h b/crates/c-api/include/wasmtime/memory.h
index 2aac6b7289..221951e439 100644
--- a/crates/c-api/include/wasmtime/memory.h
+++ b/crates/c-api/include/wasmtime/memory.h
@@ -95,7 +95,7 @@ wasmtime_memory_type(const wasmtime_context_t *store,
/**
* \brief Returns the base pointer in memory where the linear memory starts.
*/
-WASM_API_EXTERN uint8_t *wasmtime_memory_data(const wasmtime_context_t *store,
+WASM_API_EXTERN uint8_t *wasmtime_memory_data(wasmtime_context_t *store,
const wasmtime_memory_t *memory);
/**
diff --git a/crates/c-api/include/wasmtime/memory.hh b/crates/c-api/include/wasmtime/memory.hh
index 364f23e0a8..a08c0698f9 100644
--- a/crates/c-api/include/wasmtime/memory.hh
+++ b/crates/c-api/include/wasmtime/memory.hh
@@ -21,7 +21,7 @@ namespace wasmtime {
*
* Note that this type does not itself own any resources. It points to resources
* owned within a `Store` and the `Store` must be passed in as the first
- * argument to the functions defined on `Table`. Note that if the wrong `Store`
+ * argument to the functions defined on `Memory`. Note that if the wrong `Store`
* is passed in then the process will be aborted.
*/
class Memory {
diff --git a/crates/c-api/include/wasmtime/module.h b/crates/c-api/include/wasmtime/module.h
index 7f42432cf8..e9552949f9 100644
--- a/crates/c-api/include/wasmtime/module.h
+++ b/crates/c-api/include/wasmtime/module.h
@@ -60,7 +60,8 @@ WASM_API_EXTERN void wasmtime_module_delete(wasmtime_module_t *m);
* \brief Creates a shallow clone of the specified module, increasing the
* internal reference count.
*/
-WASM_API_EXTERN wasmtime_module_t *wasmtime_module_clone(wasmtime_module_t *m);
+WASM_API_EXTERN wasmtime_module_t *
+wasmtime_module_clone(const wasmtime_module_t *m);
/**
* \brief Same as #wasm_module_imports, but for #wasmtime_module_t.
@@ -106,7 +107,8 @@ wasmtime_module_validate(wasm_engine_t *engine, const uint8_t *wasm,
* expected to deallocate the returned #wasmtime_error_t and #wasm_byte_vec_t.
*/
WASM_API_EXTERN wasmtime_error_t *
-wasmtime_module_serialize(wasmtime_module_t *module, wasm_byte_vec_t *ret);
+wasmtime_module_serialize(const wasmtime_module_t *module,
+ wasm_byte_vec_t *ret);
#endif // WASMTIME_FEATURE_COMPILER
diff --git a/crates/c-api/include/wasmtime/types/export.hh b/crates/c-api/include/wasmtime/types/export.hh
index 80d7ac957e..d326e81c8e 100644
--- a/crates/c-api/include/wasmtime/types/export.hh
+++ b/crates/c-api/include/wasmtime/types/export.hh
@@ -28,14 +28,16 @@ class ExportType {
const wasm_exporttype_t *ptr;
- const wasm_externtype_t *raw_type() { return wasm_exporttype_type(ptr); }
+ const wasm_externtype_t *raw_type() const {
+ return wasm_exporttype_type(ptr);
+ }
public:
/// Creates a new reference from the raw underlying C API representation.
Ref(const wasm_exporttype_t *ptr) : ptr(ptr) {}
/// Returns the name of this export.
- std::string_view name() {
+ std::string_view name() const {
const auto *name = wasm_exporttype_name(ptr);
return std::string_view(name->data, name->size);
}
diff --git a/crates/c-api/include/wasmtime/types/import.hh b/crates/c-api/include/wasmtime/types/import.hh
index efc20873f5..2432923bba 100644
--- a/crates/c-api/include/wasmtime/types/import.hh
+++ b/crates/c-api/include/wasmtime/types/import.hh
@@ -28,20 +28,22 @@ class ImportType {
const wasm_importtype_t *ptr;
// TODO: can this circle be broken another way?
- const wasm_externtype_t *raw_type() { return wasm_importtype_type(ptr); }
+ const wasm_externtype_t *raw_type() const {
+ return wasm_importtype_type(ptr);
+ }
public:
/// Creates a new reference from the raw underlying C API representation.
Ref(const wasm_importtype_t *ptr) : ptr(ptr) {}
/// Returns the module name associated with this import.
- std::string_view module() {
+ std::string_view module() const {
const auto *name = wasm_importtype_module(ptr);
return std::string_view(name->data, name->size);
}
/// Returns the field name associated with this import.
- std::string_view name() {
+ std::string_view name() const {
const auto *name = wasm_importtype_name(ptr);
return std::string_view(name->data, name->size);
}
diff --git a/crates/c-api/include/wasmtime/wasi.hh b/crates/c-api/include/wasmtime/wasi.hh
index 7f972d41ba..034554e3c1 100644
--- a/crates/c-api/include/wasmtime/wasi.hh
+++ b/crates/c-api/include/wasmtime/wasi.hh
@@ -35,7 +35,7 @@ class WasiConfig {
ptrs.push_back(arg.c_str());
}
- wasi_config_set_argv(ptr.get(), (int)args.size(), ptrs.data());
+ wasi_config_set_argv(ptr.get(), args.size(), ptrs.data());
}
/// Configures the argv for wasm to be inherited from this process itself.
@@ -51,8 +51,7 @@ class WasiConfig {
names.push_back(name.c_str());
values.push_back(value.c_str());
}
- wasi_config_set_env(ptr.get(), (int)env.size(), names.data(),
- values.data());
+ wasi_config_set_env(ptr.get(), env.size(), names.data(), values.data());
}
/// Indicates that the entire environment of this process should be inherited
@@ -67,7 +66,7 @@ class WasiConfig {
/// Configures this WASI configuration to inherit its stdin from the host
/// process.
- void inherit_stdin() { return wasi_config_inherit_stdin(ptr.get()); }
+ void inherit_stdin() { wasi_config_inherit_stdin(ptr.get()); }
/// Configures the provided file to be created and all stdout output will be
/// written there.
@@ -77,7 +76,7 @@ class WasiConfig {
/// Configures this WASI configuration to inherit its stdout from the host
/// process.
- void inherit_stdout() { return wasi_config_inherit_stdout(ptr.get()); }
+ void inherit_stdout() { wasi_config_inherit_stdout(ptr.get()); }
/// Configures the provided file to be created and all stderr output will be
/// written there.
@@ -85,9 +84,9 @@ class WasiConfig {
return wasi_config_set_stderr_file(ptr.get(), path.c_str());
}
- /// Configures this WASI configuration to inherit its stdout from the host
+ /// Configures this WASI configuration to inherit its stderr from the host
/// process.
- void inherit_stderr() { return wasi_config_inherit_stderr(ptr.get()); }
+ void inherit_stderr() { wasi_config_inherit_stderr(ptr.get()); }
/// Opens `path` to be opened as `guest_path` in the WASI pseudo-filesystem.
[[nodiscard]] bool preopen_dir(const std::string &path,
@@ -96,6 +95,14 @@ class WasiConfig {
return wasi_config_preopen_dir(ptr.get(), path.c_str(), guest_path.c_str(),
dir_perms, file_perms);
}
+
+ /// Allows all network addresses accessible to the host.
+ void inherit_network() { wasi_config_inherit_network(ptr.get()); }
+
+ /// Configures whether `wasi:sockets/ip-name-lookup` is allowed.
+ void allow_ip_name_lookup(bool enable) {
+ wasi_config_allow_ip_name_lookup(ptr.get(), enable);
+ }
};
} // namespace wasmtime
diff --git a/crates/c-api/src/memory.rs b/crates/c-api/src/memory.rs
index 4c6b2fc685..0ef454caeb 100644
--- a/crates/c-api/src/memory.rs
+++ b/crates/c-api/src/memory.rs
@@ -104,8 +104,11 @@ pub extern "C" fn wasmtime_memory_type(
}
#[unsafe(no_mangle)]
-pub extern "C" fn wasmtime_memory_data(store: WasmtimeStoreContext<'_>, mem: &Memory) -> *const u8 {
- mem.data(store).as_ptr()
+pub extern "C" fn wasmtime_memory_data(
+ store: WasmtimeStoreContextMut<'_>,
+ mem: &Memory,
+) -> *const u8 {
+ mem.data_mut(store).as_ptr()
}
#[unsafe(no_mangle)]
diff --git a/crates/c-api/tests/gc.cc b/crates/c-api/tests/gc.cc
index d4889cb5f6..68e24511a5 100644
--- a/crates/c-api/tests/gc.cc
+++ b/crates/c-api/tests/gc.cc
@@ -149,7 +149,9 @@ TEST(StructRef, UpcastAndDowncast) {
EXPECT_FALSE(eq.is_i31(cx));
// Downcast back to structref.
- StructRef s2 = eq.as_struct(cx);
+ auto s2_opt = eq.as_struct(cx);
+ ASSERT_TRUE(s2_opt.has_value());
+ StructRef s2 = *s2_opt;
auto v = s2.field(cx, 0);
ASSERT_TRUE(v);
EXPECT_EQ(v.ok().i32(), 99);
@@ -217,7 +219,9 @@ TEST(ArrayRef, UpcastAndDowncast) {
EXPECT_FALSE(eq.is_i31(cx));
// Downcast back to arrayref.
- ArrayRef arr2 = eq.as_array(cx);
+ auto arr2_opt = eq.as_array(cx);
+ ASSERT_TRUE(arr2_opt.has_value());
+ ArrayRef arr2 = *arr2_opt;
auto len = arr2.len(cx);
ASSERT_TRUE(len);
EXPECT_EQ(len.ok(), 3u);