Customized External References

External References denotes an opaque and unforgeable reference to a host object. A new externref type can be passed into a Wasm module or return from it. The Wasm module cannot reveal an externref value’s bit pattern, nor create a fake host reference by an integer value.

Tutorial

The following tutorial is the summary of the externref example in WasmEdge.

Prepare Your Wasm File

The Wasm file should contain importing host functions that would take the externref. Take the test WASM file (this WAT is the corresponding text format) as an example:

  1. (module
  2. (type $t0 (func (param externref i32) (result i32)))
  3. (type $t1 (func (param externref i32 i32) (result i32)))
  4. (type $t2 (func (param externref externref i32 i32) (result i32)))
  5. (import "extern_module" "functor_square" (func $functor_square (type $t0)))
  6. (import "extern_module" "class_add" (func $class_add (type $t1)))
  7. (import "extern_module" "func_mul" (func $func_mul (type $t1)))
  8. (func $call_add (export "call_add") (type $t1) (param $p0 externref) (param $p1 i32) (param $p2 i32) (result i32)
  9. (call $class_add
  10. (local.get $p0)
  11. (local.get $p1)
  12. (local.get $p2)))
  13. (func $call_mul (export "call_mul") (type $t1) (param $p0 externref) (param $p1 i32) (param $p2 i32) (result i32)
  14. (call $func_mul
  15. (local.get $p0)
  16. (local.get $p1)
  17. (local.get $p2)))
  18. (func $call_square (export "call_square") (type $t0) (param $p0 externref) (param $p1 i32) (result i32)
  19. (call $functor_square
  20. (local.get $p0)
  21. (local.get $p1)))
  22. (func $call_add_square (export "call_add_square") (type $t2) (param $p0 externref) (param $p1 externref) (param $p2 i32) (param $p3 i32) (result i32)
  23. (call $functor_square
  24. (local.get $p1)
  25. (call $class_add
  26. (local.get $p0)
  27. (local.get $p2)
  28. (local.get $p3))))
  29. (memory $memory (export "memory") 1))

Users can convert wat to wasm through wat2wasm live tool. Noted that reference types checkbox should be checked on this page.

Implement Host Module and Register into WasmEdge

The host module should be implemented and registered into WasmEdge before executing Wasm. Assume that the following code is saved as main.c:

  1. #include <wasmedge/wasmedge.h>
  2. #include <stdio.h>
  3. uint32_t SquareFunc(uint32_t A) { return A * A; }
  4. uint32_t AddFunc(uint32_t A, uint32_t B) { return A + B; }
  5. uint32_t MulFunc(uint32_t A, uint32_t B) { return A * B; }
  6. // Host function to call `SquareFunc` by external reference
  7. WasmEdge_Result ExternSquare(void *Data, WasmEdge_MemoryInstanceContext *MemCxt,
  8. const WasmEdge_Value *In, WasmEdge_Value *Out) {
  9. // Function type: {externref, i32} -> {i32}
  10. uint32_t (*Func)(uint32_t) = WasmEdge_ValueGetExternRef(In[0]);
  11. uint32_t C = Func(WasmEdge_ValueGetI32(In[1]));
  12. Out[0] = WasmEdge_ValueGenI32(C);
  13. return WasmEdge_Result_Success;
  14. }
  15. // Host function to call `AddFunc` by external reference
  16. WasmEdge_Result ExternAdd(void *Data, WasmEdge_MemoryInstanceContext *MemCxt,
  17. const WasmEdge_Value *In, WasmEdge_Value *Out) {
  18. // Function type: {externref, i32, i32} -> {i32}
  19. uint32_t (*Func)(uint32_t, uint32_t) = WasmEdge_ValueGetExternRef(In[0]);
  20. uint32_t C = Func(WasmEdge_ValueGetI32(In[1]), WasmEdge_ValueGetI32(In[2]));
  21. Out[0] = WasmEdge_ValueGenI32(C);
  22. return WasmEdge_Result_Success;
  23. }
  24. // Host function to call `ExternMul` by external reference
  25. WasmEdge_Result ExternMul(void *Data, WasmEdge_MemoryInstanceContext *MemCxt,
  26. const WasmEdge_Value *In, WasmEdge_Value *Out) {
  27. // Function type: {externref, i32, i32} -> {i32}
  28. uint32_t (*Func)(uint32_t, uint32_t) = WasmEdge_ValueGetExternRef(In[0]);
  29. uint32_t C = Func(WasmEdge_ValueGetI32(In[1]), WasmEdge_ValueGetI32(In[2]));
  30. Out[0] = WasmEdge_ValueGenI32(C);
  31. return WasmEdge_Result_Success;
  32. }
  33. // Helper function to create the "extern_module" module instance.
  34. WasmEdge_ModuleInstanceContext *CreateExternModule() {
  35. WasmEdge_String HostName;
  36. WasmEdge_FunctionTypeContext *HostFType = NULL;
  37. WasmEdge_FunctionInstanceContext *HostFunc = NULL;
  38. enum WasmEdge_ValType P[3], R[1];
  39. HostName = WasmEdge_StringCreateByCString("extern_module");
  40. WasmEdge_ModuleInstanceContext *HostMod = WasmEdge_ModuleInstanceCreate(HostName);
  41. WasmEdge_StringDelete(HostName);
  42. // Add host function "functor_square": {externref, i32} -> {i32}
  43. P[0] = WasmEdge_ValType_ExternRef;
  44. P[1] = WasmEdge_ValType_I32;
  45. R[0] = WasmEdge_ValType_I32;
  46. HostFType = WasmEdge_FunctionTypeCreate(P, 2, R, 1);
  47. HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternSquare, NULL, 0);
  48. WasmEdge_FunctionTypeDelete(HostFType);
  49. HostName = WasmEdge_StringCreateByCString("functor_square");
  50. WasmEdge_ModuleInstanceAddFunction(HostMod, HostName, HostFunc);
  51. WasmEdge_StringDelete(HostName);
  52. // Add host function "class_add": {externref, i32, i32} -> {i32}
  53. P[2] = WasmEdge_ValType_I32;
  54. HostFType = WasmEdge_FunctionTypeCreate(P, 3, R, 1);
  55. HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternAdd, NULL, 0);
  56. WasmEdge_FunctionTypeDelete(HostFType);
  57. HostName = WasmEdge_StringCreateByCString("class_add");
  58. WasmEdge_ModuleInstanceAddFunction(HostMod, HostName, HostFunc);
  59. WasmEdge_StringDelete(HostName);
  60. // Add host function "func_mul": {externref, i32, i32} -> {i32}
  61. HostFType = WasmEdge_FunctionTypeCreate(P, 3, R, 1);
  62. HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternMul, NULL, 0);
  63. WasmEdge_FunctionTypeDelete(HostFType);
  64. HostName = WasmEdge_StringCreateByCString("func_mul");
  65. WasmEdge_ModuleInstanceAddFunction(HostMod, HostName, HostFunc);
  66. WasmEdge_StringDelete(HostName);
  67. return HostMod;
  68. }
  69. int main() {
  70. WasmEdge_VMContext *VMCxt = WasmEdge_VMCreate(NULL, NULL);
  71. WasmEdge_ModuleInstanceContext *HostMod = CreateExternModule();
  72. WasmEdge_Value P[3], R[1];
  73. WasmEdge_String FuncName;
  74. WasmEdge_Result Res;
  75. Res = WasmEdge_VMRegisterModuleFromImport(VMCxt, HostMod);
  76. if (!WasmEdge_ResultOK(Res)) {
  77. printf("Host module instance registration failed\n");
  78. return EXIT_FAILURE;
  79. }
  80. Res = WasmEdge_VMLoadWasmFromFile(VMCxt, "funcs.wasm");
  81. if (!WasmEdge_ResultOK(Res)) {
  82. printf("WASM file loading failed\n");
  83. return EXIT_FAILURE;
  84. }
  85. Res = WasmEdge_VMValidate(VMCxt);
  86. if (!WasmEdge_ResultOK(Res)) {
  87. printf("WASM validation failed\n");
  88. return EXIT_FAILURE;
  89. }
  90. Res = WasmEdge_VMInstantiate(VMCxt);
  91. if (!WasmEdge_ResultOK(Res)) {
  92. printf("WASM instantiation failed\n");
  93. return EXIT_FAILURE;
  94. }
  95. // Test 1: call add -- 1234 + 5678
  96. P[0] = WasmEdge_ValueGenExternRef(AddFunc);
  97. P[1] = WasmEdge_ValueGenI32(1234);
  98. P[2] = WasmEdge_ValueGenI32(5678);
  99. FuncName = WasmEdge_StringCreateByCString("call_add");
  100. Res = WasmEdge_VMExecute(VMCxt, FuncName, P, 3, R, 1);
  101. WasmEdge_StringDelete(FuncName);
  102. if (WasmEdge_ResultOK(Res)) {
  103. printf("Test 1 -- `call_add` -- 1234 + 5678 = %d\n",
  104. WasmEdge_ValueGetI32(R[0]));
  105. } else {
  106. printf("Test 1 -- `call_add` -- 1234 + 5678 -- failed\n");
  107. return EXIT_FAILURE;
  108. }
  109. // Test 2: call mul -- 789 * 4321
  110. P[0] = WasmEdge_ValueGenExternRef(MulFunc);
  111. P[1] = WasmEdge_ValueGenI32(789);
  112. P[2] = WasmEdge_ValueGenI32(4321);
  113. FuncName = WasmEdge_StringCreateByCString("call_mul");
  114. Res = WasmEdge_VMExecute(VMCxt, FuncName, P, 3, R, 1);
  115. WasmEdge_StringDelete(FuncName);
  116. if (WasmEdge_ResultOK(Res)) {
  117. printf("Test 2 -- `call_mul` -- 789 * 4321 = %d\n",
  118. WasmEdge_ValueGetI32(R[0]));
  119. } else {
  120. printf("Test 2 -- `call_mul` -- 789 * 4321 -- failed\n");
  121. return EXIT_FAILURE;
  122. }
  123. // Test 3: call square -- 8256^2
  124. P[0] = WasmEdge_ValueGenExternRef(SquareFunc);
  125. P[1] = WasmEdge_ValueGenI32(8256);
  126. FuncName = WasmEdge_StringCreateByCString("call_square");
  127. Res = WasmEdge_VMExecute(VMCxt, FuncName, P, 2, R, 1);
  128. if (WasmEdge_ResultOK(Res)) {
  129. printf("Test 3 -- `call_mul` -- 8256 ^ 2 = %d\n",
  130. WasmEdge_ValueGetI32(R[0]));
  131. } else {
  132. printf("Test 3 -- `call_mul` -- 8256 ^ 2 -- failed\n");
  133. return EXIT_FAILURE;
  134. }
  135. return EXIT_SUCCESS;
  136. }

Setup the Environment And Compile

  1. Install the WasmEdge shared library.

    Please refer to the Installation for details.

  2. Prepare the WASM file and the main.c source file as above.

  3. Compile

    1. gcc main.c -lwasmedge_c
    2. # Or you can use g++ for the C++ case, or use the clang.
  4. Run the Test

    1. $ ./a.out
    2. Test 1 -- `call_add` -- 1234 + 5678 = 6912
    3. Test 2 -- `call_mul` -- 789 * 4321 = 3409269
    4. Test 3 -- `call_mul` -- 8256 ^ 2 = 68161536

Wasm module with External References

Take the following wat for example:

  1. (module
  2. (type $t0 (func (param externref i32) (result i32)))
  3. ;; Import a host function which type is {externref i32} -> {i32}
  4. (import "extern_module" "functor_square" (func $functor_square (type $t0)))
  5. ;; Wasm function which type is {externref i32} -> {i32} and exported as "call_square"
  6. (func $call_square (export "call_square") (type $t0) (param $p0 externref) (param $p1 i32) (result i32)
  7. (call $functor_square (local.get $p0) (local.get $p1))
  8. )
  9. (memory $memory (export "memory") 1))

The Wasm function “call_square“ takes an externref parameter, and calls the imported host function functor_square with that externref. Therefore, the functor_square host function can get the object reference when users call “call_square“ Wasm function and pass the object’s reference.

WasmEdge ExternRef Example

The following examples are how to use externref in Wasm with WasmEdge C API.

Wasm Code

The Wasm code must pass the externref to host functions that want to access it. Take the following wat for example, which is a part of the test WASM file:

  1. (module
  2. (type $t0 (func (param externref i32 i32) (result i32)))
  3. (import "extern_module" "func_mul" (func $func_mul (type $t0)))
  4. (func $call_mul (export "call_mul") (type $t0) (param $p0 externref) (param $p1 i32) (param $p2 i32) (result i32)
  5. (call $func_mul (local.get $p0) (local.get $p1) (local.get $p2))
  6. )
  7. (memory $memory (export "memory") 1))

The host function “extern_module::func_mul“ takes externref as a function pointer to multiply parameters 1 and 2 and then return the result. The exported Wasm function “call_mul“ calls “func_mul“ and pass the externref and 2 numbers as arguments.

Host Functions

To instantiate the above example Wasm, the host functions must be registered into WasmEdge. See Host Functions for more details. The host functions which take externrefs must know the original objects’ types. We take the function pointer case for example.

  1. /* Function to pass as function pointer. */
  2. uint32_t MulFunc(uint32_t A, uint32_t B) { return A * B; }
  3. /* Host function to call function by external reference as a function pointer */
  4. WasmEdge_Result ExternMul(void *, WasmEdge_MemoryInstanceContext *,
  5. const WasmEdge_Value *In, WasmEdge_Value *Out) {
  6. /* Function type: {externref, i32, i32} -> {i32} */
  7. void *Ptr = WasmEdge_ValueGetExternRef(In[0]);
  8. uint32_t (*Obj)(uint32_t, uint32_t) = Ptr;
  9. /*
  10. * For C++, the `reinterpret_cast` is needed:
  11. * uint32_t (*Obj)(uint32_t, uint32_t) =
  12. * *reinterpret_cast<uint32_t (*)(uint32_t, uint32_t)>(Ptr);
  13. */
  14. uint32_t C = Obj(WasmEdge_ValueGetI32(In[1]), WasmEdge_ValueGetI32(In[2]));
  15. Out[0] = WasmEdge_ValueGenI32(C);
  16. return WasmEdge_Result_Success;
  17. }

MulFunc“ is a function that will be passed into Wasm as externref. In the “func_mul“ host function, users can use “WasmEdge_ValueGetExternRef“ API to get the pointer from the WasmEdge_Value which contains a externref.

Developers can add the host functions with names into a module instance.

  1. /* Create a module instance. */
  2. WasmEdge_String HostName = WasmEdge_StringCreateByCString("extern_module");
  3. WasmEdge_ModuleInstanceContext *HostMod = WasmEdge_ModuleInstanceCreate(HostName);
  4. WasmEdge_StringDelete(HostName);
  5. /* Create a function instance and add into the module instance. */
  6. enum WasmEdge_ValType P[3], R[1];
  7. P[0] = WasmEdge_ValType_ExternRef;
  8. P[1] = WasmEdge_ValType_I32;
  9. P[2] = WasmEdge_ValType_I32;
  10. R[0] = WasmEdge_ValType_I32;
  11. WasmEdge_FunctionTypeContext *HostFType = WasmEdge_FunctionTypeCreate(P, 3, R, 1);
  12. WasmEdge_FunctionInstanceContext *HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternFuncMul, NULL, 0);
  13. WasmEdge_FunctionTypeDelete(HostFType);
  14. HostName = WasmEdge_StringCreateByCString("func_mul");
  15. WasmEdge_ModuleInstanceAddFunction(HostMod, HostName, HostFunc);
  16. WasmEdge_StringDelete(HostName);
  17. ...

Execution

Take the test WASM file (this WAT is the corresponding text format) for example. Assume that the funcs.wasm is copied into current directory. The following is the example to execute WASM with externref through the WasmEdge C API.

  1. /* Create the VM context. */
  2. WasmEdge_VMContext *VMCxt = WasmEdge_VMCreate(NULL, NULL);
  3. /* Create the module instance context that contains the host functions. */
  4. WasmEdge_ModuleInstanceContext *HostMod = /* Ignored ... */;
  5. /* Assume that the host functions are added into the module instance above. */
  6. WasmEdge_Value P[3], R[1];
  7. WasmEdge_String FuncName;
  8. WasmEdge_Result Res;
  9. /* Register the module instance into VM. */
  10. Res = WasmEdge_VMRegisterModuleFromImport(VMCxt, HostMod);
  11. if (!WasmEdge_ResultOK(Res)) {
  12. printf("Import object registration failed\n");
  13. return EXIT_FAILURE;
  14. }
  15. /* Load WASM from file. */
  16. Res = WasmEdge_VMLoadWasmFromFile(VMCxt, "funcs.wasm");
  17. if (!WasmEdge_ResultOK(Res)) {
  18. printf("WASM file loading failed\n");
  19. return EXIT_FAILURE;
  20. }
  21. /* Validate WASM. */
  22. Res = WasmEdge_VMValidate(VMCxt);
  23. if (!WasmEdge_ResultOK(Res)) {
  24. printf("WASM validation failed\n");
  25. return EXIT_FAILURE;
  26. }
  27. /* Instantiate the WASM module. */
  28. Res = WasmEdge_VMInstantiate(VMCxt);
  29. if (!WasmEdge_ResultOK(Res)) {
  30. printf("WASM instantiation failed\n");
  31. return EXIT_FAILURE;
  32. }
  33. /* Run a WASM function. */
  34. P[0] = WasmEdge_ValueGenExternRef(AddFunc);
  35. P[1] = WasmEdge_ValueGenI32(1234);
  36. P[2] = WasmEdge_ValueGenI32(5678);
  37. /* Run the `call_add` function. */
  38. FuncName = WasmEdge_StringCreateByCString("call_add");
  39. Res = WasmEdge_VMExecute(VMCxt, FuncName, P, 3, R, 1);
  40. WasmEdge_StringDelete(FuncName);
  41. if (WasmEdge_ResultOK(Res)) {
  42. printf("Run -- `call_add` -- 1234 + 5678 = %d\n",
  43. WasmEdge_ValueGetI32(R[0]));
  44. } else {
  45. printf("Run -- `call_add` -- 1234 + 5678 -- failed\n");
  46. return EXIT_FAILURE;
  47. }

Passing Objects

The above example is passing a function reference as externref. The following examples are about how to pass an object reference into WASM as externref in C++.

Passing a Class

To pass a class as externref, the object instance is needed.

  1. class AddClass {
  2. public:
  3. uint32_t add(uint32_t A, uint32_t B) const { return A + B; }
  4. };
  5. AddClass AC;

Then users can pass the object into WasmEdge by using WasmEdge_ValueGenExternRef() API.

  1. WasmEdge_Value P[3], R[1];
  2. P[0] = WasmEdge_ValueGenExternRef(&AC);
  3. P[1] = WasmEdge_ValueGenI32(1234);
  4. P[2] = WasmEdge_ValueGenI32(5678);
  5. WasmEdge_String FuncName = WasmEdge_StringCreateByCString("call_add");
  6. WasmEdge_Result Res = WasmEdge_VMExecute(VMCxt, FuncName, P, 3, R, 1);
  7. WasmEdge_StringDelete(FuncName);
  8. if (WasmEdge_ResultOK(Res)) {
  9. std::cout << "Result : " << WasmEdge_ValueGetI32(R[0]) std::endl;
  10. // Will print `6912`.
  11. } else {
  12. return EXIT_FAILURE;
  13. }

In the host function which would access the object by reference, users can use the WasmEdge_ValueGetExternRef() API to retrieve the reference to the object.

  1. // Modify the `ExternAdd` in the above tutorial.
  2. WasmEdge_Result ExternAdd(void *, WasmEdge_MemoryInstanceContext *,
  3. const WasmEdge_Value *In, WasmEdge_Value *Out) {
  4. // Function type: {externref, i32, i32} -> {i32}
  5. void *Ptr = WasmEdge_ValueGetExternRef(In[0]);
  6. AddClass &Obj = *reinterpret_cast<AddClass *>(Ptr);
  7. uint32_t C =
  8. Obj.add(WasmEdge_ValueGetI32(In[1]), WasmEdge_ValueGetI32(In[2]));
  9. Out[0] = WasmEdge_ValueGenI32(C);
  10. return WasmEdge_Result_Success;
  11. }

Passing an Object As Functor

As the same as passing a class instance, the functor object instance is needed.

  1. struct SquareStruct {
  2. uint32_t operator()(uint32_t Val) const { return Val * Val; }
  3. };
  4. SquareStruct SS;

Then users can pass the object into WasmEdge by using the WasmEdge_ValueGenExternRef() API.

  1. WasmEdge_Value P[2], R[1];
  2. P[0] = WasmEdge_ValueGenExternRef(&SS);
  3. P[1] = WasmEdge_ValueGenI32(1024);
  4. WasmEdge_String FuncName = WasmEdge_StringCreateByCString("call_square");
  5. WasmEdge_Result Res = WasmEdge_VMExecute(VMCxt, FuncName, P, 2, R, 1);
  6. WasmEdge_StringDelete(FuncName);
  7. if (WasmEdge_ResultOK(Res)) {
  8. std::cout << "Result : " << WasmEdge_ValueGetI32(R[0]) std::endl;
  9. // Will print `1048576`.
  10. } else {
  11. return EXIT_FAILURE;
  12. }

In the host function which would access the object by reference, users can use the WasmEdge_ValueGetExternRef API to retrieve the reference to the object, and the reference is a functor.

  1. // Modify the `ExternSquare` in the above tutorial.
  2. WasmEdge_Result ExternSquare(void *, WasmEdge_MemoryInstanceContext *,
  3. const WasmEdge_Value *In, WasmEdge_Value *Out) {
  4. // Function type: {externref, i32, i32} -> {i32}
  5. void *Ptr = WasmEdge_ValueGetExternRef(In[0]);
  6. SquareStruct &Obj = *reinterpret_cast<SquareStruct *>(Ptr);
  7. uint32_t C = Obj(WasmEdge_ValueGetI32(In[1]));
  8. Out[0] = WasmEdge_ValueGenI32(C);
  9. return WasmEdge_Result_Success;
  10. }

Passing STL Objects

The example Wasm binary (this WAT is the corresponding text format) provides functions to interact with host functions which can access C++ STL objects. Assume that the WASM file stl.wasm is copied into the current directory.

Take the std::ostream and std::string objects for example. Assume that there’s a host function accesses to a std::ostream and a std::string through externrefs:

  1. // Host function to output std::string through std::ostream
  2. WasmEdge_Result ExternSTLOStreamStr(void *, WasmEdge_MemoryInstanceContext *,
  3. const WasmEdge_Value *In,
  4. WasmEdge_Value *) {
  5. // Function type: {externref, externref} -> {}
  6. void *Ptr0 = WasmEdge_ValueGetExternRef(In[0]);
  7. void *Ptr1 = WasmEdge_ValueGetExternRef(In[1]);
  8. std::ostream &RefOS = *reinterpret_cast<std::ostream *>(Ptr0);
  9. std::string &RefStr = *reinterpret_cast<std::string *>(Ptr1);
  10. RefOS << RefStr;
  11. return WasmEdge_Result_Success;
  12. }

Assume that the above host function is added into the module instance HostMod, and the HostMod is registered into a VM context VMCxt. Then users can instantiate the Wasm module:

  1. WasmEdge_Result Res = WasmEdge_VMLoadWasmFromFile(VMCxt, "stl.wasm");
  2. if (!WasmEdge_ResultOK(Res)) {
  3. printf("WASM file loading failed\n");
  4. return EXIT_FAILURE;
  5. }
  6. Res = WasmEdge_VMValidate(VMCxt);
  7. if (!WasmEdge_ResultOK(Res)) {
  8. printf("WASM validation failed\n");
  9. return EXIT_FAILURE;
  10. }
  11. Res = WasmEdge_VMInstantiate(VMCxt);
  12. if (!WasmEdge_ResultOK(Res)) {
  13. printf("WASM instantiation failed\n");
  14. return EXIT_FAILURE;
  15. }

Last, pass the std::cout and a std::string object by external references.

  1. std::string PrintStr("Hello world!");
  2. WasmEdge_Value P[2], R[1];
  3. P[0] = WasmEdge_ValueGenExternRef(&std::cout);
  4. P[1] = WasmEdge_ValueGenExternRef(&PrintStr);
  5. WasmEdge_String FuncName = WasmEdge_StringCreateByCString("call_ostream_str");
  6. WasmEdge_Result Res = WasmEdge_VMExecute(VMCxt, FuncName, P, 2, R, 1);
  7. // Will print "Hello world!" to stdout.
  8. WasmEdge_StringDelete(FuncName);
  9. if (!WasmEdge_ResultOK(Res)) {
  10. return EXIT_FAILURE;
  11. }

For other C++ STL objects cases, such as std::vector<T>, std::map<T, U>, or std::set<T>, the object can be accessed correctly in host functions if the type in reinterpret_cast is correct.