Skip to content

Commit 1a2eccc

Browse files
authored
Make too many imports an instantiation error (#1478)
* Make too many imports an instantiation error Previously we'd accidentally only take the head of the list when instantiating, but instead this changes the API to require exactly the right number of imports.
1 parent 6a68130 commit 1a2eccc

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

crates/api/src/instance.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ impl Instance {
124124
}
125125
}
126126

127+
if imports.len() != module.imports().len() {
128+
bail!(
129+
"wrong number of imports provided, {} != {}",
130+
imports.len(),
131+
module.imports().len()
132+
);
133+
}
134+
127135
module.register_frame_info();
128136
let config = store.engine().config();
129137
let instance_handle = instantiate(

crates/api/tests/instance.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use anyhow::Result;
2+
use wasmtime::*;
3+
4+
#[test]
5+
fn wrong_import_numbers() -> Result<()> {
6+
let store = Store::default();
7+
let module = Module::new(&store, r#"(module (import "" "" (func)))"#)?;
8+
9+
assert!(Instance::new(&module, &[]).is_err());
10+
let func = Func::wrap(&store, || {});
11+
assert!(Instance::new(&module, &[func.clone().into(), func.into()]).is_err());
12+
Ok(())
13+
}

0 commit comments

Comments
 (0)