Stream: general

Topic: Python Wasmtime problem


view this post on Zulip John Marvin Cadacio (Feb 16 2021 at 11:06):

I have a function written in Rust that takes a parameter of usize, and returns a mut u8. How do I call this type of function in Python?

view this post on Zulip bjorn3 (Feb 16 2021 at 11:08):

Wasm only has the i32 and i64 types. usize maps to i32 as wasm uses 32bit pointers. Everything smaller than i32 also maps to i32. I am not sure if it is zero or sign extended though.

view this post on Zulip John Marvin Cadacio (Feb 16 2021 at 11:10):

What I have done was casting my int to int32 using NumPy. However, I get an error when converting.

view this post on Zulip bjorn3 (Feb 16 2021 at 11:10):

What is the error?

view this post on Zulip bjorn3 (Feb 16 2021 at 11:11):

In the example I don't see any casting necessary: https://github.com/bytecodealliance/wasmtime-py/blob/82e61606594b5fbf7199a2e9a1fbbc881261abbb/examples/multi.py#L33-L34

Python WebAssembly runtime powered by Wasmtime. Contribute to bytecodealliance/wasmtime-py development by creating an account on GitHub.

view this post on Zulip John Marvin Cadacio (Feb 16 2021 at 11:17):

When I called a function that returns a mutable u8, I get a mut u8 1209328 from Rust. However, I need to use that value in another Wasm function, and it fails because it cannot be casted to int32 for some reason.

view this post on Zulip bjorn3 (Feb 16 2021 at 11:18):

I unfortunately don't think I can help any further. I haven't ever used wasmtime-py.

view this post on Zulip John Marvin Cadacio (Feb 16 2021 at 11:19):

Thank you for the help.

view this post on Zulip John Marvin Cadacio (Feb 16 2021 at 12:21):

@bjorn3 Nevermind, I managed to fix the problem by not casting it int32at all.


Last updated: Dec 23 2024 at 12:05 UTC