mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 06:08:29 +00:00
feat(c-api) Allow extern types to own data.
We have known memory leaks with extern types. The idea is to change the code so that extern types can hold/own data. This patch does that. A `wasm_externtype_t` holds a `WasmExternType` enum. This enum owns sibling types such as `WasmFunctionType`, `WasmGlobalType`, `WasmTableType` and `WasmMemoryType`. It is those structures that ows the extern types data, like `params` and `results` as `wasm_valtype_vec_t` for `WasmFunctionType`. That way, for example, `wasm_functype_t` can return a pointer to these vec which it owns. A `wasm_externtype_t` continues to be transmuted to `wasm_functype_t` etc. Nothing changes on that side.
This commit is contained in:
@@ -33,11 +33,11 @@ pub type wasm_env_finalizer_t = unsafe extern "C" fn(c_void);
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_new(
|
||||
store: &wasm_store_t,
|
||||
ft: &wasm_functype_t,
|
||||
function_type: &wasm_functype_t,
|
||||
callback: wasm_func_callback_t,
|
||||
) -> Option<Box<wasm_func_t>> {
|
||||
// TODO: handle null pointers?
|
||||
let func_sig = ft.sig();
|
||||
let func_sig = &function_type.inner().function_type;
|
||||
let num_rets = func_sig.results().len();
|
||||
let inner_callback = move |args: &[Val]| -> Result<Vec<Val>, RuntimeError> {
|
||||
let processed_args: wasm_val_vec_t = args
|
||||
@@ -85,13 +85,13 @@ pub unsafe extern "C" fn wasm_func_new(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_new_with_env(
|
||||
store: &wasm_store_t,
|
||||
ft: &wasm_functype_t,
|
||||
function_type: &wasm_functype_t,
|
||||
callback: wasm_func_callback_with_env_t,
|
||||
env: *mut c_void,
|
||||
finalizer: wasm_env_finalizer_t,
|
||||
) -> Option<Box<wasm_func_t>> {
|
||||
// TODO: handle null pointers?
|
||||
let func_sig = ft.sig();
|
||||
let func_sig = &function_type.inner().function_type;
|
||||
let num_rets = func_sig.results().len();
|
||||
let inner_callback =
|
||||
move |env: &mut *mut c_void, args: &[Val]| -> Result<Vec<Val>, RuntimeError> {
|
||||
|
||||
Reference in New Issue
Block a user