Skip to content

Commit

Permalink
FIXES bytecodealliance#137: make calling wasm from python 7x faster
Browse files Browse the repository at this point in the history
  • Loading branch information
muayyad-alsadi committed Apr 5, 2023
1 parent 4cd48d3 commit 9285e6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion wasmtime/_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def type(self, store: Storelike) -> FuncType:
def _create_raw_vals(self, *params: IntoVal) -> ctypes.Array[wasmtime_val_raw_t]:
raw = self._vals_raw_type()
for i, param_str in enumerate(self._params_str):
val_setter(raw[i], param_str, params[i])
val_setter(self._func.store_id, raw[i], param_str, params[i])
return raw

def _extract_return(self, vals_raw: ctypes.Array[wasmtime_val_raw_t]) -> Union[IntoVal, Sequence[IntoVal], None]:
Expand Down
5 changes: 3 additions & 2 deletions wasmtime/_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def val_getter(store_id: int, val_raw: wasmtime_val_raw_t, attr: str) -> typing.
return val


def val_setter(dst: wasmtime_val_raw_t, attr: str, val: "IntoVal") -> None:
def val_setter(store_id: int, dst: wasmtime_val_raw_t, attr: str, val: "IntoVal") -> None:
casted: typing.Union[Any, int, float, None, wasmtime.Func]
if attr == 'externref':
if isinstance(val, Val) and val._raw and val._raw.kind == WASMTIME_EXTERNREF.value:
Expand All @@ -78,7 +78,8 @@ def val_setter(dst: wasmtime_val_raw_t, attr: str, val: "IntoVal") -> None:
if isinstance(val, Val) and val._raw and val._raw.kind == WASMTIME_FUNCREF.value:
casted = val._raw.of.funcref.index
elif isinstance(val, wasmtime.Func):
# TODO: validate same val._func.store_id
if val._func.store_id != store_id:
raise TypeError("passed funcref does not belong to same store")
casted = val._func.index
else:
raise RuntimeError("expecting param of type funcref got " + type(val).__name__)
Expand Down

0 comments on commit 9285e6c

Please sign in to comment.