mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-24 14:11:32 +00:00
Allow specifying optional max value in limits
This commit is contained in:
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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" {
|
||||
|
Reference in New Issue
Block a user