Skip to content

Commit

Permalink
feat(c-api) Transmute boxed vecs to Vec<Option<Box<T>>> when deleting.
Browse files Browse the repository at this point in the history
It's a safer way to handle partially uninitialized boxed vector, since
it protects against based deletion for every item.
  • Loading branch information
Hywan committed Dec 18, 2020
1 parent 51fe219 commit a68a1e6
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions lib/c-api/src/wasm_c_api/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,7 @@ See the [`wasm_" $name "_vec_t`] type to get an example."]
if let Some(vec) = ptr {
if !vec.data.is_null() {
let data: Vec<*mut [<wasm_ $name _t>]> = Vec::from_raw_parts(vec.data, vec.size, vec.size);

// 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);
}
let _data: Vec<Option<Box<[<wasm_ $name _t>]>>> = ::std::mem::transmute(data);

vec.data = ::std::ptr::null_mut();
vec.size = 0;
Expand Down

0 comments on commit a68a1e6

Please sign in to comment.