Skip to content

c-api: Tidy up some wasmtime_func_t usage#8461

Merged
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:small-funcref-change
Apr 24, 2024
Merged

c-api: Tidy up some wasmtime_func_t usage#8461
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:small-funcref-change

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

Try to avoid using a transmute in the implementation of the C API and instead use a union like is being done in #8451. Additionally add some helper functions to the header to work with null funcref values instead of only documenting the implementation.

Try to avoid using a `transmute` in the implementation of the C API and
instead use a `union` like is being done in bytecodealliance#8451. Additionally add some
helper functions to the header to work with null funcref values instead
of only documenting the implementation.
@alexcrichton alexcrichton marked this pull request as ready for review April 24, 2024 15:04
@alexcrichton alexcrichton requested a review from a team as a code owner April 24, 2024 15:04
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team April 24, 2024 15:04
@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. labels Apr 24, 2024
@fitzgen fitzgen added this pull request to the merge queue Apr 24, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 24, 2024
@alexcrichton alexcrichton enabled auto-merge April 24, 2024 18:33
@alexcrichton alexcrichton added this pull request to the merge queue Apr 24, 2024
Merged via the queue into bytecodealliance:main with commit c6e4a50 Apr 24, 2024
@alexcrichton alexcrichton deleted the small-funcref-change branch April 24, 2024 19:20
kpreisser added a commit to kpreisser/wasmtime-dotnet that referenced this pull request Jun 24, 2024
This includes updates for:
- bytecodealliance/wasmtime#8451
- bytecodealliance/wasmtime#8461
- bytecodealliance/wasmtime#8011

TODOs:
- Allocating an `externref` can now fail (by `wasmtime_externref_new` returning `false`). Currently, we throw a `WasmtimeException` in that case. We need to check where that exception can be thrown, and whether we need to do any additional clean-up (e.g. when converting arguments for a function call).
- Check whether it's ok to compare the `__private` field of externs (which has been remaned in the C API, previously it was `index`).
- `anyref` type is not yet supported, but I'm not sure what exactly it is and whether we need to add it.

Fixes bytecodealliance#315
jsturtevant pushed a commit to bytecodealliance/wasmtime-dotnet that referenced this pull request Jun 28, 2024
* Update to recent Wasmtime C API changes regarding values.

This includes updates for:
- bytecodealliance/wasmtime#8451
- bytecodealliance/wasmtime#8461
- bytecodealliance/wasmtime#8011

TODOs:
- Allocating an `externref` can now fail (by `wasmtime_externref_new` returning `false`). Currently, we throw a `WasmtimeException` in that case. We need to check where that exception can be thrown, and whether we need to do any additional clean-up (e.g. when converting arguments for a function call).
- Check whether it's ok to compare the `__private` field of externs (which has been remaned in the C API, previously it was `index`).
- `anyref` type is not yet supported, but I'm not sure what exactly it is and whether we need to add it.

Fixes #315

* Follow-Up: Make fields private.

* Ensure to clean-up `Value` instances (in arguments for a function call, and in results for an untyped callback) when e.g. allocating an `externref` fails.

We don't need to do such a clean-up for unchecked function calls that use `ValueRaw` because in that case we don't own `externref` values.

* Avoid accessing the `__private` fields in tests by checking the whole struct for equality (which is the case when all members are equal).

* Use separate dictionaries for caching `Function`, `Memory`, and `Global` objects in the `Store`, which avoids having to explicitly accessing the `__private` field (because the whole struct is now compared).

Additionally, it is more type-safe (since we don't need to cast the `object`).
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