bytecodealliance / wasm-micro-runtime

WebAssembly Micro Runtime (WAMR)
Apache License 2.0
4.8k stars 609 forks source link

EH: Add APIs to set a name to a WASMModule and get it #3247

Closed lum1n0us closed 5 months ago

lum1n0us commented 6 months ago

Plan to add several APIs to support the name of a WASMModule. People can set it and get it. A rough idea will be

WASM_RUNTIME_API_EXTERN bool
wasm_runtime_set_module_name(wasm_module_t module, const char *name,
                             char *error_buf, uint32_t error_buf_size);

/* return the most recently set module name or "" if never set before */
WASM_RUNTIME_API_EXTERN const char*
wasm_runtime_get_module_name(wasm_module_t module);

Another choice about set_module_name is adding an extra parameter to wasm_runtime_load(), like wasm_runtime_load(uint8_t*,uint32_t,const char*,...). Drop it because it feels not right to change an existed and widely used API, especially when there is another way.

Those APIs will not do any additional protections from sharing same names in WASMModules, or repeatedly set names to one same WASMModule and so on. Basically, we let callers to handle those situations.

The name will be stored in const_str_list to save memory consumption.

lum1n0us commented 5 months ago

3254