Skip to content

Commit

Permalink
Fix bug relating to type conversion in function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed Sep 8, 2020
1 parent 8313c35 commit 7c94095
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/api/src/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,39 @@ mod inner {
};
}

macro_rules! from_to_native_wasm_type_same_size {
( $( $type:ty => $native_type:ty ),* ) => {
$(
#[allow(clippy::use_self)]
unsafe impl FromToNativeWasmType for $type {
type Native = $native_type;

#[inline]
fn from_native(native: Self::Native) -> Self {
unsafe {
std::mem::transmute::<$native_type, $type>(native)
}
}

#[inline]
fn to_native(self) -> Self::Native {
unsafe {
std::mem::transmute::<$type, $native_type>(self)
}
}
}
)*
};
}

from_to_native_wasm_type!(
i8 => i32,
u8 => i32,
i16 => i32,
u16 => i32,
u16 => i32
);

from_to_native_wasm_type_same_size!(
i32 => i32,
u32 => i32,
i64 => i64,
Expand Down

0 comments on commit 7c94095

Please sign in to comment.