mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-14 09:21:20 +00:00
feat(runtime-c-api) Add the wasmer_module_serialization_destroy
function.
This commit is contained in:
@ -576,9 +576,7 @@ pub unsafe extern "C" fn wasmer_export_descriptor_kind(
|
|||||||
|
|
||||||
/// Serialize the given Module.
|
/// Serialize the given Module.
|
||||||
///
|
///
|
||||||
/// It's up to the caller to free the memory of the
|
/// The caller owns the object and should call `wasmer_memory_serialization_destroy` to free it.
|
||||||
/// `serialized_module` byte array (both the `bytes` field and the
|
|
||||||
/// structure).
|
|
||||||
///
|
///
|
||||||
/// Returns `wasmer_result_t::WASMER_OK` upon success.
|
/// Returns `wasmer_result_t::WASMER_OK` upon success.
|
||||||
///
|
///
|
||||||
@ -620,6 +618,15 @@ pub unsafe extern "C" fn wasmer_module_serialize(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Frees memory for the given serialized Module.
|
||||||
|
#[allow(clippy::cast_ptr_alignment)]
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn wasmer_module_serialization_destroy(serialized_module: *mut wasmer_byte_array) {
|
||||||
|
if !serialized_module.is_null() {
|
||||||
|
unsafe { Box::from_raw(serialized_module as *mut wasmer_byte_array) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Deserialize the given bytes into a Module.
|
/// Deserialize the given bytes into a Module.
|
||||||
///
|
///
|
||||||
/// Returns `wasmer_result_t::WASMER_OK` upon success.
|
/// Returns `wasmer_result_t::WASMER_OK` upon success.
|
||||||
|
@ -62,8 +62,7 @@ int main()
|
|||||||
assert(call_result == WASMER_OK);
|
assert(call_result == WASMER_OK);
|
||||||
|
|
||||||
printf("Destroy the serialized module\n");
|
printf("Destroy the serialized module\n");
|
||||||
free((uint8_t *) serialized_module->bytes);
|
wasmer_module_serialization_destroy(serialized_module);
|
||||||
free(serialized_module);
|
|
||||||
|
|
||||||
printf("Destroy instance\n");
|
printf("Destroy instance\n");
|
||||||
wasmer_instance_destroy(instance);
|
wasmer_instance_destroy(instance);
|
||||||
|
@ -514,11 +514,14 @@ wasmer_result_t wasmer_module_instantiate(const wasmer_module_t *module,
|
|||||||
wasmer_import_t *imports,
|
wasmer_import_t *imports,
|
||||||
int imports_len);
|
int imports_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees memory for the given serialized Module.
|
||||||
|
*/
|
||||||
|
void wasmer_module_serialization_destroy(wasmer_byte_array *serialized_module);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Module.
|
* Serialize the given Module.
|
||||||
* It's up to the caller to free the memory of the
|
* The caller owns the object and should call `wasmer_memory_serialization_destroy` to free it.
|
||||||
* `serialized_module` byte array (both the `bytes` field and the
|
|
||||||
* structure).
|
|
||||||
* Returns `wasmer_result_t::WASMER_OK` upon success.
|
* Returns `wasmer_result_t::WASMER_OK` upon success.
|
||||||
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
|
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
|
||||||
* and `wasmer_last_error_message` to get an error message.
|
* and `wasmer_last_error_message` to get an error message.
|
||||||
|
@ -405,10 +405,11 @@ wasmer_result_t wasmer_module_instantiate(const wasmer_module_t *module,
|
|||||||
wasmer_import_t *imports,
|
wasmer_import_t *imports,
|
||||||
int imports_len);
|
int imports_len);
|
||||||
|
|
||||||
|
/// Frees memory for the given serialized Module.
|
||||||
|
void wasmer_module_serialization_destroy(wasmer_byte_array *serialized_module);
|
||||||
|
|
||||||
/// Serialize the given Module.
|
/// Serialize the given Module.
|
||||||
/// It's up to the caller to free the memory of the
|
/// The caller owns the object and should call `wasmer_memory_serialization_destroy` to free it.
|
||||||
/// `serialized_module` byte array (both the `bytes` field and the
|
|
||||||
/// structure).
|
|
||||||
/// Returns `wasmer_result_t::WASMER_OK` upon success.
|
/// Returns `wasmer_result_t::WASMER_OK` upon success.
|
||||||
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
|
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
|
||||||
/// and `wasmer_last_error_message` to get an error message.
|
/// and `wasmer_last_error_message` to get an error message.
|
||||||
|
Reference in New Issue
Block a user