-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
add C API for epoch_deadline_callback and wasmtime_error_t creation #6359
add C API for epoch_deadline_callback and wasmtime_error_t creation #6359
Conversation
c3d50e6
to
bae24ca
Compare
Subscribe to Label Actioncc @peterhuene
This issue or pull request has been labeled: "wasmtime:c-api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
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 reasonable to me, thanks!
crates/c-api/src/error.rs
Outdated
Some(Box::new(wasmtime_error_t::from(anyhow!("{:?}", unsafe { | ||
std::ffi::CStr::from_ptr(msg) | ||
})))) | ||
} |
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 think instead of :?
this should use .to_str()
on the pointer received to avoid Rust-level string escaping which shows up in the debug representation.
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.
.to_str()
leaves me with the potential to get a Utf8Error
instead of a &str
. I was not sure what the preferred way to deal with such bad input would be, but based on what I see in crates/c-api/src/trap.rs
, I think I will go with String::from_utf8_lossy()
. Sound good?
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.
Yeah I think the _lossy
variant is fine. That's a reality of working with cross-language FFI here but in the context of "just an error message" the lossy variant should be fine.
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.
Thanks, revised.
Hi! From my testing, it seems the new I would have expected a similar behavior as Thanks! |
Ah thanks for testing! That's a mistake in the API and a subtle detail with the implementation. It's definitely not intended that the pointer should remain live, the contents should be copied into the error. The line that needs to change is this one, namely the |
🤦 Sorry, that's my Rust newbieness showing. I missed that |
issue #6277
This adds C API interfaces to: