mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Add Memory data length
This commit is contained in:
parent
2fa9cec0ed
commit
0cfe864fe6
@ -7,13 +7,13 @@ use std::slice;
|
||||
use std::str;
|
||||
use std::sync::Arc;
|
||||
use std::{ffi::c_void, mem, ptr};
|
||||
use wasmer_runtime::{Global, ImportObject, Instance, Memory, Table, Value};
|
||||
use wasmer_runtime::{Ctx, Global, ImportObject, Instance, Memory, Table, Value};
|
||||
use wasmer_runtime_core::export::{Context, Export, FuncPointer};
|
||||
use wasmer_runtime_core::import::{LikeNamespace, Namespace};
|
||||
use wasmer_runtime_core::types::{
|
||||
ElementType, FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type,
|
||||
};
|
||||
use wasmer_runtime_core::units::Pages;
|
||||
use wasmer_runtime_core::units::{Bytes, Pages};
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasmer_import_object_t();
|
||||
@ -428,22 +428,17 @@ pub unsafe extern "C" fn wasmer_imports_set_import_func(
|
||||
// };
|
||||
}
|
||||
|
||||
//#[no_mangle]
|
||||
//pub extern "C" fn wasmer_debug_print(kind: uint8_t, thing: *mut c_void) {
|
||||
// match kind {
|
||||
// 1 => {
|
||||
// println!("wasmer import object:");
|
||||
// let import_object = unsafe { Box::from_raw(thing as *mut ImportObject) };
|
||||
// println!("after import object");
|
||||
// Box::into_raw(import_object);
|
||||
// },
|
||||
// _ => panic!("unknown kind {:?}", kind)
|
||||
// }
|
||||
//}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_instance_context_memory(instance: *mut wasmer_instance_context_t) {}
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_memory_data_length(mem: *mut wasmer_memory_t) -> uint32_t {
|
||||
let memory = mem as *mut Memory;
|
||||
let Bytes(len) = unsafe { (*memory).size().bytes() };
|
||||
len as uint32_t
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_instance_destroy(instance: *mut wasmer_instance_t) {
|
||||
|
@ -24,6 +24,10 @@ int main()
|
||||
printf("Memory pages length: %d\n", new_len);
|
||||
assert(new_len == 12);
|
||||
|
||||
uint32_t bytes_len = wasmer_memory_data_length(memory);
|
||||
printf("Memory bytes length: %d\n", bytes_len);
|
||||
assert(bytes_len == 12 * 65536);
|
||||
|
||||
// Err, grow beyond max
|
||||
wasmer_memory_result_t grow_result2 = wasmer_memory_grow(memory, 10);
|
||||
assert(grow_result2 == WASMER_MEMORY_ERROR);
|
||||
|
@ -113,6 +113,8 @@ wasmer_compile_result_t wasmer_instantiate(wasmer_instance_t **instance,
|
||||
uint32_t wasm_bytes_len,
|
||||
wasmer_import_object_t *import_object);
|
||||
|
||||
uint32_t wasmer_memory_data_length(wasmer_memory_t *mem);
|
||||
|
||||
void wasmer_memory_destroy(wasmer_memory_t *memory);
|
||||
|
||||
wasmer_memory_result_t wasmer_memory_grow(wasmer_memory_t *memory, uint32_t delta);
|
||||
|
@ -113,6 +113,8 @@ wasmer_compile_result_t wasmer_instantiate(wasmer_instance_t **instance,
|
||||
uint32_t wasm_bytes_len,
|
||||
wasmer_import_object_t *import_object);
|
||||
|
||||
uint32_t wasmer_memory_data_length(wasmer_memory_t *mem);
|
||||
|
||||
void wasmer_memory_destroy(wasmer_memory_t *memory);
|
||||
|
||||
wasmer_memory_result_t wasmer_memory_grow(wasmer_memory_t *memory, uint32_t delta);
|
||||
|
Loading…
Reference in New Issue
Block a user