Skip to content

Commit

Permalink
Merge #2478
Browse files Browse the repository at this point in the history
2478: Rename wasm_instance_new()’s “traps” argument to “trap”. r=syrusakbary a=FGasper

Issue #2472

# Description

This clarifies a bit how to properly use the error-handling mechanism in `wasm_instance_new()`, which only produces 0 or 1 traps, not 2+ as the name “traps” implies.

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file


Co-authored-by: Felipe Gasper <[email protected]>
  • Loading branch information
bors[bot] and FGasper authored Jul 17, 2021
2 parents e916643 + d8cd757 commit 784b85e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/c-api/examples/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ int main(int argc, const char* argv[]) {

printf("Instantiating module...\n");
wasm_extern_vec_t imports = WASM_EMPTY_VEC;
wasm_trap_t* traps = NULL;
wasm_instance_t* instance = wasm_instance_new(store, module, &imports,&traps);
wasm_trap_t* trap = NULL;
wasm_instance_t* instance = wasm_instance_new(store, module, &imports,&trap);

if (!instance) {
printf("> Error instantiating module!\n");
Expand Down
4 changes: 2 additions & 2 deletions lib/c-api/src/wasm_c_api/externals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ mod tests {
assert(module);

wasm_extern_vec_t imports = WASM_EMPTY_VEC;
wasm_trap_t* traps = NULL;
wasm_trap_t* trap = NULL;

wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
assert(instance);

wasm_extern_vec_t exports;
Expand Down
14 changes: 7 additions & 7 deletions lib/c-api/src/wasm_c_api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct wasm_instance_t {
/// 2. Runtime errors that happen when running the module `start`
/// function.
///
/// Failures are stored in the `traps` argument; the program doesn't
/// The failure is stored in the `trap` argument; the program doesn't
/// panic.
///
/// # Notes
Expand All @@ -41,7 +41,7 @@ pub unsafe extern "C" fn wasm_instance_new(
_store: Option<&wasm_store_t>,
module: Option<&wasm_module_t>,
imports: Option<&wasm_extern_vec_t>,
traps: *mut *mut wasm_trap_t,
trap: *mut *mut wasm_trap_t,
) -> Option<Box<wasm_instance_t>> {
let module = module?;
let imports = imports?;
Expand All @@ -68,7 +68,7 @@ pub unsafe extern "C" fn wasm_instance_new(

Err(InstantiationError::Start(runtime_error)) => {
let trap: Box<wasm_trap_t> = Box::new(runtime_error.into());
*traps = Box::into_raw(trap);
*trap = Box::into_raw(trap);

return None;
}
Expand Down Expand Up @@ -124,9 +124,9 @@ pub unsafe extern "C" fn wasm_instance_delete(_instance: Option<Box<wasm_instanc
///
/// // Instantiate the module.
/// wasm_extern_vec_t imports = WASM_EMPTY_VEC;
/// wasm_trap_t* traps = NULL;
/// wasm_trap_t* trap = NULL;
///
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
/// assert(instance);
///
/// // Read the exports.
Expand Down Expand Up @@ -252,8 +252,8 @@ mod tests {
wasm_extern_vec_t imports = WASM_ARRAY_VEC(externs);

// Instantiate the module.
wasm_trap_t* traps = NULL;
wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
wasm_trap_t* trap = NULL;
wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);

assert(instance);

Expand Down
4 changes: 2 additions & 2 deletions lib/c-api/src/wasm_c_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ pub mod externals;
///
/// // Instantiate the module.
/// wasm_extern_vec_t imports = WASM_EMPTY_VEC;
/// wasm_trap_t* traps = NULL;
/// wasm_trap_t* trap = NULL;
///
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
/// assert(instance);
///
/// // Now do something with the instance, like calling the
Expand Down
8 changes: 4 additions & 4 deletions lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
//!
//! // Instantiate the module.
//! wasm_extern_vec_t imports = WASM_EMPTY_VEC;
//! wasm_trap_t* traps = NULL;
//! wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
//! wasm_trap_t* trap = NULL;
//! wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
//! assert(instance);
//!
//! // Here we go. At this step, we will get the `add_two` exported function, and
Expand Down Expand Up @@ -269,8 +269,8 @@ pub extern "C" fn wasmer_metering_points_are_exhausted(instance: &wasm_instance_
/// assert(module);
///
/// wasm_extern_vec_t imports = WASM_EMPTY_VEC;
/// wasm_trap_t* traps = NULL;
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
/// wasm_trap_t* trap = NULL;
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
/// assert(instance);
///
/// // Read the number of points.
Expand Down

0 comments on commit 784b85e

Please sign in to comment.