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
wasmtimePython package's ctypes bindings (wasmtime._ffi). Its declaration matchesinclude/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
pip install wasmtime==50.0.1- Save
test.watandrepro.pyabove in one directory.python repro.pyExpected 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_i31should return false for the struct.In
crates/c-api/src/anyref.rs,wasmtime_anyref_is_i31andwasmtime_anyref_i31_get_uboth callAnyRef::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 TrueFor the struct,
wasmtime_anyref_is_i31returns true, whilewasmtime_anyref_i31_get_uandwasmtime_anyref_is_structare correct.The returned value is not a normalised
bool. Calling the same symbol throughctypes.CFUNCTYPE(c_uint64, c_void_p, c_void_p)givesrax = 0xbfor the i31 and0x10for the struct, not 0 or 1.It is also true for a host value turned into an
anyrefbyany.convert_extern.Versions and Environment
Wasmtime version or commit: 50.0.1 (the C library bundled in the
wasmtime50.0.1 Python wheel)Operating system: Linux (Ubuntu, glibc)
Architecture: x86_64
Extra Info
- Workaround: classify with
wasmtime_anyref_i31_get_u's success flag first, thenwasmtime_anyref_is_struct/wasmtime_anyref_is_array.- I have not checked other platforms, or a C program that links
libwasmtimedirectly instead of the Python wheel's copy.
o-murphy added the bug label to Issue #15216.
alexcrichton added the wasmtime:c-api label to Issue #15216.
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
wasmtimePython package's ctypes bindings (wasmtime._ffi). Its declaration matchesinclude/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
pip install wasmtime==50.0.1- Save
test.watandrepro.pyabove in one directory.python repro.pyExpected 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_i31should return false for the struct.In
crates/c-api/src/anyref.rs,wasmtime_anyref_is_i31andwasmtime_anyref_i31_get_uboth callAnyRef::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 TrueFor the struct,
wasmtime_anyref_is_i31returns true, whilewasmtime_anyref_i31_get_uandwasmtime_anyref_is_structare correct.The returned value is not a normalised
bool. Calling the same symbol throughctypes.CFUNCTYPE(c_uint64, c_void_p, c_void_p)givesrax = 0xbfor the i31 and0x10for the struct, not 0 or 1.It is also true for a host value turned into an
anyrefbyany.convert_extern.Versions and Environment
Wasmtime version or commit: 50.0.1 (the C library bundled in the
wasmtime50.0.1 Python wheel)Operating system: Linux (Ubuntu, glibc)
Architecture: x86_64
Extra Info
- Workaround: classify with
wasmtime_anyref_i31_get_u's success flag first, thenwasmtime_anyref_is_struct/wasmtime_anyref_is_array.- I have not checked other platforms, or a C program that links
libwasmtimedirectly instead of the Python wheel's copy.
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