Stream: git-wasmtime

Topic: wasmtime / Issue #1730 Error occurred when running sample...


view this post on Zulip Wasmtime GitHub notifications bot (May 20 2020 at 09:43):

leonwanghui opened Issue #1730:

Summary

Hi, I was testing with some sample code (with some variants) of wasmtime, but found the error below:

Error: wrong number of imports provided, 0 != 1

I was totally confused of the errors because there is no more addtional debug info, could be appreciated if anyone could take a look, thanks!

Sample code

use anyhow::Result;
use wasmtime::*;

fn main() -> Result<()> {
    let store = Store::default();
    let module = Module::from_file(&store, "/opt/ms_backend_wasm.wasi.wasm")?;
    let instance = Instance::new(&module, &[])?;

    let in_data = vec![1, 2, 3];
    let in_data_ptr = &in_data[0] as *const i32;
    let in_addr = in_data_ptr as i32;
    let in_size: i32 = 3;
    let out_data = vec![0, 0, 0];
    let out_data_ptr = &out_data[0] as *const i32;
    let out_addr = out_data_ptr as i32;
    let out_size: i32 = 3;

    // Invoke `run` export
    let add = instance
        .get_func("run")
        .ok_or(anyhow::format_err!("failed to find `add` function export"))?
        .get7::<i32, i32, i32, i32, i32, i32, i32, i32>()?;

    println!(
        "run({}) = {}",
        0,
        add(0, in_addr, in_size, in_addr, in_size, out_addr, out_size)?
    );
    Ok(())
}

view this post on Zulip Wasmtime GitHub notifications bot (May 20 2020 at 10:48):

leonwanghui edited Issue #1730:

Summary

Hi, I was testing with some sample code (with some variants) of wasmtime, but found the error below:

Error: wrong number of imports provided, 0 != 1

I was totally confused of the errors because there is no more addtional debug info, could be appreciated if anyone could take a look, thanks!

Sample code

use anyhow::Result;
use wasmtime::*;

fn main() -> Result<()> {
    let store = Store::default();
    let module = Module::from_file(&store, "/opt/ms_backend_wasm.wasi.wasm")?;
    let instance = Instance::new(&module, &[])?;

    let in_data = vec![1, 2, 3];
    let in_data_ptr = &in_data[0] as *const i32;
    let in_addr = in_data_ptr as i32;
    let in_size: i32 = 3;
    let out_data = vec![0, 0, 0];
    let out_data_ptr = &out_data[0] as *const i32;
    let out_addr = out_data_ptr as i32;
    let out_size: i32 = 3;

    // Invoke `run` export
    let run = instance
        .get_func("run")
        .ok_or(anyhow::format_err!("failed to find `run` function export"))?
        .get7::<i32, i32, i32, i32, i32, i32, i32, i32>()?;

    println!(
        "run({}) = {}",
        0,
        run(0, in_addr, in_size, in_addr, in_size, out_addr, out_size)?
    );
    Ok(())
}

view this post on Zulip Wasmtime GitHub notifications bot (May 20 2020 at 11:32):

leonwanghui commented on Issue #1730:

Some follow-up info is as below:

# wasmtime /opt/ms_backend_wasm.wasi.wasm --invoke run 0 1 3 1 3 1 3
warning: using `--invoke` with a function that takes arguments is experimental and may break in the future
AddOp init success!
AddOp result is [0, 0, 0]
AddOp run success!
warning: using `--invoke` with a function that returns values is experimental and may break in the future
0

view this post on Zulip Wasmtime GitHub notifications bot (May 20 2020 at 15:42):

alexcrichton commented on Issue #1730:

Thanks for the report! There's a few issues with what's going on here:

view this post on Zulip Wasmtime GitHub notifications bot (May 20 2020 at 15:53):

leonwanghui commented on Issue #1730:

@alexcrichton Thanks, I will have a try, please keep this issue opened in case that something unexpected occurred.

view this post on Zulip Wasmtime GitHub notifications bot (May 22 2020 at 06:54):

leonwanghui commented on Issue #1730:

@alexcrichton Thanks, the issue has been addressed : )

view this post on Zulip Wasmtime GitHub notifications bot (May 22 2020 at 06:54):

leonwanghui closed Issue #1730:

Summary

Hi, I was testing with some sample code (with some variants) of wasmtime, but found the error below:

Error: wrong number of imports provided, 0 != 1

I was totally confused of the errors because there is no more addtional debug info, could be appreciated if anyone could take a look, thanks!

Sample code

use anyhow::Result;
use wasmtime::*;

fn main() -> Result<()> {
    let store = Store::default();
    let module = Module::from_file(&store, "/opt/ms_backend_wasm.wasi.wasm")?;
    let instance = Instance::new(&module, &[])?;

    let in_data = vec![1, 2, 3];
    let in_data_ptr = &in_data[0] as *const i32;
    let in_addr = in_data_ptr as i32;
    let in_size: i32 = 3;
    let out_data = vec![0, 0, 0];
    let out_data_ptr = &out_data[0] as *const i32;
    let out_addr = out_data_ptr as i32;
    let out_size: i32 = 3;

    // Invoke `run` export
    let run = instance
        .get_func("run")
        .ok_or(anyhow::format_err!("failed to find `run` function export"))?
        .get7::<i32, i32, i32, i32, i32, i32, i32, i32>()?;

    println!(
        "run({}) = {}",
        0,
        run(0, in_addr, in_size, in_addr, in_size, out_addr, out_size)?
    );
    Ok(())
}

Last updated: Oct 23 2024 at 20:03 UTC