mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 14:18:20 +00:00
feat(c-api) wasm_$name_vec_delete for boxed vec now takes an Option<&mut T>.
This was already the case for regular vec. This patch applies the same
pattern for boxed vec.
See deec77d2df.
This commit is contained in:
@@ -341,21 +341,21 @@ int main() {
|
|||||||
|
|
||||||
See the [`wasm_" $name "_vec_t`] type to get an example."]
|
See the [`wasm_" $name "_vec_t`] type to get an example."]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn [<wasm_ $name _vec_delete>](ptr: *mut [<wasm_ $name _vec_t>]) {
|
pub unsafe extern "C" fn [<wasm_ $name _vec_delete>](ptr: Option<&mut [<wasm_ $name _vec_t>]>) {
|
||||||
let vec = &mut *ptr;
|
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 !vec.data.is_null() {
|
// If the vector has been initialized (we check
|
||||||
let data: Vec<*mut [<wasm_ $name _t>]> = Vec::from_raw_parts(vec.data, vec.size, vec.size);
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
// If the vector has been initialized (we check
|
vec.data = ::std::ptr::null_mut();
|
||||||
// only the first item), we can transmute items to
|
vec.size = 0;
|
||||||
// `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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user