Skip to content

Commit

Permalink
Merge #1689
Browse files Browse the repository at this point in the history
1689: feat(c-api) Use `Option<NonNull<wasm_valtype_t>>` in `wasm_valtype_kind` r=syrusakbary a=Hywan

A more Rust-FFI idiomatic way to handle null pointer.

Note: In `wasm_valtype_kind`, it's tricky to handle the error because
we _must_ return a `wasm_valtype_kind` value. For the moment, it
continues to panic, which is probably the best tradeoff.

Co-authored-by: Ivan Enderlin <[email protected]>
  • Loading branch information
bors[bot] and Hywan authored Oct 13, 2020
2 parents 41abb4d + 7cc4d5a commit 9c309ea
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/c-api/src/wasm_c_api/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ pub extern "C" fn wasm_valtype_new(kind: wasm_valkind_t) -> Option<Box<wasm_valt
pub unsafe extern "C" fn wasm_valtype_delete(_valtype: Option<Box<wasm_valtype_t>>) {}

#[no_mangle]
pub unsafe extern "C" fn wasm_valtype_kind(valtype: *const wasm_valtype_t) -> wasm_valkind_t {
if valtype.is_null() {
// TODO: handle error
panic!("wasm_valtype_kind: argument is null pointer");
}
return (*valtype).valkind as wasm_valkind_t;
pub unsafe extern "C" fn wasm_valtype_kind(valtype: Option<&wasm_valtype_t>) -> wasm_valkind_t {
valtype
.expect("`wasm_valtype_kind: argument is a null pointer")
.valkind as wasm_valkind_t
}

0 comments on commit 9c309ea

Please sign in to comment.