You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have been working on calling wasm export functions recently, and I'm trying to make it though wasmer-c-api. But I've run into a problem that I can't solve.
One wasm export funtion I'd like to call receives a funtion pointer as parameter, the origin C code is here.
intcall_add(inta, intb, int (*add)(int, int)) {
// ...
}
And I'll compile it into wasm(wasi) via clang. And it'll be like this in wat.
And now I want to call this call_add function in another C file through wasmer-c-api, the relative code shows below.
intadd(inta, intb) { returna+b; }
voidcall_function() {
// construct the `args` and `results`// how to pass `add`?wasm_val_targs_val[3] = { WASM_I32_VAL(1), WASM_I32_VAL(2), WASM_I32_VAL(1) };
wasm_val_vec_targs=WASM_ARRAY_VEC(args_val);
wasm_val_tresults_val[1] = { WASM_INIT_VAL };
wasm_val_vec_tres=WASM_ARRAY_VEC(results_val);
// get the function ...// ...// call the functionwasm_func_call(call_add, &args, &res);
}
You may notice that the thrid args should be wrong here. It should be the index of function add in the wasm table. But the problem is that wasmer-c-api doesn't support wasm_table_get or wasm_table_set yet. Except for that, we should also grow the table and put the function to the table which is not supported either. I know this is a problem about the unsupported interfaces. But I just want to know any other ways to make it work.
And in real situation, the function pointer is much more complicated. So trying to implement it in the origin wasm is hard as well.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I have been working on calling wasm export functions recently, and I'm trying to make it though wasmer-c-api. But I've run into a problem that I can't solve.
One wasm export funtion I'd like to call receives a funtion pointer as parameter, the origin C code is here.
And I'll compile it into wasm(wasi) via
clang
. And it'll be like this inwat
.And now I want to call this
call_add
function in another C file through wasmer-c-api, the relative code shows below.You may notice that the thrid args should be wrong here. It should be the index of function
add
in the wasm table. But the problem is that wasmer-c-api doesn't support wasm_table_get or wasm_table_set yet. Except for that, we should also grow the table and put the function to the table which is not supported either. I know this is a problem about the unsupported interfaces. But I just want to know any other ways to make it work.And in real situation, the function pointer is much more complicated. So trying to implement it in the origin wasm is hard as well.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions