Add Wasmtime-specific C API functions to return errors (#1467)
* Add Wasmtime-specific C API functions to return errors This commit adds new `wasmtime_*` symbols to the C API, many of which mirror the existing counterparts in the `wasm.h` header. These APIs are enhanced in a number of respects: * Detailed error information is now available through a `wasmtime_error_t`. Currently this only exposes one function which is to extract a string version of the error. * There is a distinction now between traps and errors during instantiation and function calling. Traps only happen if wasm traps, and errors can happen for things like runtime type errors when interacting with the API. * APIs have improved safety with respect to embedders where the lengths of arrays are now taken as explicit parameters rather than assumed from other parameters. * Handle trap updates * Update C examples * Fix memory.c compile on MSVC * Update test assertions * Refactor C slightly * Bare-bones .NET update * Remove bogus nul handling
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::{handle_result, wasmtime_error_t};
|
||||
use wasmtime::{Config, OptLevel, ProfilingStrategy, Strategy};
|
||||
|
||||
#[repr(C)]
|
||||
@@ -72,15 +73,14 @@ pub extern "C" fn wasmtime_config_wasm_multi_value_set(c: &mut wasm_config_t, en
|
||||
pub extern "C" fn wasmtime_config_strategy_set(
|
||||
c: &mut wasm_config_t,
|
||||
strategy: wasmtime_strategy_t,
|
||||
) -> bool {
|
||||
) -> Option<Box<wasmtime_error_t>> {
|
||||
use wasmtime_strategy_t::*;
|
||||
c.config
|
||||
.strategy(match strategy {
|
||||
WASMTIME_STRATEGY_AUTO => Strategy::Auto,
|
||||
WASMTIME_STRATEGY_CRANELIFT => Strategy::Cranelift,
|
||||
WASMTIME_STRATEGY_LIGHTBEAM => Strategy::Lightbeam,
|
||||
})
|
||||
.is_ok()
|
||||
let result = c.config.strategy(match strategy {
|
||||
WASMTIME_STRATEGY_AUTO => Strategy::Auto,
|
||||
WASMTIME_STRATEGY_CRANELIFT => Strategy::Cranelift,
|
||||
WASMTIME_STRATEGY_LIGHTBEAM => Strategy::Lightbeam,
|
||||
});
|
||||
handle_result(result, |_cfg| {})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -108,12 +108,11 @@ pub extern "C" fn wasmtime_config_cranelift_opt_level_set(
|
||||
pub extern "C" fn wasmtime_config_profiler_set(
|
||||
c: &mut wasm_config_t,
|
||||
strategy: wasmtime_profiling_strategy_t,
|
||||
) -> bool {
|
||||
) -> Option<Box<wasmtime_error_t>> {
|
||||
use wasmtime_profiling_strategy_t::*;
|
||||
c.config
|
||||
.profiler(match strategy {
|
||||
WASMTIME_PROFILING_STRATEGY_NONE => ProfilingStrategy::None,
|
||||
WASMTIME_PROFILING_STRATEGY_JITDUMP => ProfilingStrategy::JitDump,
|
||||
})
|
||||
.is_ok()
|
||||
let result = c.config.profiler(match strategy {
|
||||
WASMTIME_PROFILING_STRATEGY_NONE => ProfilingStrategy::None,
|
||||
WASMTIME_PROFILING_STRATEGY_JITDUMP => ProfilingStrategy::JitDump,
|
||||
});
|
||||
handle_result(result, |_cfg| {})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user