Wasmtime
val.h File Reference
#include <wasm.h>
#include <wasmtime/extern.h>

Go to the source code of this file.

Data Structures

union  wasmtime_valunion
 Container for different kinds of wasm values. More...
 
union  wasmtime_val_raw
 Container for possible wasm values. More...
 
union  wasmtime_val
 Container for different kinds of wasm values. More...
 

Macros

#define WASMTIME_I32   0
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is an i32.
 
#define WASMTIME_I64   1
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is an i64.
 
#define WASMTIME_F32   2
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is a f32.
 
#define WASMTIME_F64   3
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is a f64.
 
#define WASMTIME_V128   4
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is a v128.
 
#define WASMTIME_FUNCREF   5
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is a funcref.
 
#define WASMTIME_EXTERNREF   6
 Value of wasmtime_valkind_t meaning that wasmtime_val_t is an externref.
 

Typedefs

typedef struct wasmtime_externref wasmtime_externref_t
 Convenience alias for wasmtime_externref.
 
typedef uint8_t wasmtime_valkind_t
 Discriminant stored in wasmtime_val::kind.
 
typedef uint8_t wasmtime_v128[16]
 A 128-bit value representing the WebAssembly v128 type. Bytes are stored in little-endian order.
 
typedef union wasmtime_valunion wasmtime_valunion_t
 Convenience alias for wasmtime_valunion.
 
typedef union wasmtime_val_raw wasmtime_val_raw_t
 Convenience alias for wasmtime_val_raw.
 
typedef struct wasmtime_val wasmtime_val_t
 Convenience alias for wasmtime_val_t.
 

Functions

wasmtime_externref_twasmtime_externref_new (void *data, void(*finalizer)(void *))
 Create a new externref value. More...
 
void * wasmtime_externref_data (wasmtime_externref_t *data)
 Get an externref's wrapped data. More...
 
wasmtime_externref_twasmtime_externref_clone (wasmtime_externref_t *ref)
 Creates a shallow copy of the externref argument, returning a separately owned pointer (increases the reference count).
 
void wasmtime_externref_delete (wasmtime_externref_t *ref)
 Decrements the reference count of the ref, deleting it if it's the last reference.
 
wasmtime_externref_twasmtime_externref_from_raw (wasmtime_context_t *context, size_t raw)
 Converts a raw externref value coming from wasmtime_val_raw_t into a wasmtime_externref_t. More...
 
size_t wasmtime_externref_to_raw (wasmtime_context_t *context, const wasmtime_externref_t *ref)
 Converts a wasmtime_externref_t to a raw value suitable for storing into a wasmtime_val_raw_t. More...
 
void wasmtime_val_delete (wasmtime_val_t *val)
 Delets an owned wasmtime_val_t. More...
 
void wasmtime_val_copy (wasmtime_val_t *dst, const wasmtime_val_t *src)
 Copies src into dst.
 

Detailed Description

APIs for interacting with WebAssembly values in Wasmtime.

Function Documentation

◆ wasmtime_externref_data()

void * wasmtime_externref_data ( wasmtime_externref_t data)

Get an externref's wrapped data.

Returns the original data passed to wasmtime_externref_new. It is required that data is not NULL.

◆ wasmtime_externref_from_raw()

wasmtime_externref_t * wasmtime_externref_from_raw ( wasmtime_context_t context,
size_t  raw 
)

Converts a raw externref value coming from wasmtime_val_raw_t into a wasmtime_externref_t.

Note that the returned wasmtime_externref_t is an owned value that must be deleted via wasmtime_externref_delete by the caller if it is non-null.

◆ wasmtime_externref_new()

wasmtime_externref_t * wasmtime_externref_new ( void *  data,
void(*)(void *)  finalizer 
)

Create a new externref value.

Creates a new externref value wrapping the provided data, returning the pointer to the externref.

Parameters
datathe host-specific data to wrap
finalizeran optional finalizer for data

When the reference is reclaimed, the wrapped data is cleaned up with the provided finalizer.

The returned value must be deleted with wasmtime_externref_delete

◆ wasmtime_externref_to_raw()

size_t wasmtime_externref_to_raw ( wasmtime_context_t context,
const wasmtime_externref_t ref 
)

Converts a wasmtime_externref_t to a raw value suitable for storing into a wasmtime_val_raw_t.

Note that the returned underlying value is not tracked by Wasmtime's garbage collector until it enters WebAssembly. This means that a GC may release the context's reference to the raw value, making the raw value invalid within the context of the store. Do not perform a GC between calling this function and passing it to WebAssembly.

◆ wasmtime_val_delete()

void wasmtime_val_delete ( wasmtime_val_t val)

Delets an owned wasmtime_val_t.

Note that this only deletes the contents, not the memory that val points to itself (which is owned by the caller).