c-api: add wasmtime_trap_code#3086
Conversation
Subscribe to Label Actioncc @peterhuene DetailsThis 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 |
alexcrichton
left a comment
There was a problem hiding this comment.
Looks good to me, thanks!
FWIW we don't have much testing of the C API in this repository itself, we currently rely on each of the language bindings repositories to do most of the testing.
| #define WASMTIME_TRAP_CODE_UNREACHABLE_CODE_REACHED | ||
| /// Execution has potentially run too long and may be interrupted. | ||
| #define WASMTIME_TRAP_CODE_INTERRUPT | ||
| }; |
There was a problem hiding this comment.
I think here it's ok to skip the enum { .. } wrapper, and I think the value of each #define constant will need to be listed.
There was a problem hiding this comment.
Oops, I had a bunch of #defines first, then decided to model this after the config enums like
wasmtime/crates/c-api/include/wasmtime/config.h
Lines 56 to 64 in 73fd702
...and didn't follow through properly 😬 I've updated the code using a proper enum instead of defines. What do you think?
There was a problem hiding this comment.
Eh I could go either way, I don't actually know enough about C to know whether these are really that different, and they feel like the same to me. I'm happy to defer to whichever you feel is more appropriate here!
There was a problem hiding this comment.
I'm not a C expert either -- it felt to be a tad more consistent going with the enum definition. Updated ✔️
crates/c-api/include/wasmtime/trap.h
Outdated
| * Returns `true` if the trap is an instruction trap triggered while | ||
| * executing Wasm. If `true` is returned then the trap code is returned | ||
| * through the `code` pointer. If `false` is returned then this is not | ||
| * an instruction trap. |
There was a problem hiding this comment.
Could this describe a situation where false is returned? (e.g. the trap was originally created with wasmtime_trap_new)
| TrapCode::BadConversionToInteger => 8, | ||
| TrapCode::UnreachableCodeReached => 9, | ||
| TrapCode::Interrupt => 10, | ||
| _ => unreachable!(), |
There was a problem hiding this comment.
Could you leave a comment near enum TrapCode and its #[non_exhaustive] that any additions should get added here too?
ad76fb8 to
6cb2bd6
Compare
Eventually this should be added to the wasmtime-go binding, addressing bytecodealliance/wasmtime-go#63. Added a snippet to examples/interrupt.c to verify that this works as expected in manual testing. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
6cb2bd6 to
6e2a6a8
Compare
Subscribe to Label Actioncc @peterhuene DetailsThis issue or pull request has been labeled: "wasmtime:api"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
This complements bytecodealliance/wasmtime#3086 Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
This complements bytecodealliance/wasmtime#3086 Fixes bytecodealliance#63. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
This complements bytecodealliance/wasmtime#3086 Fixes #63. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
This complements bytecodealliance/wasmtime#3086 Fixes #63. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Eventually this should be added to the wasmtime-go binding, addressing
bytecodealliance/wasmtime-go#63.
❓ How would this be tested, short of actually using it from a binding? Happy to add test cases, but I'm afraid I'll need some direction.