Wasmtime
structref.h File Reference

Go to the source code of this file.

Typedefs

typedef struct wasmtime_struct_ref_pre wasmtime_struct_ref_pre_t
 An opaque, pre-allocated, and registered struct layout for faster allocation. More...
 

Functions

WASM_API_EXTERN wasmtime_struct_ref_pre_twasmtime_struct_ref_pre_new (wasmtime_context_t *context, const wasmtime_struct_type_t *ty)
 Create a new struct pre-allocator. More...
 
WASM_API_EXTERN void wasmtime_struct_ref_pre_delete (wasmtime_struct_ref_pre_t *pre)
 Delete a struct pre-allocator.
 
WASM_API_EXTERN wasmtime_error_twasmtime_structref_new (wasmtime_context_t *context, const wasmtime_struct_ref_pre_t *pre, const wasmtime_val_t *fields, size_t nfields, wasmtime_structref_t *out)
 Allocate a new struct instance. More...
 
WASM_API_EXTERN void wasmtime_structref_clone (const wasmtime_structref_t *structref, wasmtime_structref_t *out)
 Clone a structref, creating a new root.
 
WASM_API_EXTERN void wasmtime_structref_unroot (wasmtime_structref_t *ref)
 Unroot a structref to allow garbage collection.
 
WASM_API_EXTERN void wasmtime_structref_to_anyref (const wasmtime_structref_t *structref, wasmtime_anyref_t *out)
 Upcast a structref to an anyref.
 
WASM_API_EXTERN void wasmtime_structref_to_eqref (const wasmtime_structref_t *structref, wasmtime_eqref_t *out)
 Upcast a structref to an eqref.
 
WASM_API_EXTERN wasmtime_error_twasmtime_structref_field (wasmtime_context_t *context, const wasmtime_structref_t *structref, size_t index, wasmtime_val_t *out)
 Read a field from a struct. More...
 
WASM_API_EXTERN wasmtime_error_twasmtime_structref_set_field (wasmtime_context_t *context, const wasmtime_structref_t *structref, size_t index, const wasmtime_val_t *val)
 Set a field of a struct. More...
 

Detailed Description

APIs for interacting with WebAssembly structref type in Wasmtime.

Typedef Documentation

◆ wasmtime_struct_ref_pre_t

typedef struct wasmtime_struct_ref_pre wasmtime_struct_ref_pre_t

An opaque, pre-allocated, and registered struct layout for faster allocation.

Created from a wasmtime_struct_type_t and a store context. Reusable for allocating many struct instances of the same type.

Owned. Must be deleted with wasmtime_struct_ref_pre_delete.

Function Documentation

◆ wasmtime_struct_ref_pre_new()

WASM_API_EXTERN wasmtime_struct_ref_pre_t * wasmtime_struct_ref_pre_new ( wasmtime_context_t context,
const wasmtime_struct_type_t ty 
)

Create a new struct pre-allocator.

Parameters
contextThe store context.
tyThe struct type.
Returns
Returns a new struct ref pre-allocator.

◆ wasmtime_structref_field()

WASM_API_EXTERN wasmtime_error_t * wasmtime_structref_field ( wasmtime_context_t context,
const wasmtime_structref_t structref,
size_t  index,
wasmtime_val_t out 
)

Read a field from a struct.

Parameters
contextThe store context.
structrefThe struct to read from (not consumed).
indexThe field index.
outReceives the field value on success.
Returns
NULL on success, or a wasmtime_error_t on failure.

◆ wasmtime_structref_new()

WASM_API_EXTERN wasmtime_error_t * wasmtime_structref_new ( wasmtime_context_t context,
const wasmtime_struct_ref_pre_t pre,
const wasmtime_val_t fields,
size_t  nfields,
wasmtime_structref_t out 
)

Allocate a new struct instance.

Parameters
contextThe store context.
preThe struct pre-allocator.
fieldsPointer to array of field values (wasmtime_val_t).
nfieldsNumber of fields (must match the struct type).
outReceives the new structref on success.
Returns
NULL on success, or a wasmtime_error_t on failure.

◆ wasmtime_structref_set_field()

WASM_API_EXTERN wasmtime_error_t * wasmtime_structref_set_field ( wasmtime_context_t context,
const wasmtime_structref_t structref,
size_t  index,
const wasmtime_val_t val 
)

Set a field of a struct.

Parameters
contextThe store context.
structrefThe struct to write to (not consumed).
indexThe field index.
valThe value to write (not consumed; caller must still unroot if applicable).
Returns
NULL on success, or a wasmtime_error_t on failure.