dotcarmen opened PR #10765 from dotcarmen:c-api-wasmtime-new-trap-code to bytecodealliance:main:
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
right now, returning wasmtime-recognized traps from functions is only available to the Rust API. this PR adds a new functionwasmtime_trap_new_codeto the c api that returns a newwasm_trap_twith theTrapvalue associated with the given code.
dotcarmen requested wasmtime-core-reviewers for a review on PR #10765.
dotcarmen requested fitzgen for a review on PR #10765.
dotcarmen requested wasmtime-default-reviewers for a review on PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen submitted PR review.
dotcarmen created PR review comment:
i kinda figured this is the appropriate way to handle this, if a different way is preferred i can change it :)
dotcarmen deleted PR review comment.
dotcarmen updated PR #10765.
dotcarmen submitted PR review.
dotcarmen created PR review comment:
i'm not sure if this is a good idea or if it's desired, i can change it if not :)
dotcarmen deleted PR review comment.
dotcarmen submitted PR review.
dotcarmen created PR review comment:
i'm not sure if this is a good idea or if it's desired, i can change it if not :)
dotcarmen created PR review comment:
same as above, i'm not sure if
assertis the preferred way to handle this
dotcarmen created PR review comment:
returning a null pointer is kinda an anti-pattern in the wasmtime c-api afaict, but i also think it makes sense here. lmk if a different pattern is preferred
dotcarmen updated PR #10765.
dotcarmen edited PR review comment.
alexcrichton submitted PR review:
Thanks! Would you be up for sync-ing the implementation in C and Rust? The trap code listing here already doesn't match the Rust definition, so using
from_u8I don't think will work for the out-of-fuel trap for example. The convert-to-u8can probably usetrap as u8nowadays, I'm not sure it was possible to do that when it was originally written. That should make thefrom_u8conversion work as well.Additionally would you be up for adding a test for this? Somewhere within this file is probably a good place to go.
alexcrichton created PR review comment:
Mind leaving this to your own personal
~/.gitignore?
alexcrichton created PR review comment:
Another alternative might be to
.unwrap()here, effectively asserting that the code is valid?
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen submitted PR review.
dotcarmen created PR review comment:
hmmm apparently my test command doesn't run the tests in this dir, @alexcrichton what's the command to run these tests? i can document it in c-api/README as well :)
dotcarmen submitted PR review.
dotcarmen created PR review comment:
nvm, found it from ci :)
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen requested alexcrichton for a review on PR #10765.
alexcrichton created PR review comment:
I'm not actually sure how this works, it probably means that our include paths are set up incorrectly? This should already be taken care of below by
<wasmtime/trap.h>I think though?
alexcrichton submitted PR review.
dotcarmen submitted PR review.
dotcarmen created PR review comment:
Ugh I think my LSP keeps sneaking that in. I removed this line before
dotcarmen updated PR #10765.
dotcarmen updated PR #10765.
dotcarmen submitted PR review.
dotcarmen created PR review comment:
removed both accidental includes in 5e2dc3e
alexcrichton submitted PR review.
alexcrichton merged PR #10765.
Last updated: Dec 06 2025 at 06:05 UTC