Add Table grow function

This commit is contained in:
Brandon Fish 2019-02-09 13:58:50 -06:00
parent 4e5e525626
commit 8364c39b4c
4 changed files with 35 additions and 2 deletions

View File

@ -163,6 +163,22 @@ pub unsafe extern "C" fn wasmer_table_new(
wasmer_table_result_t::WASMER_TABLE_OK
}
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_table_grow(
table: *mut wasmer_table_t,
delta: uint32_t,
) -> wasmer_table_result_t {
let table = unsafe { Box::from_raw(table as *mut Table) };
let maybe_delta = table.grow(delta);
Box::into_raw(table);
if let Some(_delta) = maybe_delta {
wasmer_table_result_t::WASMER_TABLE_OK
} else {
wasmer_table_result_t::WASMER_TABLE_ERROR
}
}
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_table_length(table: *mut wasmer_table_t) -> uint32_t {

View File

@ -8,14 +8,27 @@ int main()
wasmer_table_t *table = NULL;
wasmer_limits_t descriptor;
descriptor.min = 10;
descriptor.max = 10;
descriptor.max = 15;
wasmer_table_result_t table_result = wasmer_table_new(&table, descriptor);
printf("Table result: %d\n", table_result);
assert(table_result == WASMER_TABLE_OK);
uint32_t len = wasmer_table_length(table);
printf("Table length: %d\n", len);
assert(len == 10);
assert(len == 15);
// wasmer_table_result_t grow_result1 = wasmer_table_grow(&table, 5);
// assert(grow_result1 == WASMER_TABLE_OK);
// uint32_t len_grow1 = wasmer_table_length(table);
// printf("Table length: %d\n", len_grow1);
// assert(len_grow1 == 15);
// // Try to grow beyond max
// wasmer_table_result_t grow_result2 = wasmer_table_grow(&table, 1);
// assert(grow_result2 == WASMER_TABLE_ERROR);
// uint32_t len_grow2 = wasmer_table_length(table);
// printf("Table length: %d\n", len_grow2);
// assert(len_grow2 == 15);
printf("Destroy table\n");
wasmer_table_destroy(table);

View File

@ -99,6 +99,8 @@ wasmer_memory_result_t wasmer_memory_new(wasmer_memory_t **memory, wasmer_limits
void wasmer_table_destroy(wasmer_table_t *table);
wasmer_table_result_t wasmer_table_grow(wasmer_table_t *table, uint32_t delta);
uint32_t wasmer_table_length(wasmer_table_t *table);
wasmer_table_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits);

View File

@ -99,6 +99,8 @@ wasmer_memory_result_t wasmer_memory_new(wasmer_memory_t **memory, wasmer_limits
void wasmer_table_destroy(wasmer_table_t *table);
wasmer_table_result_t wasmer_table_grow(wasmer_table_t *table, uint32_t delta);
uint32_t wasmer_table_length(wasmer_table_t *table);
wasmer_table_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits);