Skip to content

Commit 9c0346a

Browse files
authored
Some miscellaneous C API improvements (#13191)
* Some miscellaneous C API improvements This commit goes through the C API and fixes a number of mistakes such as typos, copy/paste errors, missing `const`, etc. * Run clang-format
1 parent ad6d088 commit 9c0346a

30 files changed

Lines changed: 137 additions & 67 deletions

crates/c-api/include/wasmtime/_eqref_class.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef WASMTIME_EQREF_CLASS_HH
22
#define WASMTIME_EQREF_CLASS_HH
33

4+
#include <optional>
45
#include <wasmtime/conf.h>
56

67
#ifdef WASMTIME_FEATURE_GC
@@ -74,12 +75,12 @@ public:
7475
/// Downcast this `eqref` into a `structref`.
7576
//
7677
// as_struct() defined after StructRef below.
77-
StructRef as_struct(Store::Context cx) const;
78+
std::optional<StructRef> as_struct(Store::Context cx) const;
7879

7980
/// Downcast this `eqref` into an `arrayref`.
8081
//
8182
// as_array() defined after ArrayRef below.
82-
ArrayRef as_array(Store::Context cx) const;
83+
std::optional<ArrayRef> as_array(Store::Context cx) const;
8384
};
8485

8586
} // namespace wasmtime

crates/c-api/include/wasmtime/async.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extern "C" {
6565
* For more information see the Rust documentation at
6666
* https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.async_stack_size
6767
*/
68-
WASMTIME_CONFIG_PROP(void, async_stack_size, uint64_t)
68+
WASMTIME_CONFIG_PROP(void, async_stack_size, size_t)
6969

7070
/**
7171
* \brief Configures a Store to yield execution of async WebAssembly code
@@ -184,7 +184,7 @@ typedef struct wasmtime_call_future wasmtime_call_future_t;
184184
WASM_API_EXTERN bool wasmtime_call_future_poll(wasmtime_call_future_t *future);
185185

186186
/**
187-
* /brief Frees the underlying memory for a future.
187+
* \brief Frees the underlying memory for a future.
188188
*
189189
* All wasmtime_call_future_t are owned by the caller and should be deleted
190190
* using this function.

crates/c-api/include/wasmtime/component/component.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ wasmtime_component_clone(const wasmtime_component_t *component);
106106
/**
107107
* \brief Returns the type of this component.
108108
*
109-
* The returned pointer must be deallocatd with
109+
* The returned pointer must be deallocated with
110110
* `wasmtime_component_type_delete`.
111111
*/
112112
WASM_API_EXTERN wasmtime_component_type_t *

crates/c-api/include/wasmtime/component/component.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ class Component {
153153
* The `instance` argument is an optionally provided index which is the
154154
* instance under which the `name` should be looked up.
155155
*/
156-
std::optional<ExportIndex> export_index(ExportIndex *instance,
157-
std::string_view name) {
156+
std::optional<ExportIndex> export_index(const ExportIndex *instance,
157+
std::string_view name) const {
158158
auto ret = wasmtime_component_get_export_index(
159159
capi(), instance ? instance->capi() : nullptr, name.data(),
160160
name.size());

crates/c-api/include/wasmtime/component/func.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace wasmtime {
1919
namespace component {
2020

2121
/**
22-
* \brief Class representing an instantiated WebAssembly component.
22+
* \brief Class representing a WebAssembly component function.
2323
*/
2424
class Func {
2525
wasmtime_component_func_t func;
@@ -67,4 +67,4 @@ public:
6767

6868
#endif // WASMTIME_FEATURE_COMPONENT_MODEL
6969

70-
#endif // WASMTIME_COMPONENT_FUNC_H
70+
#endif // WASMTIME_COMPONENT_FUNC_HH

crates/c-api/include/wasmtime/component/instance.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ public:
6767

6868
#endif // WASMTIME_FEATURE_COMPONENT_MODEL
6969

70-
#endif // WASMTIME_COMPONENT_INSTANCE_H
70+
#endif // WASMTIME_COMPONENT_INSTANCE_HH

crates/c-api/include/wasmtime/component/linker.hh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class LinkerInstance {
3131
/**
3232
* \brief Adds a module to this linker instance under the specified name.
3333
*/
34-
Result<std::monostate> add_module(std::string_view name, Module &module) {
34+
Result<std::monostate> add_module(std::string_view name,
35+
const Module &module) {
3536
wasmtime_error_t *error = wasmtime_component_linker_instance_add_module(
3637
ptr.get(), name.data(), name.size(), module.capi());
3738
if (error != nullptr) {
@@ -188,7 +189,7 @@ class Linker {
188189
}
189190

190191
/// \brief Instantiates the given component within this linker.
191-
Result<Instance> instantiate(Store::Context cx, Component &component) {
192+
Result<Instance> instantiate(Store::Context cx, const Component &component) {
192193
wasmtime_component_instance_t ret;
193194
wasmtime_error_t *error = wasmtime_component_linker_instantiate(
194195
ptr.get(), cx.capi(), component.capi(), &ret);
@@ -277,4 +278,4 @@ class Linker {
277278

278279
#endif // WASMTIME_FEATURE_COMPONENT_MODEL
279280

280-
#endif // WASMTIME_COMPONENT_LINKER_H
281+
#endif // WASMTIME_COMPONENT_LINKER_HH

crates/c-api/include/wasmtime/component/types/component.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ typedef struct wasmtime_component_type_t wasmtime_component_type_t;
2323

2424
/// \brief Clones a component type.
2525
///
26-
/// The returned pointer must be deallocated wit
27-
/// h`wasmtime_component_type_delete`.
26+
/// The returned pointer must be deallocated with
27+
/// `wasmtime_component_type_delete`.
2828
WASM_API_EXTERN
2929
wasmtime_component_type_t *
3030
wasmtime_component_type_clone(const wasmtime_component_type_t *ty);

crates/c-api/include/wasmtime/component/types/func.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ WASM_API_EXTERN
2525
wasmtime_component_func_type_t *
2626
wasmtime_component_func_type_clone(const wasmtime_component_func_type_t *ty);
2727

28-
/// \brief Deallocates a component instance type.
28+
/// \brief Deallocates a component function type.
2929
WASM_API_EXTERN
3030
void wasmtime_component_func_type_delete(wasmtime_component_func_type_t *ty);
3131

crates/c-api/include/wasmtime/component/types/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ WASM_API_EXTERN
2424
wasmtime_module_type_t *
2525
wasmtime_module_type_clone(const wasmtime_module_type_t *ty);
2626

27-
/// \brief Deallocates a component instance type.
27+
/// \brief Deallocates a module type.
2828
WASM_API_EXTERN
2929
void wasmtime_module_type_delete(wasmtime_module_type_t *ty);
3030

0 commit comments

Comments
 (0)