-
Notifications
You must be signed in to change notification settings - Fork 824
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
feat(runtime-c-api) Implement wasmer_trap
#1133
Conversation
The new `wasmer_import_trap` allows a host function to fail properly with the Wasmer trapping API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea for an update!
Ready for a review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a few small nit-picks:
The naming of wasmer_import_trap
is a little confusing to me, it sounds like it could give you the handle of something that traps that you could use in your import_object. Not sure what else to call it, though and not a huge issue. wasmer_trap
may make more sense, it sounds more like a command to me.
.do_early_trap(Box::new(error_message)); // never returns | ||
|
||
#[allow(unreachable_code)] | ||
wasmer_result_t::WASMER_OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should panic here? Seems like a small thing, not sure what best practice is here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cbindgen doesn't generate a C bindgen for a Rust function with !
as returned type.
Since I need to error before calling do_early_trap
, I've decided to return a wasmer_result_t
. And in the best scenario, I return WASMER_OK
, even if it's unreachable. I'll add more documentation to explain.
lib/runtime-core/src/backend.rs
Outdated
@@ -219,10 +219,11 @@ pub trait RunnableModule: Send + Sync { | |||
} | |||
|
|||
/// A wasm trampoline contains the necessary data to dynamically call an exported wasm function. | |||
/// Given a particular signature index, we are returned a trampoline that is matched with that | |||
/// Given a particular signature index, we are returning a trampoline that is matched with that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer returned
to returning
here;
, we return a trampoline...
is probably best though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was an English typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's grammatically correct and called the "passive voice", it's often discouraged in English though because it takes more words and ends up being less specific. For example, I generally prefer direct writing like, "This function takes a function signature and returns a corresponding trampoline".
Go for |
wasmer_import_trap
wasmer_trap
bors r+ |
1133: feat(runtime-c-api) Implement `wasmer_trap` r=Hywan a=Hywan Idea is to provide an API to get fallible host function by calling `wasmer_trap` to run the Wasmer trapping API. This is probably the easiest solution to not break the existing API, and not add a lot of complexity in the code. Co-authored-by: Ivan Enderlin <[email protected]>
Build succeeded
|
Address wasmerio/wasmer-go#58.
Idea is to provide an API to get fallible host function by calling
wasmer_trap
to run the Wasmer trapping API.This is probably the easiest solution to not break the existing API, and not add a lot of complexity in the code.