Fix module initialization with externref element segments (#2392)
This commit fixes an issue with reference-types-using-modules where they panicked on instantiation if any element segments had an externref null specified.
This commit is contained in:
@@ -1270,15 +1270,19 @@ fn initialize_tables(instance: &Instance) -> Result<(), InstantiationError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i, func_idx) in init.elements.iter().enumerate() {
|
for (i, func_idx) in init.elements.iter().enumerate() {
|
||||||
let anyfunc = instance.get_caller_checked_anyfunc(*func_idx).map_or(
|
let item = match table.element_type() {
|
||||||
ptr::null_mut(),
|
TableElementType::Func => instance
|
||||||
|f: &VMCallerCheckedAnyfunc| {
|
.get_caller_checked_anyfunc(*func_idx)
|
||||||
f as *const VMCallerCheckedAnyfunc as *mut VMCallerCheckedAnyfunc
|
.map_or(ptr::null_mut(), |f: &VMCallerCheckedAnyfunc| {
|
||||||
},
|
f as *const VMCallerCheckedAnyfunc as *mut VMCallerCheckedAnyfunc
|
||||||
);
|
})
|
||||||
table
|
.into(),
|
||||||
.set(u32::try_from(start + i).unwrap(), anyfunc.into())
|
TableElementType::Val(_) => {
|
||||||
.unwrap();
|
assert!(*func_idx == FuncIndex::reserved_value());
|
||||||
|
TableElement::ExternRef(None)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
table.set(u32::try_from(start + i).unwrap(), item).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
(module
|
||||||
|
(table 2 externref)
|
||||||
|
(elem (i32.const 0) externref (ref.null extern))
|
||||||
|
(elem (i32.const 1) externref (ref.null extern))
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user