mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 13:48:26 +00:00
feat(c-api) wasm_$name_vec_delete checks the vec is initialized.
In case of a boxed vector, `wasm_$name_vec_delete` now checks that the vec is correctly initialized (by checking the first item only) because transmuting `Vec<*mut T>` to `Vec<Box<T>>`, otherwise it will crash.
This commit is contained in:
@@ -274,7 +274,14 @@ Read the documentation of [`wasm_" $name "_t`] to see more concrete examples."]
|
||||
let vec = &mut *ptr;
|
||||
if !vec.data.is_null() {
|
||||
let data: Vec<*mut [<wasm_ $name _t>]> = Vec::from_raw_parts(vec.data, vec.size, vec.size);
|
||||
let _data: Vec<Box<[<wasm_ $name _t>]>> = ::std::mem::transmute(data);
|
||||
|
||||
// If the vector has been initialized (we check
|
||||
// only the first item), we can transmute items to
|
||||
// `Box`es.
|
||||
if vec.size > 0 && !data[0].is_null() {
|
||||
let _data: Vec<Box<[<wasm_ $name _t>]>> = ::std::mem::transmute(data);
|
||||
}
|
||||
|
||||
vec.data = ::std::ptr::null_mut();
|
||||
vec.size = 0;
|
||||
}
|
||||
@@ -299,7 +306,6 @@ macro_rules! wasm_declare_ref_base {
|
||||
}
|
||||
|
||||
// TODO: finish this...
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user