mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 05:01:33 +00:00
Fix broken reference
This commit is contained in:
@ -351,9 +351,7 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
|
|
||||||
let mut func = ir::Function::with_name_signature(name, sig);
|
let mut func = ir::Function::with_name_signature(name, sig);
|
||||||
|
|
||||||
println!("translating function");
|
|
||||||
func_translator.translate(body_bytes, &mut func, &mut func_env)?;
|
func_translator.translate(body_bytes, &mut func, &mut func_env)?;
|
||||||
println!("done translating function");
|
|
||||||
|
|
||||||
func
|
func
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@ use wasmer_runtime::{import::Imports, Instance};
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut instance = create_module_1();
|
let mut instance = create_module_1();
|
||||||
let result = instance.call("get-0", &[]);
|
let result = instance.call("call-overwritten-element", &[]);
|
||||||
println!("result: {:?}", result);
|
println!("result: {:?}", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,14 +20,17 @@ fn main() {
|
|||||||
fn create_module_1() -> Instance {
|
fn create_module_1() -> Instance {
|
||||||
let module_str = r#"(module
|
let module_str = r#"(module
|
||||||
(type (;0;) (func (result i32)))
|
(type (;0;) (func (result i32)))
|
||||||
(import "spectest" "global_i32" (global (;0;) i32))
|
(import "spectest" "table" (table (;0;) 10 anyfunc))
|
||||||
(func (;0;) (type 0) (result i32)
|
(func (;0;) (type 0) (result i32)
|
||||||
get_global 0)
|
i32.const 65)
|
||||||
(func (;1;) (type 0) (result i32)
|
(func (;1;) (type 0) (result i32)
|
||||||
get_global 1)
|
i32.const 66)
|
||||||
(global (;1;) i32 (get_global 0))
|
(func (;2;) (type 0) (result i32)
|
||||||
(export "get-0" (func 0))
|
i32.const 9
|
||||||
(export "get-0-ref" (func 1)))
|
call_indirect (type 0))
|
||||||
|
(export "call-overwritten-element" (func 2))
|
||||||
|
(elem (;0;) (i32.const 9) 0)
|
||||||
|
(elem (;1;) (i32.const 9) 1))
|
||||||
"#;
|
"#;
|
||||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||||
let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new())
|
let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new())
|
||||||
|
@ -307,29 +307,34 @@ impl ImportBacking {
|
|||||||
imports: &mut Imports,
|
imports: &mut Imports,
|
||||||
vmctx: *mut vm::Ctx,
|
vmctx: *mut vm::Ctx,
|
||||||
) -> LinkResult<Self> {
|
) -> LinkResult<Self> {
|
||||||
|
let mut failed = false;
|
||||||
let mut link_errors = vec![];
|
let mut link_errors = vec![];
|
||||||
|
|
||||||
let functions = import_functions(module, imports, vmctx).unwrap_or_else(|le| {
|
let functions = import_functions(module, imports, vmctx).unwrap_or_else(|le| {
|
||||||
|
failed = true;
|
||||||
link_errors.extend(le);
|
link_errors.extend(le);
|
||||||
Map::new().into_boxed_map()
|
Map::new().into_boxed_map()
|
||||||
});
|
});
|
||||||
|
|
||||||
let memories = import_memories(module, imports, vmctx).unwrap_or_else(|le| {
|
let memories = import_memories(module, imports, vmctx).unwrap_or_else(|le| {
|
||||||
|
failed = true;
|
||||||
link_errors.extend(le);
|
link_errors.extend(le);
|
||||||
Map::new().into_boxed_map()
|
Map::new().into_boxed_map()
|
||||||
});
|
});
|
||||||
|
|
||||||
let tables = import_tables(module, imports, vmctx).unwrap_or_else(|le| {
|
let tables = import_tables(module, imports, vmctx).unwrap_or_else(|le| {
|
||||||
|
failed = true;
|
||||||
link_errors.extend(le);
|
link_errors.extend(le);
|
||||||
Map::new().into_boxed_map()
|
Map::new().into_boxed_map()
|
||||||
});
|
});
|
||||||
|
|
||||||
let globals = import_globals(module, imports).unwrap_or_else(|le| {
|
let globals = import_globals(module, imports).unwrap_or_else(|le| {
|
||||||
|
failed = true;
|
||||||
link_errors.extend(le);
|
link_errors.extend(le);
|
||||||
Map::new().into_boxed_map()
|
Map::new().into_boxed_map()
|
||||||
});
|
});
|
||||||
|
|
||||||
if link_errors.len() > 0 {
|
if failed {
|
||||||
Err(link_errors)
|
Err(link_errors)
|
||||||
} else {
|
} else {
|
||||||
Ok(ImportBacking {
|
Ok(ImportBacking {
|
||||||
|
@ -248,9 +248,9 @@ impl InstanceInner {
|
|||||||
) -> (MemoryPointer, Context, Memory) {
|
) -> (MemoryPointer, Context, Memory) {
|
||||||
match mem_index.local_or_import(module) {
|
match mem_index.local_or_import(module) {
|
||||||
LocalOrImport::Local(local_mem_index) => {
|
LocalOrImport::Local(local_mem_index) => {
|
||||||
let vm_mem = &mut self.backing.memories[local_mem_index];
|
let vm_mem = &mut self.backing.vm_memories[local_mem_index];
|
||||||
(
|
(
|
||||||
unsafe { MemoryPointer::new(&mut vm_mem.into_vm_memory(local_mem_index)) },
|
unsafe { MemoryPointer::new(vm_mem) },
|
||||||
Context::Internal,
|
Context::Internal,
|
||||||
*module
|
*module
|
||||||
.memories
|
.memories
|
||||||
@ -313,9 +313,9 @@ impl InstanceInner {
|
|||||||
) -> (TablePointer, Context, Table) {
|
) -> (TablePointer, Context, Table) {
|
||||||
match table_index.local_or_import(module) {
|
match table_index.local_or_import(module) {
|
||||||
LocalOrImport::Local(local_table_index) => {
|
LocalOrImport::Local(local_table_index) => {
|
||||||
let vm_table = &mut self.backing.tables[local_table_index];
|
let vm_table = &mut self.backing.vm_tables[local_table_index];
|
||||||
(
|
(
|
||||||
unsafe { TablePointer::new(&mut vm_table.into_vm_table()) },
|
unsafe { TablePointer::new(vm_table) },
|
||||||
Context::Internal,
|
Context::Internal,
|
||||||
*module
|
*module
|
||||||
.tables
|
.tables
|
||||||
|
@ -7,6 +7,7 @@ use std::{
|
|||||||
/// This is a dynamically-sized slice
|
/// This is a dynamically-sized slice
|
||||||
/// that can only be indexed by the
|
/// that can only be indexed by the
|
||||||
/// correct index type.
|
/// correct index type.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SliceMap<K, V>
|
pub struct SliceMap<K, V>
|
||||||
where
|
where
|
||||||
K: TypedIndex,
|
K: TypedIndex,
|
||||||
|
Reference in New Issue
Block a user