Implement wasm_externref_objdel and wasm_externref_set_cleanup (#2455)

## Context

Some native libraries may want to explicitly delete an externref object without
waiting for the module instance to be deleted.
In addition, it may want to add a cleanup function.

## Proposed Changes

Implement:
* `wasm_externref_objdel` to explicitly delete an externeref'd object. 
* `wasm_externref_set_cleanup` to set a cleanup function that is called when
  the externref'd object is deleted.
This commit is contained in:
tonibofarull
2023-08-14 10:45:30 +02:00
committed by GitHub
parent 5c6613b2b1
commit 8d1cf46f02
2 changed files with 106 additions and 4 deletions

View File

@ -1292,6 +1292,32 @@ WASM_RUNTIME_API_EXTERN bool
wasm_externref_obj2ref(wasm_module_inst_t module_inst,
void *extern_obj, uint32_t *p_externref_idx);
/**
* Delete external object registered by `wasm_externref_obj2ref`.
*
* @param module_inst the WASM module instance that the extern object
* belongs to
* @param extern_obj the external object to be deleted
*
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_externref_objdel(wasm_module_inst_t module_inst, void *extern_obj);
/**
* Set cleanup callback to release external object.
*
* @param module_inst the WASM module instance that the extern object
* belongs to
* @param extern_obj the external object to which to set the `extern_obj_cleanup` cleanup callback.
* @param extern_obj_cleanup a callback to release `extern_obj`
*
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_externref_set_cleanup(wasm_module_inst_t module_inst, void *extern_obj,
void (*extern_obj_cleanup)(void *));
/**
* Retrieve the external object from an internal externref index
*