Skip to content
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 Wasmtime-specific C API functions to return errors #1467

Merged
merged 8 commits into from
Apr 6, 2020

Conversation

alexcrichton
Copy link
Member

This commit adds new wasmtime_* symbols to the C API, many of which
mirror the existing counterparts in the wasm.h header. These APIs are
enhanced in a number of respects:

  • Detailed error information is now available through a
    wasmtime_error_t. Currently this only exposes one function which is
    to extract a string version of the error.

  • There is a distinction now between traps and errors during
    instantiation and function calling. Traps only happen if wasm traps,
    and errors can happen for things like runtime type errors when
    interacting with the API.

  • APIs have improved safety with respect to embedders where the lengths
    of arrays are now taken as explicit parameters rather than assumed
    from other parameters.

This commit adds new `wasmtime_*` symbols to the C API, many of which
mirror the existing counterparts in the `wasm.h` header. These APIs are
enhanced in a number of respects:

* Detailed error information is now available through a
  `wasmtime_error_t`. Currently this only exposes one function which is
  to extract a string version of the error.

* There is a distinction now between traps and errors during
  instantiation and function calling. Traps only happen if wasm traps,
  and errors can happen for things like runtime type errors when
  interacting with the API.

* APIs have improved safety with respect to embedders where the lengths
  of arrays are now taken as explicit parameters rather than assumed
  from other parameters.
@github-actions github-actions bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API. wasmtime:docs Issues related to Wasmtime's documentation labels Apr 3, 2020
@github-actions
Copy link

github-actions bot commented Apr 3, 2020

Subscribe to Label Action

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

Users Subscribed to "wasmtime:api"
Users Subscribed to "wasmtime:c-api"

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

Learn more.

@github-actions github-actions bot added the fuzzing Issues related to our fuzzing infrastructure label Apr 6, 2020
@github-actions
Copy link

github-actions bot commented Apr 6, 2020

Subscribe to Label Action

This issue or pull request has been labeled: "fuzzing"

Users Subscribed to "fuzzing"

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

Learn more.

Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

👍 Looks great! Just a nit or two and a question about how you want to deal with the .NET CI failures.

examples/fib-debug/main.c Show resolved Hide resolved
examples/fib-debug/main.c Outdated Show resolved Hide resolved
WASMTIME_DECLARE_OWN(linker)

WASM_API_EXTERN own wasmtime_linker_t* wasmtime_linker_new(wasm_store_t* store);

WASM_API_EXTERN void wasmtime_linker_allow_shadowing(wasmtime_linker_t* linker, bool allow_shadowing);

WASM_API_EXTERN bool wasmtime_linker_define(
WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_define(
Copy link
Member

Choose a reason for hiding this comment

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

This (and the similar changes above) is the source of the .NET CI failures since it's now the inverse of what the .NET code is expecting (i.e. return value of 0 is now success rather than failure).

As I'm now moving the .NET code to wasmtime-dotnet, so we just merge this in with failing CI and fix it there or do you want to get this CI green and I'll port the fix to the other repo?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed! Mind double-checking my C# to confirm that what's there is reasonable?

(it's somewhat intentionally not fully fleshed out in every spot since I figured you'll want to tweak APIs further as well)

Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

Just the one comment regarding the null termination of wasmtime error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API. wasmtime:docs Issues related to Wasmtime's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants