mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-21 20:51:32 +00:00
feat(runtime-c-api) wasmer_memory_data_length
returns 0 if memory
is NULL.
This commit is contained in:
@ -198,10 +198,15 @@ pub extern "C" fn wasmer_memory_data(memory: *const wasmer_memory_t) -> *mut u8
|
|||||||
/// ```
|
/// ```
|
||||||
#[allow(clippy::cast_ptr_alignment)]
|
#[allow(clippy::cast_ptr_alignment)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasmer_memory_data_length(mem: *mut wasmer_memory_t) -> u32 {
|
pub extern "C" fn wasmer_memory_data_length(memory: *mut wasmer_memory_t) -> u32 {
|
||||||
let memory = mem as *mut Memory;
|
if memory.is_null() {
|
||||||
let Bytes(len) = unsafe { (*memory).size().bytes() };
|
return 0;
|
||||||
len as u32
|
}
|
||||||
|
|
||||||
|
let memory = unsafe { &*(memory as *const Memory) };
|
||||||
|
let Bytes(length) = memory.size().bytes();
|
||||||
|
|
||||||
|
length as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frees memory for the given Memory
|
/// Frees memory for the given Memory
|
||||||
|
Reference in New Issue
Block a user