Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve return value types in the C API #4

Open
gzurl opened this issue Oct 18, 2022 · 0 comments
Open

Improve return value types in the C API #4

gzurl opened this issue Oct 18, 2022 · 0 comments
Labels
c-api libwasm_runtime C API 🚀 enhancement New feature or request 💡looking for ideas Issue under discussion and looking for new ideas

Comments

@gzurl
Copy link
Contributor

gzurl commented Oct 18, 2022

@ereslibre initiated an interesting discussion about the return value types in the C API.

Currently, some functions return a *const c_char as a result:

pub extern "C" fn wasm_executionctx_run(executionctx_id: *const c_char) -> *const c_char
pub extern "C" fn wasm_executionctx_create_from_config(config_id: *const c_char) -> *const c_char {

So there is no formal way to distinguish whether the returned data is the expected output or a text explaining the error.

We should explore returning a CResult that looks like this:

struct CResult {
  bool succeeded;
  char *result;
};

Or we could go for this other approach of result-type-in.c.

An example of mod_wasm.c code that is missing error logging is the Wasm execution invocation. We don't know if the returned string was the expected output or not.

const char* module_response = wasm_executionctx_run(exec_ctx_id);

In any case, we should take care of returning the string ownership to Rust.

I am opening this issue to have a discussion about it.

@gzurl gzurl added 🚀 enhancement New feature or request question Further information is requested c-api libwasm_runtime C API labels Oct 18, 2022
@gzurl gzurl added 💡looking for ideas Issue under discussion and looking for new ideas and removed question Further information is requested labels Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-api libwasm_runtime C API 🚀 enhancement New feature or request 💡looking for ideas Issue under discussion and looking for new ideas
Projects
None yet
Development

No branches or pull requests

1 participant