Skip to content

c-api: new wasmtime_trap_new_code function #10765

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

Merged

Conversation

dotcarmen
Copy link
Contributor

right now, returning wasmtime-recognized traps from functions is only available to the Rust API. this PR adds a new function wasmtime_trap_new_code to the c api that returns a new wasm_trap_t with the Trap value associated with the given code.

@dotcarmen dotcarmen requested review from a team as code owners May 11, 2025 12:41
@dotcarmen dotcarmen requested review from fitzgen and removed request for a team May 11, 2025 12:41
@dotcarmen dotcarmen force-pushed the c-api-wasmtime-new-trap-code branch 6 times, most recently from e95f7fb to 78ea5b9 Compare May 11, 2025 13:09
@@ -129,7 +131,13 @@ public:
explicit Trap(std::string_view msg)
: Trap(wasmtime_trap_new(msg.data(), msg.size())) {}

/// Returns the descriptive message associated with this trap
/// Creates a new trap with the given wasmtime trap code.
Trap(wasmtime_trap_code_enum code)
Copy link
Contributor Author

@dotcarmen dotcarmen May 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure if this constructor signature is a good idea or if it's desired, i can change it if not :)

@dotcarmen dotcarmen force-pushed the c-api-wasmtime-new-trap-code branch from 78ea5b9 to 388b3ff Compare May 11, 2025 13:24
@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label May 11, 2025
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_u8 I don't think will work for the out-of-fuel trap for example. The convert-to-u8 can probably use trap as u8 nowadays, I'm not sure it was possible to do that when it was originally written. That should make the from_u8 conversion 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.

@dotcarmen dotcarmen force-pushed the c-api-wasmtime-new-trap-code branch 3 times, most recently from 61b2d25 to e527e25 Compare May 11, 2025 21:23
@dotcarmen dotcarmen force-pushed the c-api-wasmtime-new-trap-code branch 4 times, most recently from 1cb87ae to 12b0870 Compare May 11, 2025 22:28
@dotcarmen dotcarmen force-pushed the c-api-wasmtime-new-trap-code branch from 12b0870 to f6848b6 Compare May 11, 2025 22:35
@dotcarmen dotcarmen requested a review from alexcrichton May 11, 2025 22:46
@dotcarmen dotcarmen force-pushed the c-api-wasmtime-new-trap-code branch from f8e4c19 to 5e2dc3e Compare May 13, 2025 10:39
@alexcrichton alexcrichton added this pull request to the merge queue May 15, 2025
Merged via the queue into bytecodealliance:main with commit 23e27ba May 15, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:c-api Issues pertaining to the C API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants