Add Store::consume_fuel to manually consume fuel (#3352)

This can be useful for host functions that want to consume fuel to
reflect their relative cost. Additionally it's a relatively easy
addition to have and someone's asking for it!

Closes #3315
This commit is contained in:
Alex Crichton
2021-09-15 13:10:11 -05:00
committed by GitHub
parent 9db418cfd9
commit b31a4ea16b
5 changed files with 143 additions and 0 deletions

View File

@@ -145,6 +145,17 @@ pub extern "C" fn wasmtime_context_fuel_consumed(store: CStoreContext<'_>, fuel:
}
}
#[no_mangle]
pub extern "C" fn wasmtime_context_consume_fuel(
mut store: CStoreContextMut<'_>,
fuel: u64,
remaining_fuel: &mut u64,
) -> Option<Box<wasmtime_error_t>> {
crate::handle_result(store.consume_fuel(fuel), |remaining| {
*remaining_fuel = remaining;
})
}
#[repr(C)]
pub struct wasmtime_interrupt_handle_t {
handle: InterruptHandle,