diff --git a/lib/c-api/src/wasm_c_api/macros.rs b/lib/c-api/src/wasm_c_api/macros.rs index 07a99b01545..8132f5cc5c2 100644 --- a/lib/c-api/src/wasm_c_api/macros.rs +++ b/lib/c-api/src/wasm_c_api/macros.rs @@ -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 []> = Vec::from_raw_parts(vec.data, vec.size, vec.size); - let _data: Vec]>> = ::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]>> = ::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... - } }; }