wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

Feature Request - support native API parameter with known struct size

Open AfflatusX opened this issue 4 years ago • 1 comments

Recently I tried to debug some memory consumption issue within the AssemblyScript app - and the official way of doing so is through rtrace: https://github.com/AssemblyScript/assemblyscript/tree/main/lib/rtrace

Essentially in AS's memory module it calls external tracing functions. I tried to register native APIs to provide these functions, but in their runtime they send a struct over (instead of plain int).

Reading documentation, sounds like the only way to send struct over the boundary is using "*~" and caller needs to pass down the length as well. I see how this applies to raw byte buffer, but for structs we know the size already, can we add support to following syntax:

"*4" represents a pointer with 4 bytes length. This way we don't have to do the pack/unpack manually nor changing caller signature. (In this case we can't since it's third party library)

AfflatusX avatar Jun 03 '21 15:06 AfflatusX

@AfflatusX, For the "Essentially in AS's memory module it calls external tracing functions. " you said above, Do you refer to the following trace function in AssemblyScript?

function trace(
  message: string,
  n: i32 = 0, // number of given parameters a0 to a4
  a0?: f64,
  a1?: f64,
  a2?: f64,
  a3?: f64,
  a4?: f64
): void

JavanZhu avatar Nov 15 '21 07:11 JavanZhu