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

Avoid transmute for binding primitive argument types #1907

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions crates/libs/bindgen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,9 @@ impl<'a> Gen<'a> {
_ if self.reader.signature_param_is_convertible(param) => {
quote! { #name.into(), }
}
_ if self.reader.signature_param_is_primitive(param) => {
quote! { #name, }
}
_ => quote! { ::core::mem::transmute(#name), },
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/libs/metadata/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,9 @@ impl<'a> Reader<'a> {
pub fn signature_param_is_convertible(&self, param: &SignatureParam) -> bool {
self.signature_param_maybe_generic(param) && self.type_is_convertible(&param.ty)
}
pub fn signature_param_is_primitive(&self, param: &SignatureParam) -> bool {
self.signature_param_maybe_generic(param) && self.type_is_primitive(&param.ty)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like the name signature_param_maybe_generic is wrong now. I'm not sure exactly what it represents. It's an input param that's not a pointer, not a winrt array, and has no array info. How do we succinctly describe that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep those names don't make sense to me. I'm slowly making my way to these inner helpers.

}
pub fn signature_param_is_generic(&self, param: &SignatureParam) -> bool {
self.signature_param_maybe_generic(param) && (self.signature_param_is_borrowed(param) || self.signature_param_is_param(param) || self.signature_param_is_failible_param(param) || self.signature_param_is_convertible(param))
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

90 changes: 45 additions & 45 deletions crates/libs/windows/src/Windows/Win32/Data/HtmlHelp/mod.rs

Large diffs are not rendered by default.

148 changes: 74 additions & 74 deletions crates/libs/windows/src/Windows/Win32/Data/RightsManagement/mod.rs

Large diffs are not rendered by default.

294 changes: 147 additions & 147 deletions crates/libs/windows/src/Windows/Win32/Data/Xml/MsXml/mod.rs

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions crates/libs/windows/src/Windows/Win32/Data/Xml/XmlLite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
fn CreateXmlReaderInputWithEncodingCodePage(pinputstream: *mut ::core::ffi::c_void, pmalloc: *mut ::core::ffi::c_void, nencodingcodepage: u32, fencodinghint: super::super::super::Foundation::BOOL, pwszbaseuri: ::windows::core::PCWSTR, ppinput: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT;
}
let mut result__ = ::core::mem::MaybeUninit::<*mut ::core::ffi::c_void>::zeroed();
CreateXmlReaderInputWithEncodingCodePage(pinputstream.into().abi(), pmalloc.into().abi(), ::core::mem::transmute(nencodingcodepage), fencodinghint.into(), pwszbaseuri.into(), ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<::windows::core::IUnknown>(result__)
CreateXmlReaderInputWithEncodingCodePage(pinputstream.into().abi(), pmalloc.into().abi(), nencodingcodepage, fencodinghint.into(), pwszbaseuri.into(), ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<::windows::core::IUnknown>(result__)
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`, `\"Win32_Foundation\"`, `\"Win32_System_Com\"`*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_System_Com"))]
Expand Down Expand Up @@ -72,7 +72,7 @@ where
fn CreateXmlWriterOutputWithEncodingCodePage(poutputstream: *mut ::core::ffi::c_void, pmalloc: *mut ::core::ffi::c_void, nencodingcodepage: u32, ppoutput: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT;
}
let mut result__ = ::core::mem::MaybeUninit::<*mut ::core::ffi::c_void>::zeroed();
CreateXmlWriterOutputWithEncodingCodePage(poutputstream.into().abi(), pmalloc.into().abi(), ::core::mem::transmute(nencodingcodepage), ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<::windows::core::IUnknown>(result__)
CreateXmlWriterOutputWithEncodingCodePage(poutputstream.into().abi(), pmalloc.into().abi(), nencodingcodepage, ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<::windows::core::IUnknown>(result__)
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`, `\"Win32_System_Com\"`*"]
#[cfg(feature = "Win32_System_Com")]
Expand Down Expand Up @@ -133,11 +133,11 @@ impl IXmlReader {
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn GetProperty(&self, nproperty: u32) -> ::windows::core::Result<isize> {
let mut result__ = ::core::mem::MaybeUninit::<isize>::zeroed();
(::windows::core::Interface::vtable(self).GetProperty)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(nproperty), ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<isize>(result__)
(::windows::core::Interface::vtable(self).GetProperty)(::windows::core::Interface::as_raw(self), nproperty, ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<isize>(result__)
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn SetProperty(&self, nproperty: u32, pvalue: isize) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).SetProperty)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(nproperty), ::core::mem::transmute(pvalue)).ok()
(::windows::core::Interface::vtable(self).SetProperty)(::windows::core::Interface::as_raw(self), nproperty, pvalue).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn Read(&self, pnodetype: *mut XmlNodeType) -> ::windows::core::HRESULT {
Expand Down Expand Up @@ -374,11 +374,11 @@ impl IXmlWriter {
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn GetProperty(&self, nproperty: u32) -> ::windows::core::Result<isize> {
let mut result__ = ::core::mem::MaybeUninit::<isize>::zeroed();
(::windows::core::Interface::vtable(self).GetProperty)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(nproperty), ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<isize>(result__)
(::windows::core::Interface::vtable(self).GetProperty)(::windows::core::Interface::as_raw(self), nproperty, ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<isize>(result__)
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn SetProperty(&self, nproperty: u32, pvalue: isize) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).SetProperty)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(nproperty), ::core::mem::transmute(pvalue)).ok()
(::windows::core::Interface::vtable(self).SetProperty)(::windows::core::Interface::as_raw(self), nproperty, pvalue).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down Expand Up @@ -408,7 +408,7 @@ impl IXmlWriter {
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteCharEntity(&self, wch: u16) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).WriteCharEntity)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(wch)).ok()
(::windows::core::Interface::vtable(self).WriteCharEntity)(::windows::core::Interface::as_raw(self), wch).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteChars(&self, pwch: &[u16]) -> ::windows::core::Result<()> {
Expand Down Expand Up @@ -521,7 +521,7 @@ impl IXmlWriter {
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteStartDocument(&self, standalone: XmlStandalone) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).WriteStartDocument)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(standalone)).ok()
(::windows::core::Interface::vtable(self).WriteStartDocument)(::windows::core::Interface::as_raw(self), standalone).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteStartElement<'a, P0, P1, P2>(&self, pwszprefix: P0, pwszlocalname: P1, pwsznamespaceuri: P2) -> ::windows::core::Result<()>
Expand All @@ -541,7 +541,7 @@ impl IXmlWriter {
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteSurrogateCharEntity(&self, wchlow: u16, wchhigh: u16) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).WriteSurrogateCharEntity)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(wchlow), ::core::mem::transmute(wchhigh)).ok()
(::windows::core::Interface::vtable(self).WriteSurrogateCharEntity)(::windows::core::Interface::as_raw(self), wchlow, wchhigh).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteWhitespace<'a, P0>(&self, pwszwhitespace: P0) -> ::windows::core::Result<()>
Expand Down Expand Up @@ -647,11 +647,11 @@ impl IXmlWriterLite {
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn GetProperty(&self, nproperty: u32) -> ::windows::core::Result<isize> {
let mut result__ = ::core::mem::MaybeUninit::<isize>::zeroed();
(::windows::core::Interface::vtable(self).GetProperty)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(nproperty), ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<isize>(result__)
(::windows::core::Interface::vtable(self).GetProperty)(::windows::core::Interface::as_raw(self), nproperty, ::core::mem::transmute(result__.as_mut_ptr())).from_abi::<isize>(result__)
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn SetProperty(&self, nproperty: u32, pvalue: isize) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).SetProperty)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(nproperty), ::core::mem::transmute(pvalue)).ok()
(::windows::core::Interface::vtable(self).SetProperty)(::windows::core::Interface::as_raw(self), nproperty, pvalue).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand All @@ -675,7 +675,7 @@ impl IXmlWriterLite {
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteCharEntity(&self, wch: u16) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).WriteCharEntity)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(wch)).ok()
(::windows::core::Interface::vtable(self).WriteCharEntity)(::windows::core::Interface::as_raw(self), wch).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteChars(&self, pwch: &[u16]) -> ::windows::core::Result<()> {
Expand Down Expand Up @@ -777,7 +777,7 @@ impl IXmlWriterLite {
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteStartDocument(&self, standalone: XmlStandalone) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).WriteStartDocument)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(standalone)).ok()
(::windows::core::Interface::vtable(self).WriteStartDocument)(::windows::core::Interface::as_raw(self), standalone).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteStartElement(&self, pwszqname: &[u16]) -> ::windows::core::Result<()> {
Expand All @@ -792,7 +792,7 @@ impl IXmlWriterLite {
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteSurrogateCharEntity(&self, wchlow: u16, wchhigh: u16) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).WriteSurrogateCharEntity)(::windows::core::Interface::as_raw(self), ::core::mem::transmute(wchlow), ::core::mem::transmute(wchhigh)).ok()
(::windows::core::Interface::vtable(self).WriteSurrogateCharEntity)(::windows::core::Interface::as_raw(self), wchlow, wchhigh).ok()
}
#[doc = "*Required features: `\"Win32_Data_Xml_XmlLite\"`*"]
pub unsafe fn WriteWhitespace<'a, P0>(&self, pwszwhitespace: P0) -> ::windows::core::Result<()>
Expand Down
Loading