Skip to content

wasm_val_t missmatch in Rust vs C causing errors in wasmi_c_api #1669

@dimitris-aspetakis

Description

@dimitris-aspetakis

Hi! I was trying to use wasmi_c_api in one of my projects, and stumbled upon an error on v0.51.1, c_api/src/func.rs:203. I ended up chasing the error and found out through print-debugging that I was getting only half of the parameters I was trying to pass from the C side.

Upon closer inspection, this is what I gathered:

Here is the struct definition in C:

typedef struct wasm_val_t {
  wasm_valkind_t kind;
  union {
    int32_t i32;
    int64_t i64;
    float32_t f32;
    float64_t f64;
    struct wasm_ref_t* ref;
  } of;
} wasm_val_t;

And here in Rust:

pub struct wasm_val_t {
    /// The kind of the Wasm value.
    pub kind: wasm_valkind_t,
    /// The underlying data of the Wasm value classified by `kind`.
    pub of: wasm_val_union,
}

Importantly, wasm_val_union includes a u128 field, making it 16 bytes instead of the 8 in the C version:

pub union wasm_val_union {
    /// A Wasm 32-bit signed integer.
    pub i32: i32,
    /// A Wasm 64-bit signed integer.
    pub i64: i64,
    /// A Wasm 32-bit unsigned integer.
    pub u32: u32,
    /// A Wasm 64-bit unsigned integer.
    pub u64: u64,
    /// A Wasm 32-bit float.
    pub f32: f32,
    /// A Wasm 64-bit float.
    pub f64: f64,
    /// A Wasm `v128` value.
    pub v128: u128,
    /// A Wasm referenced object.
    pub ref_: *mut wasm_ref_t,
}

…and hence a difference in pointer arithmetic when iterating through wasm_val_vec_t objects.

As a total newcomer to the project, I don't think I have the capacity to track down exactly what's up with the missing value type in C, and which files I should touch — sorry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions