Allow specifying optional max value in limits

This commit is contained in:
Brandon Fish
2019-02-19 00:05:08 -06:00
parent 380d766943
commit d2f3023191
5 changed files with 45 additions and 12 deletions

View File

@ -87,7 +87,13 @@ pub struct wasmer_global_t();
#[repr(C)]
pub struct wasmer_limits_t {
pub min: uint32_t,
pub max: uint32_t,
pub max: wasmer_limit_option_t,
}
#[repr(C)]
pub struct wasmer_limit_option_t {
pub has_some: bool,
pub some: uint32_t,
}
#[repr(C)]
@ -167,9 +173,14 @@ pub unsafe extern "C" fn wasmer_memory_new(
mut memory: *mut *mut wasmer_memory_t,
limits: wasmer_limits_t,
) -> wasmer_result_t {
let max = if limits.max.has_some {
Some(Pages(limits.max.some))
} else {
None
};
let desc = MemoryDescriptor {
minimum: Pages(limits.min),
maximum: Some(Pages(limits.max)),
maximum: max,
shared: false,
};
let result = Memory::new(desc);
@ -231,10 +242,15 @@ pub unsafe extern "C" fn wasmer_table_new(
mut table: *mut *mut wasmer_table_t,
limits: wasmer_limits_t,
) -> wasmer_result_t {
let max = if limits.max.has_some {
Some(limits.max.some)
} else {
None
};
let desc = TableDescriptor {
element: ElementType::Anyfunc,
minimum: limits.min,
maximum: Some(limits.max),
maximum: max,
};
let result = Table::new(desc);
let new_table = match result {

View File

@ -8,7 +8,10 @@ int main()
wasmer_memory_t *memory = NULL;
wasmer_limits_t descriptor;
descriptor.min = 10;
descriptor.max = 15;
wasmer_limit_option_t max;
max.has_some = true;
max.some = 15;
descriptor.max = max;
wasmer_result_t memory_result = wasmer_memory_new(&memory, descriptor);
printf("Memory result: %d\n", memory_result);
assert(memory_result == WASMER_OK);

View File

@ -8,7 +8,11 @@ int main()
wasmer_table_t *table = NULL;
wasmer_limits_t descriptor;
descriptor.min = 10;
descriptor.max = 15;
wasmer_limit_option_t max;
// max.has_some = false;
max.has_some = true;
max.some = 15;
descriptor.max = max;
wasmer_result_t table_result = wasmer_table_new(&table, descriptor);
printf("Table result: %d\n", table_result);
assert(table_result == WASMER_OK);
@ -17,7 +21,7 @@ int main()
printf("Table length: %d\n", len);
assert(len == 15);
// wasmer_result_t grow_result1 = wasmer_table_grow(&table, 5);
// wasmer_result_t grow_result1 = wasmer_table_grow(table, 5);
// assert(grow_result1 == WASMER_OK);
// uint32_t len_grow1 = wasmer_table_length(table);
// printf("Table length: %d\n", len_grow1);

View File

@ -93,9 +93,14 @@ typedef struct {
wasmer_import_export_value value;
} wasmer_import_t;
typedef struct {
bool has_some;
uint32_t some;
} wasmer_limit_option_t;
typedef struct {
uint32_t min;
uint32_t max;
wasmer_limit_option_t max;
} wasmer_limits_t;
/**

View File

@ -90,9 +90,14 @@ struct wasmer_import_t {
wasmer_import_export_value value;
};
struct wasmer_limit_option_t {
bool has_some;
uint32_t some;
};
struct wasmer_limits_t {
uint32_t min;
uint32_t max;
wasmer_limit_option_t max;
};
extern "C" {