Wasmtime
arrayref.h File Reference
#include <wasmtime/conf.h>
#include <wasmtime/types/arrayref.h>
#include <wasmtime/val.h>

Go to the source code of this file.

Typedefs

typedef struct wasmtime_array_ref_pre wasmtime_array_ref_pre_t
 An opaque pre-allocated array layout for fast allocation. More...
 

Functions

WASM_API_EXTERN wasmtime_array_ref_pre_twasmtime_array_ref_pre_new (wasmtime_context_t *context, const wasmtime_array_type_t *ty)
 Create a new array pre-allocator. More...
 
WASM_API_EXTERN void wasmtime_array_ref_pre_delete (wasmtime_array_ref_pre_t *pre)
 Delete an array pre-allocator.
 
WASM_API_EXTERN wasmtime_error_twasmtime_arrayref_new (wasmtime_context_t *context, const wasmtime_array_ref_pre_t *pre, const wasmtime_val_t *elem, uint32_t len, wasmtime_arrayref_t *out)
 Allocate a new array instance. More...
 
WASM_API_EXTERN void wasmtime_arrayref_clone (const wasmtime_arrayref_t *arrayref, wasmtime_arrayref_t *out)
 Clone an arrayref, creating a new root.
 
WASM_API_EXTERN void wasmtime_arrayref_unroot (wasmtime_arrayref_t *ref)
 Unroot an arrayref to allow garbage collection.
 
WASM_API_EXTERN void wasmtime_arrayref_to_anyref (const wasmtime_arrayref_t *arrayref, wasmtime_anyref_t *out)
 Upcast an arrayref to an anyref.
 
WASM_API_EXTERN void wasmtime_arrayref_to_eqref (const wasmtime_arrayref_t *arrayref, wasmtime_eqref_t *out)
 Upcast an arrayref to an eqref.
 
WASM_API_EXTERN wasmtime_error_twasmtime_arrayref_len (wasmtime_context_t *context, const wasmtime_arrayref_t *arrayref, uint32_t *out)
 Get the length of an array. More...
 
WASM_API_EXTERN wasmtime_error_twasmtime_arrayref_get (wasmtime_context_t *context, const wasmtime_arrayref_t *arrayref, uint32_t index, wasmtime_val_t *out)
 Read an element from an array. More...
 
WASM_API_EXTERN wasmtime_error_twasmtime_arrayref_set (wasmtime_context_t *context, const wasmtime_arrayref_t *arrayref, uint32_t index, const wasmtime_val_t *val)
 Set an element of an array. More...
 
WASM_API_EXTERN wasmtime_array_type_twasmtime_arrayref_type (wasmtime_context_t *context, const wasmtime_arrayref_t *arrayref)
 Returns the type of the specified arrayref. More...
 

Detailed Description

APIs for interacting with WebAssembly arrayref type in Wasmtime.

Typedef Documentation

◆ wasmtime_array_ref_pre_t

typedef struct wasmtime_array_ref_pre wasmtime_array_ref_pre_t

An opaque pre-allocated array layout for fast allocation.

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

Owned. Must be deleted with wasmtime_array_ref_pre_delete.

Function Documentation

◆ wasmtime_array_ref_pre_new()

WASM_API_EXTERN wasmtime_array_ref_pre_t * wasmtime_array_ref_pre_new ( wasmtime_context_t context,
const wasmtime_array_type_t ty 
)

Create a new array pre-allocator.

Parameters
contextThe store context.
tyThe array type (not consumed; caller retains ownership).
Returns
Returns a new array ref pre-allocator.

◆ wasmtime_arrayref_get()

WASM_API_EXTERN wasmtime_error_t * wasmtime_arrayref_get ( wasmtime_context_t context,
const wasmtime_arrayref_t arrayref,
uint32_t  index,
wasmtime_val_t out 
)

Read an element from an array.

Parameters
contextThe store context.
arrayrefThe array (not consumed).
indexThe element index.
outReceives the element value on success.
Returns
NULL on success, or a wasmtime_error_t on failure.

◆ wasmtime_arrayref_len()

WASM_API_EXTERN wasmtime_error_t * wasmtime_arrayref_len ( wasmtime_context_t context,
const wasmtime_arrayref_t arrayref,
uint32_t *  out 
)

Get the length of an array.

Parameters
contextThe store context.
arrayrefThe array (not consumed).
outReceives the length on success.
Returns
NULL on success, or a wasmtime_error_t on failure.

◆ wasmtime_arrayref_new()

WASM_API_EXTERN wasmtime_error_t * wasmtime_arrayref_new ( wasmtime_context_t context,
const wasmtime_array_ref_pre_t pre,
const wasmtime_val_t elem,
uint32_t  len,
wasmtime_arrayref_t out 
)

Allocate a new array instance.

All elements are initialized to the same value.

Parameters
contextThe store context.
preThe array pre-allocator.
elemThe initial element value.
lenThe number of elements.
outReceives the new arrayref on success.
Returns
NULL on success, or a wasmtime_error_t on failure.

◆ wasmtime_arrayref_set()

WASM_API_EXTERN wasmtime_error_t * wasmtime_arrayref_set ( wasmtime_context_t context,
const wasmtime_arrayref_t arrayref,
uint32_t  index,
const wasmtime_val_t val 
)

Set an element of an array.

Parameters
contextThe store context.
arrayrefThe array (not consumed).
indexThe element index.
valThe value to write.
Returns
NULL on success, or a wasmtime_error_t on failure.

◆ wasmtime_arrayref_type()

WASM_API_EXTERN wasmtime_array_type_t * wasmtime_arrayref_type ( wasmtime_context_t context,
const wasmtime_arrayref_t arrayref 
)

Returns the type of the specified arrayref.

Returns
If arrayref is NULL or represents ref.null array, then NULL is returned. Otherwise the type of this value is returned. Callers must delete the returned value.