Stream: git-wasmtime

Topic: wasmtime / issue #15216 C API: `wasmtime_anyref_is_i31` r...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 10 2026 at 14:55):

o-murphy opened issue #15216:

Thanks for filing a bug report! Please fill out the TODOs below.

Note: if you want to report a security issue, please read our security policy!

Test Case

The test case is this module, given as WAT (test.wat):

(module
  (type $s (struct (field i32)))
  (func (export "i31") (result anyref) (ref.i31 (i32.const 5)))
  (func (export "st")  (result anyref) (struct.new_default $s)))

The calls go through the C API, using the wasmtime Python package's ctypes bindings (wasmtime._ffi). Its declaration matches include/wasmtime/anyref.h:

bool wasmtime_anyref_is_i31(wasmtime_context_t *context, const wasmtime_anyref_t *anyref);

repro.py:

import ctypes, wasmtime
from wasmtime import _ffi as ffi

cfg = wasmtime.Config()
cfg.wasm_gc = True
cfg.wasm_function_references = True
eng = wasmtime.Engine(cfg)
store = wasmtime.Store(eng)
inst = wasmtime.Instance(store, wasmtime.Module.from_file(eng, "test.wat"), [])

for name in ("i31", "st"):
    f = inst.exports(store)[name]
    res = (ffi.wasmtime_val_t * 1)()
    trap = ctypes.POINTER(ffi.wasm_trap_t)()
    assert not ffi.wasmtime_func_call(store._context(), ctypes.byref(f._func),
                                      None, 0, res, 1, ctypes.byref(trap))
    ctx, ref = store._context(), ctypes.byref(res[0].of.anyref)
    print(name,
          "is_i31", ffi.wasmtime_anyref_is_i31(ctx, ref),
          "i31_get_u", ffi.wasmtime_anyref_i31_get_u(ctx, ref, ctypes.byref(ctypes.c_uint32())),
          "is_struct", ffi.wasmtime_anyref_is_struct(ctx, ref))

Steps to Reproduce

Expected Results

i31 is_i31 True i31_get_u True is_struct False
st is_i31 False i31_get_u False is_struct True

wasmtime_anyref_is_i31 should return false for the struct.

In crates/c-api/src/anyref.rs, wasmtime_anyref_is_i31 and wasmtime_anyref_i31_get_u both call AnyRef::is_i31. So the two should never disagree on the same value.

Actual Results

i31 is_i31 True i31_get_u True is_struct False
st is_i31 True i31_get_u False is_struct True

For the struct, wasmtime_anyref_is_i31 returns true, while wasmtime_anyref_i31_get_u and wasmtime_anyref_is_struct are correct.

The returned value is not a normalised bool. Calling the same symbol through ctypes.CFUNCTYPE(c_uint64, c_void_p, c_void_p) gives rax = 0xb for the i31 and 0x10 for the struct, not 0 or 1.

It is also true for a host value turned into an anyref by any.convert_extern.

Versions and Environment

Wasmtime version or commit: 50.0.1 (the C library bundled in the wasmtime 50.0.1 Python wheel)

Operating system: Linux (Ubuntu, glibc)

Architecture: x86_64

Extra Info

view this post on Zulip Wasmtime GitHub notifications bot (Nov 10 2026 at 14:55):

o-murphy added the bug label to Issue #15216.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 10 2026 at 16:40):

alexcrichton added the wasmtime:c-api label to Issue #15216.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 10 2026 at 16:56):

alexcrichton closed issue #15216:

Thanks for filing a bug report! Please fill out the TODOs below.

Note: if you want to report a security issue, please read our security policy!

Test Case

The test case is this module, given as WAT (test.wat):

(module
  (type $s (struct (field i32)))
  (func (export "i31") (result anyref) (ref.i31 (i32.const 5)))
  (func (export "st")  (result anyref) (struct.new_default $s)))

The calls go through the C API, using the wasmtime Python package's ctypes bindings (wasmtime._ffi). Its declaration matches include/wasmtime/anyref.h:

bool wasmtime_anyref_is_i31(wasmtime_context_t *context, const wasmtime_anyref_t *anyref);

repro.py:

import ctypes, wasmtime
from wasmtime import _ffi as ffi

cfg = wasmtime.Config()
cfg.wasm_gc = True
cfg.wasm_function_references = True
eng = wasmtime.Engine(cfg)
store = wasmtime.Store(eng)
inst = wasmtime.Instance(store, wasmtime.Module.from_file(eng, "test.wat"), [])

for name in ("i31", "st"):
    f = inst.exports(store)[name]
    res = (ffi.wasmtime_val_t * 1)()
    trap = ctypes.POINTER(ffi.wasm_trap_t)()
    assert not ffi.wasmtime_func_call(store._context(), ctypes.byref(f._func),
                                      None, 0, res, 1, ctypes.byref(trap))
    ctx, ref = store._context(), ctypes.byref(res[0].of.anyref)
    print(name,
          "is_i31", ffi.wasmtime_anyref_is_i31(ctx, ref),
          "i31_get_u", ffi.wasmtime_anyref_i31_get_u(ctx, ref, ctypes.byref(ctypes.c_uint32())),
          "is_struct", ffi.wasmtime_anyref_is_struct(ctx, ref))

Steps to Reproduce

Expected Results

i31 is_i31 True i31_get_u True is_struct False
st is_i31 False i31_get_u False is_struct True

wasmtime_anyref_is_i31 should return false for the struct.

In crates/c-api/src/anyref.rs, wasmtime_anyref_is_i31 and wasmtime_anyref_i31_get_u both call AnyRef::is_i31. So the two should never disagree on the same value.

Actual Results

i31 is_i31 True i31_get_u True is_struct False
st is_i31 True i31_get_u False is_struct True

For the struct, wasmtime_anyref_is_i31 returns true, while wasmtime_anyref_i31_get_u and wasmtime_anyref_is_struct are correct.

The returned value is not a normalised bool. Calling the same symbol through ctypes.CFUNCTYPE(c_uint64, c_void_p, c_void_p) gives rax = 0xb for the i31 and 0x10 for the struct, not 0 or 1.

It is also true for a host value turned into an anyref by any.convert_extern.

Versions and Environment

Wasmtime version or commit: 50.0.1 (the C library bundled in the wasmtime 50.0.1 Python wheel)

Operating system: Linux (Ubuntu, glibc)

Architecture: x86_64

Extra Info

view this post on Zulip Wasmtime GitHub notifications bot (Nov 10 2026 at 16:56):

alexcrichton commented on issue #15216:

This is actually a Rust miscomiple we're affected by. The fix is to update our Rust toolchain used, such as https://github.com/bytecodealliance/wasmtime/pull/15218. That'll eventually percolate to a new release which means wasmtime-py will get fixed. In the meantime I'd recommend skipping wasmtime-py 50


Last updated: Nov 19 2026 at 20:05 UTC