Add Memory Grow C API

This commit is contained in:
Brandon Fish
2019-02-09 17:53:03 -06:00
parent a8dcc0ee87
commit a0288c87ac
4 changed files with 32 additions and 1 deletions

View File

@ -146,6 +146,22 @@ pub unsafe extern "C" fn wasmer_memory_new(
wasmer_memory_result_t::WASMER_MEMORY_OK
}
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_memory_grow(
memory: *mut wasmer_memory_t,
delta: uint32_t,
) -> wasmer_memory_result_t {
let memory = unsafe { Box::from_raw(memory as *mut Memory) };
let maybe_delta = memory.grow(Pages(delta));
Box::into_raw(memory);
if let Some(_delta) = maybe_delta {
wasmer_memory_result_t::WASMER_MEMORY_OK
} else {
wasmer_memory_result_t::WASMER_MEMORY_ERROR
}
}
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_memory_length(memory: *mut wasmer_memory_t) -> uint32_t {