Skip to content

Commit d314c48

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 d314c48

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,25 @@ def _infinite_loop_wasm(self):
214214
return read_test_wasm("loop.wasm")
215215

216216

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

0 commit comments

Comments
 (0)