Skip to content

Commit 15be869

Browse files
committed
fix: float arguments in host function parameters
There was a small typo in _convert_value which logged an error whenever a host function with float argument was called: Exception ignored from cffi callback <function handle_args at 0x7fee3735b480>: Traceback (most recent call last): File ".../extism/extism.py", line 908, in handle_args inp.append(_convert_value(inputs[i])) File ".../extism/extism.py", line 648, in _convert_value elif x.y == 3: AttributeError: cdata 'ExtismVal' has no field 'y'
1 parent 5b8da6e commit 15be869

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

extism/extism.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def _convert_value(x):
644644
return Val(ValType.I64, x.v.i64)
645645
elif x.t == 2:
646646
return Val(ValType.F32, x.v.f32)
647-
elif x.y == 3:
647+
elif x.t == 3:
648648
return Val(ValType.F64, x.v.f64)
649649
return None
650650

tests/test_extism.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ def _infinite_loop_wasm(self):
214214
return read_test_wasm("loop.wasm")
215215

216216

217+
class TestConvertValue(unittest.TestCase):
218+
"""Tests for the _convert_value helper that converts CFFI ExtismVal structs."""
219+
220+
def _make_extism_val(self, t, **kwargs):
221+
"""Create a mock ExtismVal with type tag `t` and value fields."""
222+
val_union = namedtuple("ValUnion", kwargs.keys())(**kwargs)
223+
return namedtuple("ExtismVal", ["t", "v"])(t=t, v=val_union)
224+
225+
def test_convert_f64_value(self):
226+
x = self._make_extism_val(3, f64=3.14)
227+
result = extism.extism._convert_value(x)
228+
self.assertIsNotNone(result, "_convert_value returned None for F64 input")
229+
self.assertEqual(result.t, extism.ValType.F64)
230+
self.assertAlmostEqual(result.value, 3.14)
231+
232+
217233
def read_test_wasm(p):
218234
path = join(dirname(__file__), "..", "wasm", p)
219235
with open(path, "rb") as wasm_file:

0 commit comments

Comments
 (0)