Skip to content

Add support for structref to the C and C++ APIs#12915

Open
fitzgen wants to merge 2 commits intobytecodealliance:mainfrom
fitzgen:add-structref-support-to-c-api
Open

Add support for structref to the C and C++ APIs#12915
fitzgen wants to merge 2 commits intobytecodealliance:mainfrom
fitzgen:add-structref-support-to-c-api

Conversation

@fitzgen
Copy link
Copy Markdown
Member

@fitzgen fitzgen commented Mar 31, 2026

Also requires adding support for struct and field types, as well as
StructRefPre.

Depends on #12914

fitzgen added 2 commits March 31, 2026 12:25
Also requires adding support for struct and field types, as well as
`StructRefPre`.
@fitzgen fitzgen requested a review from a team as a code owner March 31, 2026 21:39
@fitzgen fitzgen requested review from pchickey and removed request for a team March 31, 2026 21:39
Comment on lines +558 to +569
let storage = match ft.kind {
WASMTIME_I8 => StorageType::I8,
WASMTIME_I16 => StorageType::I16,
crate::WASMTIME_I32 => StorageType::ValType(ValType::I32),
crate::WASMTIME_I64 => StorageType::ValType(ValType::I64),
crate::WASMTIME_F32 => StorageType::ValType(ValType::F32),
crate::WASMTIME_F64 => StorageType::ValType(ValType::F64),
crate::WASMTIME_V128 => StorageType::ValType(ValType::V128),
crate::WASMTIME_FUNCREF => StorageType::ValType(ValType::FUNCREF),
crate::WASMTIME_EXTERNREF => StorageType::ValType(ValType::EXTERNREF),
crate::WASMTIME_ANYREF => StorageType::ValType(ValType::ANYREF),
other => panic!("unknown wasmtime_storage_kind_t: {other}"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

exnref?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah that didn't exist yet, I can rebase and add that here

}

/// Get the underlying C pointer (non-owning).
const wasmtime_struct_ref_pre_t *c_ptr() const { return ptr.get(); }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/c_ptr/capi/

(I think that's used elsewhere throughout).

Also, can this use the WASMTIME_OWN_WRAPPER helper macro? (and maybe some of the other helper macros in other places if applicable?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It may also be worth making a macro for the GC types since they're all going to be quite similar.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There aren't that many GC types and the casts available is all going to defer, so I think I'll avoid a new macro for GC types

Comment on lines +141 to +144
/// \brief An 8-bit packed integer (only valid inside struct/array fields).
#define WASMTIME_I8 8
/// \brief A 16-bit packed integer (only valid inside struct/array fields).
#define WASMTIME_I16 9
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

bikeshed: WASMTIME_STORAGE_KIND_I8?

@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:ref-types Issues related to reference types and GC in Wasmtime labels Mar 31, 2026
@github-actions
Copy link
Copy Markdown

Subscribe to Label Action

cc @fitzgen

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

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

  • fitzgen: wasmtime:ref-types

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

Learn more.

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. wasmtime:ref-types Issues related to reference types and GC in Wasmtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants