mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 21:21:33 +00:00
feat(runtime-c-api) wasmer_validate
expects a *const uint8_t
.
This patch updates the first argument of `wasmer_validate` from `*mut uint8_t` to `*const uint8_t`. Indeed, the `wasmer-runtime-core::validate` function doesn't expect a mutable slice, so it's not required to expect a mutable array from C. Also, it's likely for the Wasm bytes to be stored in the `wasmer_byte_array` structure. The first field `bytes` is defined as `*const uint8_t`. So this patch avoids a cast when writing a C++ program.
This commit is contained in:
@ -159,13 +159,13 @@ pub struct wasmer_byte_array {
|
|||||||
#[allow(clippy::cast_ptr_alignment)]
|
#[allow(clippy::cast_ptr_alignment)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasmer_validate(
|
pub unsafe extern "C" fn wasmer_validate(
|
||||||
wasm_bytes: *mut uint8_t,
|
wasm_bytes: *const uint8_t,
|
||||||
wasm_bytes_len: uint32_t,
|
wasm_bytes_len: uint32_t,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if wasm_bytes.is_null() {
|
if wasm_bytes.is_null() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let bytes: &[u8] = ::std::slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize);
|
let bytes: &[u8] = ::std::slice::from_raw_parts(wasm_bytes, wasm_bytes_len as usize);
|
||||||
|
|
||||||
wasmer_runtime_core::validate(bytes)
|
wasmer_runtime_core::validate(bytes)
|
||||||
}
|
}
|
||||||
|
@ -535,6 +535,6 @@ wasmer_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits)
|
|||||||
/**
|
/**
|
||||||
* Returns true for valid wasm bytes and false for invalid bytes
|
* Returns true for valid wasm bytes and false for invalid bytes
|
||||||
*/
|
*/
|
||||||
bool wasmer_validate(uint8_t *wasm_bytes, uint32_t wasm_bytes_len);
|
bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len);
|
||||||
|
|
||||||
#endif /* WASMER_H */
|
#endif /* WASMER_H */
|
||||||
|
@ -418,7 +418,7 @@ uint32_t wasmer_table_length(wasmer_table_t *table);
|
|||||||
wasmer_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits);
|
wasmer_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits);
|
||||||
|
|
||||||
/// Returns true for valid wasm bytes and false for invalid bytes
|
/// Returns true for valid wasm bytes and false for invalid bytes
|
||||||
bool wasmer_validate(uint8_t *wasm_bytes, uint32_t wasm_bytes_len);
|
bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len);
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user