Skip to content

c-api: add wasmtime_trap_code#3086

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
srenatus:sr/c-api/add-trap-code-accessor
Jul 15, 2021
Merged

c-api: add wasmtime_trap_code#3086
alexcrichton merged 1 commit intobytecodealliance:mainfrom
srenatus:sr/c-api/add-trap-code-accessor

Conversation

@srenatus
Copy link
Contributor

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.

@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Jul 14, 2021
@github-actions
Copy link

Subscribe to Label Action

cc @peterhuene

Details This issue or pull request has been labeled: "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:c-api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

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.

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
};
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I had a bunch of #defines first, then decided to model this after the config enums like

enum wasmtime_opt_level_enum { // OptLevel
/// Generated code will not be optimized at all.
WASMTIME_OPT_LEVEL_NONE,
/// Generated code will be optimized purely for speed.
WASMTIME_OPT_LEVEL_SPEED,
/// Generated code will be optimized, but some speed optimizations are
/// disabled if they cause the generated code to be significantly larger.
WASMTIME_OPT_LEVEL_SPEED_AND_SIZE,
};

...and didn't follow through properly 😬 I've updated the code using a proper enum instead of defines. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not a C expert either -- it felt to be a tad more consistent going with the enum definition. Updated ✔️

* 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.
Copy link
Member

Choose a reason for hiding this comment

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

Could this describe a situation where false is returned? (e.g. the trap was originally created with wasmtime_trap_new)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup will do

TrapCode::BadConversionToInteger => 8,
TrapCode::UnreachableCodeReached => 9,
TrapCode::Interrupt => 10,
_ => unreachable!(),
Copy link
Member

Choose a reason for hiding this comment

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

Could you leave a comment near enum TrapCode and its #[non_exhaustive] that any additions should get added here too?

@srenatus srenatus force-pushed the sr/c-api/add-trap-code-accessor branch 2 times, most recently from ad76fb8 to 6cb2bd6 Compare July 15, 2021 11:11
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>
@srenatus srenatus force-pushed the sr/c-api/add-trap-code-accessor branch from 6cb2bd6 to 6e2a6a8 Compare July 15, 2021 11:16
@srenatus srenatus marked this pull request as ready for review July 15, 2021 11:16
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jul 15, 2021
@github-actions
Copy link

Subscribe to Label Action

cc @peterhuene

Details This issue or pull request has been labeled: "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

srenatus added a commit to srenatus/wasmtime-go that referenced this pull request Jul 15, 2021
This complements bytecodealliance/wasmtime#3086

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
@alexcrichton alexcrichton merged commit f3b80ec into bytecodealliance:main Jul 15, 2021
srenatus added a commit to srenatus/wasmtime-go that referenced this pull request Jul 15, 2021
This complements bytecodealliance/wasmtime#3086

Fixes bytecodealliance#63.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
alexcrichton pushed a commit to bytecodealliance/wasmtime-go that referenced this pull request Jul 15, 2021
This complements bytecodealliance/wasmtime#3086

Fixes #63.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
X-leaf7 added a commit to X-leaf7/wasmtime-go that referenced this pull request Jun 24, 2024
This complements bytecodealliance/wasmtime#3086

Fixes #63.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants