Tweak C API for fuel

* Ensure `store` is in the function names
* Don't abort the process on `add_fuel` when fuel isn't configured
* Allow learning about failure in both `add_fuel` and `fuel_consumed`
This commit is contained in:
Alex Crichton
2021-02-09 07:16:59 -08:00
parent 5b55ba8053
commit de27fbe20f
5 changed files with 37 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
use crate::wasm_engine_t;
use crate::{wasm_engine_t, wasmtime_error_t};
use wasmtime::{InterruptHandle, Store};
#[repr(C)]
@@ -44,11 +44,20 @@ pub extern "C" fn wasmtime_interrupt_handle_interrupt(handle: &wasmtime_interrup
}
#[no_mangle]
pub extern "C" fn wasmtime_add_fuel(store: &wasm_store_t, fuel: u64) {
store.store.add_fuel(fuel);
pub extern "C" fn wasmtime_store_add_fuel(
store: &wasm_store_t,
fuel: u64,
) -> Option<Box<wasmtime_error_t>> {
crate::handle_result(store.store.add_fuel(fuel), |()| {})
}
#[no_mangle]
pub extern "C" fn wasmtime_fuel_consumed(store: &wasm_store_t) -> u64 {
store.store.fuel_consumed().unwrap_or(0)
pub extern "C" fn wasmtime_store_fuel_consumed(store: &wasm_store_t, fuel: &mut u64) -> bool {
match store.store.fuel_consumed() {
Some(amt) => {
*fuel = amt;
true
}
None => false,
}
}