Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wasm_val_copy for null funcref/externref #2041

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions crates/c-api/src/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ impl Drop for wasm_val_t {

impl Clone for wasm_val_t {
fn clone(&self) -> Self {
match into_valtype(self.kind) {
ValType::ExternRef => wasm_val_t {
kind: self.kind,
of: wasm_val_union {
ref_: unsafe { Box::into_raw(Box::new((*self.of.ref_).clone())) },
},
},
_ => wasm_val_t {
kind: self.kind,
of: self.of,
},
let mut ret = wasm_val_t {
kind: self.kind,
of: self.of,
};
unsafe {
match into_valtype(self.kind) {
ValType::ExternRef | ValType::FuncRef if !self.of.ref_.is_null() => {
ret.of.ref_ = Box::into_raw(Box::new((*self.of.ref_).clone()));
}
_ => {}
}
}
return ret;
}
}

Expand Down Expand Up @@ -139,18 +140,7 @@ impl wasm_val_t {

#[no_mangle]
pub unsafe extern "C" fn wasm_val_copy(out: &mut MaybeUninit<wasm_val_t>, source: &wasm_val_t) {
crate::initialize(
out,
match into_valtype(source.kind) {
ValType::I32
| ValType::I64
| ValType::F32
| ValType::F64
| ValType::ExternRef
| ValType::FuncRef => source.clone(),
_ => unimplemented!("wasm_val_copy arg"),
},
);
crate::initialize(out, source.clone());
}

#[no_mangle]
Expand Down