Skip to content

Commit

Permalink
Use std::mem::zeroed with type inference (#2526)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored May 30, 2023
1 parent 593ff2e commit 7b2df65
Show file tree
Hide file tree
Showing 509 changed files with 49,959 additions and 49,965 deletions.
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/com_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn gen(
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<#return_type> #where_clause {
let mut result__ = ::windows_core::zeroed::<#return_type>();
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).from_abi(result__)
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn gen(
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<#return_type> #where_clause {
let mut result__ = ::windows_core::zeroed::<#return_type>();
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args);
::windows_core::from_abi(result__)
}
Expand All @@ -111,7 +111,7 @@ pub fn gen(
#doc
#features
pub unsafe fn #name<#generics>(&self, #params) -> #return_type #where_clause {
let mut result__ = ::windows_core::zeroed::<#return_type>();
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args);
::std::mem::transmute(result__)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#[inline]
pub unsafe fn #name<#generics>(#params) -> ::windows_core::Result<#return_type> #where_clause {
#link
let mut result__ = ::windows_core::zeroed::<#return_type>();
let mut result__ = ::std::mem::zeroed();
#name(#args).from_abi(result__)
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#[inline]
pub unsafe fn #name<#generics>(#params) -> ::windows_core::Result<#return_type> #where_clause {
#link
let mut result__ = ::windows_core::zeroed::<#return_type>();
let mut result__ = ::std::mem::zeroed();
#name(#args);
::windows_core::from_abi(result__.assume_init())
}
Expand All @@ -121,7 +121,7 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
#[inline]
pub unsafe fn #name<#generics>(#params) -> #return_type #where_clause {
#link
let mut result__ = ::windows_core::zeroed::<#return_type>();
let mut result__ = ::std::mem::zeroed();
#name(#args);
::std::mem::transmute(result__)
}
Expand Down
3 changes: 1 addition & 2 deletions crates/libs/bindgen/src/winrt_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ pub fn gen(
}
}
_ => {
let return_type = gen.type_name(&signature.return_type);
quote! {
let mut result__ = ::windows_core::zeroed::<#return_type>();
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).#vname)(::windows_core::Interface::as_raw(this), #args #return_arg)
.from_abi(result__)
}
Expand Down
190 changes: 95 additions & 95 deletions crates/libs/core/src/imp/com_bindings.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/libs/core/src/imp/generic_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct IGenericFactory(crate::IUnknown);
impl IGenericFactory {
pub fn ActivateInstance<I: crate::ComInterface>(&self) -> crate::Result<I> {
unsafe {
let mut result__ = crate::zeroed::<I>();
let mut result__ = std::mem::zeroed();
(crate::Interface::vtable(self).ActivateInstance)(std::mem::transmute_copy(self), &mut result__ as *mut _ as *mut _).from_abi::<crate::IInspectable>(result__)?.cast()
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ where
fn try_into_param(self) -> Result<Param<T>> {
match self {
Some(from) => Ok(Param::Borrowed(from.abi())),
None => Ok(Param::Borrowed(zeroed::<T>())),
None => Ok(Param::Borrowed(unsafe { std::mem::zeroed() })),
}
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ where
fn into_param(self) -> Param<T> {
match self {
Some(item) => Param::Borrowed(item.abi()),
None => Param::Borrowed(zeroed::<T>()),
None => Param::Borrowed(unsafe { std::mem::zeroed() }),
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions crates/libs/core/src/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,3 @@ pub type AbiType<T> = <T as Type<T>>::Abi;
pub unsafe fn from_abi<T: Type<T>>(abi: T::Abi) -> Result<T> {
T::from_abi(abi)
}

#[doc(hidden)]
pub fn zeroed<T: Type<T>>() -> T::Abi {
unsafe { std::mem::zeroed() }
}
Loading

0 comments on commit 7b2df65

Please sign in to comment.