Skip to content

Commit

Permalink
Limit win32 array params to non-shared length params (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Mar 28, 2022
1 parent 683283b commit b1b9bac
Show file tree
Hide file tree
Showing 44 changed files with 660 additions and 662 deletions.
28 changes: 7 additions & 21 deletions crates/libs/bindgen/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,13 @@ pub fn gen_win32_params(params: &[MethodParam], gen: &Gen) -> TokenStream {
}
}

if let Some(ArrayInfo::RelativeLen(len)) = param.array_info {
if let Some(ArrayInfo::RelativeLen(_)) = param.array_info {
let ty = param.ty.deref();
let ty = gen_default_type(&ty, gen);
let ty = if let Some(ArrayInfo::RelativePtr(Some(_))) = params[len].array_info {
if param.def.flags().output() {
quote! { &mut [#ty] }
} else {
quote! { &[#ty] }
}
let ty = if param.def.flags().output() {
quote! { &mut [#ty] }
} else {
let len: TokenStream = format!("PARAM{}", len).into();
if param.def.flags().output() {
quote! { &mut [#ty; #len] }
} else {
quote! { &[#ty; #len] }
}
quote! { &[#ty] }
};

tokens.combine(&quote! { #name: #ty, });
Expand All @@ -325,7 +316,7 @@ pub fn gen_win32_params(params: &[MethodParam], gen: &Gen) -> TokenStream {
pub fn gen_win32_args(params: &[MethodParam]) -> TokenStream {
let mut tokens = quote! {};

for (position, param) in params.iter().enumerate() {
for param in params {
let name = gen_param_name(&param.def);

if let Some(ArrayInfo::Fixed(fixed)) = param.array_info {
Expand Down Expand Up @@ -353,13 +344,8 @@ pub fn gen_win32_args(params: &[MethodParam]) -> TokenStream {
}

if let Some(ArrayInfo::RelativePtr(relative)) = param.array_info {
if let Some(relative) = relative {
let name = gen_param_name(&params[relative].def);
tokens.combine(&quote! { #name.len() as _, });
} else {
let len: TokenStream = format!("PARAM{}", position).into();
tokens.combine(&quote! { #len as _, });
}
let name = gen_param_name(&params[relative].def);
tokens.combine(&quote! { #name.len() as _, });
continue;
}

Expand Down
5 changes: 1 addition & 4 deletions crates/libs/bindgen/src/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ pub fn gen_param_constraints(params: &[MethodParam], gen: &Gen) -> TokenStream {
let mut tokens = quote! {};

for (position, param) in params.iter().enumerate() {
if let Some(ArrayInfo::RelativePtr(None)) = param.array_info {
let name: TokenStream = format!("PARAM{}", position).into();
tokens.combine(&quote! { const #name: usize, });
} else if param.is_convertible() {
if param.is_convertible() {
let name: TokenStream = format!("Param{}", position).into();
let into = gen_element_name(&param.ty, gen);
tokens.combine(&quote! { #name: ::windows::core::IntoParam<'a, #into>, });
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/metadata/src/reader/array_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
pub enum ArrayInfo {
Fixed(usize),
RelativeLen(usize),
RelativePtr(Option<usize>),
RelativePtr(usize),
}
10 changes: 3 additions & 7 deletions crates/libs/metadata/src/reader/tables/method_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ impl MethodDef {
// The len params must be input only.
// TODO: workaround for https://github.com/microsoft/win32metadata/issues/813
if !params[relative].def.flags().output() && position != relative {
if params[relative].array_info.is_none() {
params[relative].array_info = Some(ArrayInfo::RelativePtr(Some(position)));
} else {
params[relative].array_info = Some(ArrayInfo::RelativePtr(None));
}
params[relative].array_info = Some(ArrayInfo::RelativePtr(position));
} else {
params[position].array_info = None;
}
Expand All @@ -144,9 +140,9 @@ impl MethodDef {
}
}

// Remove any sets that have optional ptr params.
// Remove all sets.
for (len, ptrs) in sets {
if ptrs.len() > 1 && ptrs.iter().any(|ptr| params[*ptr].def.flags().optional()) {
if ptrs.len() > 1 {
params[len].array_info = None;
for ptr in ptrs {
params[ptr].array_info = None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8820,14 +8820,14 @@ pub unsafe fn HidP_UnsetUsages<'a, Param6: ::windows::core::IntoParam<'a, ::wind
#[doc = "*Required features: `\"Win32_Devices_HumanInterfaceDevice\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
#[inline]
pub unsafe fn HidP_UsageListDifference<'a, const PARAM4: usize>(previoususagelist: &[u16; PARAM4], currentusagelist: &[u16; PARAM4], breakusagelist: &mut [u16; PARAM4], makeusagelist: &mut [u16; PARAM4]) -> ::windows::core::Result<()> {
pub unsafe fn HidP_UsageListDifference(previoususagelist: *const u16, currentusagelist: *const u16, breakusagelist: *mut u16, makeusagelist: *mut u16, usagelistlength: u32) -> ::windows::core::Result<()> {
#[cfg(windows)]
{
#[link(name = "windows")]
extern "system" {
fn HidP_UsageListDifference(previoususagelist: *const u16, currentusagelist: *const u16, breakusagelist: *mut u16, makeusagelist: *mut u16, usagelistlength: u32) -> super::super::Foundation::NTSTATUS;
}
HidP_UsageListDifference(::core::mem::transmute(::windows::core::as_ptr_or_null(previoususagelist)), ::core::mem::transmute(::windows::core::as_ptr_or_null(currentusagelist)), ::core::mem::transmute(::windows::core::as_mut_ptr_or_null(breakusagelist)), ::core::mem::transmute(::windows::core::as_mut_ptr_or_null(makeusagelist)), PARAM4 as _).ok()
HidP_UsageListDifference(::core::mem::transmute(previoususagelist), ::core::mem::transmute(currentusagelist), ::core::mem::transmute(breakusagelist), ::core::mem::transmute(makeusagelist), ::core::mem::transmute(usagelistlength)).ok()
}
#[cfg(not(windows))]
unimplemented!("Unsupported target OS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2519,8 +2519,8 @@ pub struct IWiaPropertyStorage(::windows::core::IUnknown);
impl IWiaPropertyStorage {
#[doc = "*Required features: `\"Win32_Devices_ImageAcquisition\"`, `\"Win32_Foundation\"`, `\"Win32_System_Com_StructuredStorage\"`*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_System_Com_StructuredStorage"))]
pub unsafe fn ReadMultiple<'a, const PARAM0: usize>(&self, rgpspec: &[super::super::System::Com::StructuredStorage::PROPSPEC; PARAM0], rgpropvar: &mut [super::super::System::Com::StructuredStorage::PROPVARIANT; PARAM0]) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).ReadMultiple)(::core::mem::transmute_copy(self), PARAM0 as _, ::core::mem::transmute(::windows::core::as_ptr_or_null(rgpspec)), ::core::mem::transmute(::windows::core::as_mut_ptr_or_null(rgpropvar))).ok()
pub unsafe fn ReadMultiple(&self, cpspec: u32, rgpspec: *const super::super::System::Com::StructuredStorage::PROPSPEC, rgpropvar: *mut super::super::System::Com::StructuredStorage::PROPVARIANT) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).ReadMultiple)(::core::mem::transmute_copy(self), ::core::mem::transmute(cpspec), ::core::mem::transmute(rgpspec), ::core::mem::transmute(rgpropvar)).ok()
}
#[doc = "*Required features: `\"Win32_Devices_ImageAcquisition\"`, `\"Win32_Foundation\"`, `\"Win32_System_Com_StructuredStorage\"`*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_System_Com_StructuredStorage"))]
Expand All @@ -2533,12 +2533,12 @@ impl IWiaPropertyStorage {
(::windows::core::Interface::vtable(self).DeleteMultiple)(::core::mem::transmute_copy(self), rgpspec.len() as _, ::core::mem::transmute(::windows::core::as_ptr_or_null(rgpspec))).ok()
}
#[doc = "*Required features: `\"Win32_Devices_ImageAcquisition\"`*"]
pub unsafe fn ReadPropertyNames<'a, const PARAM0: usize>(&self, rgpropid: &[u32; PARAM0], rglpwstrname: &mut [::windows::core::PWSTR; PARAM0]) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).ReadPropertyNames)(::core::mem::transmute_copy(self), PARAM0 as _, ::core::mem::transmute(::windows::core::as_ptr_or_null(rgpropid)), ::core::mem::transmute(::windows::core::as_mut_ptr_or_null(rglpwstrname))).ok()
pub unsafe fn ReadPropertyNames(&self, cpropid: u32, rgpropid: *const u32, rglpwstrname: *mut ::windows::core::PWSTR) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).ReadPropertyNames)(::core::mem::transmute_copy(self), ::core::mem::transmute(cpropid), ::core::mem::transmute(rgpropid), ::core::mem::transmute(rglpwstrname)).ok()
}
#[doc = "*Required features: `\"Win32_Devices_ImageAcquisition\"`*"]
pub unsafe fn WritePropertyNames<'a, const PARAM0: usize>(&self, rgpropid: &[u32; PARAM0], rglpwstrname: &[::windows::core::PWSTR; PARAM0]) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).WritePropertyNames)(::core::mem::transmute_copy(self), PARAM0 as _, ::core::mem::transmute(::windows::core::as_ptr_or_null(rgpropid)), ::core::mem::transmute(::windows::core::as_ptr_or_null(rglpwstrname))).ok()
pub unsafe fn WritePropertyNames(&self, cpropid: u32, rgpropid: *const u32, rglpwstrname: *const ::windows::core::PWSTR) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).WritePropertyNames)(::core::mem::transmute_copy(self), ::core::mem::transmute(cpropid), ::core::mem::transmute(rgpropid), ::core::mem::transmute(rglpwstrname)).ok()
}
#[doc = "*Required features: `\"Win32_Devices_ImageAcquisition\"`*"]
pub unsafe fn DeletePropertyNames(&self, rgpropid: &[u32]) -> ::windows::core::Result<()> {
Expand Down Expand Up @@ -2575,8 +2575,8 @@ impl IWiaPropertyStorage {
}
#[doc = "*Required features: `\"Win32_Devices_ImageAcquisition\"`, `\"Win32_Foundation\"`, `\"Win32_System_Com_StructuredStorage\"`*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_System_Com_StructuredStorage"))]
pub unsafe fn GetPropertyAttributes<'a, const PARAM0: usize>(&self, rgpspec: &[super::super::System::Com::StructuredStorage::PROPSPEC; PARAM0], rgflags: &mut [u32; PARAM0], rgpropvar: &mut [super::super::System::Com::StructuredStorage::PROPVARIANT; PARAM0]) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).GetPropertyAttributes)(::core::mem::transmute_copy(self), PARAM0 as _, ::core::mem::transmute(::windows::core::as_ptr_or_null(rgpspec)), ::core::mem::transmute(::windows::core::as_mut_ptr_or_null(rgflags)), ::core::mem::transmute(::windows::core::as_mut_ptr_or_null(rgpropvar))).ok()
pub unsafe fn GetPropertyAttributes(&self, cpspec: u32, rgpspec: *const super::super::System::Com::StructuredStorage::PROPSPEC, rgflags: *mut u32, rgpropvar: *mut super::super::System::Com::StructuredStorage::PROPVARIANT) -> ::windows::core::Result<()> {
(::windows::core::Interface::vtable(self).GetPropertyAttributes)(::core::mem::transmute_copy(self), ::core::mem::transmute(cpspec), ::core::mem::transmute(rgpspec), ::core::mem::transmute(rgflags), ::core::mem::transmute(rgpropvar)).ok()
}
#[doc = "*Required features: `\"Win32_Devices_ImageAcquisition\"`*"]
pub unsafe fn GetCount(&self) -> ::windows::core::Result<u32> {
Expand Down
Loading

0 comments on commit b1b9bac

Please sign in to comment.