Skip to content

Commit 19bd155

Browse files
authored
Detect more value types and reduce transmute reliance (#2220)
1 parent 58963c5 commit 19bd155

File tree

291 files changed

+22140
-23028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

291 files changed

+22140
-23028
lines changed

crates/libs/bindgen/src/functions.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,16 @@ fn gen_win_function(gen: &Gen, def: MethodDef) -> TokenStream {
4040

4141
let abi_params = signature.params.iter().map(|p| {
4242
let name = gen.param_name(p.def);
43-
let tokens = gen.type_abi_name(&p.ty);
44-
quote! { #name: #tokens }
43+
match p.kind {
44+
SignatureParamKind::ValueType => {
45+
let abi = gen.type_default_name(&p.ty);
46+
quote! { #name: #abi }
47+
}
48+
_ => {
49+
let abi = gen.type_abi_name(&p.ty);
50+
quote! { #name: #abi }
51+
}
52+
}
4553
});
4654

4755
let extern_abi = gen.reader.method_def_extern_abi(def);

crates/libs/bindgen/src/gen.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ impl<'a> Gen<'a> {
180180
quote! { ::core::mem::ManuallyDrop<#tokens> }
181181
}
182182
}
183+
TypeKind::Delegate => {
184+
if self.reader.type_def_flags(*def).winrt() {
185+
quote! { *mut ::core::ffi::c_void }
186+
} else {
187+
self.type_def_name(*def, &[])
188+
}
189+
}
183190
_ => quote! { *mut ::core::ffi::c_void },
184191
},
185192
Type::MutPtr((kind, pointers)) => {
@@ -831,8 +838,16 @@ impl<'a> Gen<'a> {
831838
quote! { #name: *mut #abi, }
832839
}
833840
} else {
834-
let abi = self.type_abi_name(&p.ty);
835-
quote! { #name: #abi, }
841+
match p.kind {
842+
SignatureParamKind::ValueType => {
843+
let abi = self.type_default_name(&p.ty);
844+
quote! { #name: #abi, }
845+
}
846+
_ => {
847+
let abi = self.type_abi_name(&p.ty);
848+
quote! { #name: #abi, }
849+
}
850+
}
836851
}
837852
});
838853

@@ -853,7 +868,6 @@ impl<'a> Gen<'a> {
853868
quote! { -> () }
854869
}
855870
}
856-
// TODO: consolidate both WinRT and Win32 generation once SignatureParamKind is rich enough
857871
pub fn win32_args(&self, params: &[SignatureParam], kind: SignatureKind) -> TokenStream {
858872
let mut tokens = quote! {};
859873

crates/libs/metadata/src/reader/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ impl<'a> Reader<'a> {
633633
let flags = self.param_flags(param.def);
634634
if param.ty.is_pointer() && (flags.optional() || self.param_is_reserved(param.def)) {
635635
param.kind = SignatureParamKind::OptionalPointer;
636-
} else if self.type_is_primitive(&param.ty) && !param.ty.is_pointer() {
636+
} else if self.type_is_primitive(&param.ty) && (!param.ty.is_pointer() || self.type_is_blittable(&param.ty.deref())) {
637637
param.kind = SignatureParamKind::ValueType;
638638
} else if self.type_is_blittable(&param.ty) {
639639
param.kind = SignatureParamKind::Blittable;
@@ -929,6 +929,7 @@ impl<'a> Reader<'a> {
929929
match self.type_def_kind(row) {
930930
TypeKind::Enum => true,
931931
TypeKind::Struct => self.type_def_is_handle(row),
932+
TypeKind::Delegate => !self.type_def_flags(row).winrt(),
932933
_ => false,
933934
}
934935
}

crates/libs/windows/src/Windows/Win32/AI/MachineLearning/DirectML/mod.rs

Lines changed: 38 additions & 38 deletions
Large diffs are not rendered by default.

crates/libs/windows/src/Windows/Win32/AI/MachineLearning/WinML/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl IMLOperatorAttributes {
2727
where
2828
P0: ::std::convert::Into<::windows::core::PCSTR>,
2929
{
30-
(::windows::core::Vtable::vtable(self).GetAttribute)(::windows::core::Vtable::as_raw(self), name.into(), r#type, elementcount, elementbytesize, ::core::mem::transmute(value)).ok()
30+
(::windows::core::Vtable::vtable(self).GetAttribute)(::windows::core::Vtable::as_raw(self), name.into(), r#type, elementcount, elementbytesize, value).ok()
3131
}
3232
pub unsafe fn GetStringAttributeElementLength<'a, P0>(&self, name: P0, elementindex: u32) -> ::windows::core::Result<u32>
3333
where
@@ -187,7 +187,7 @@ impl IMLOperatorKernelCreationContext {
187187
where
188188
P0: ::std::convert::Into<::windows::core::PCSTR>,
189189
{
190-
(::windows::core::Vtable::vtable(self).base__.GetAttribute)(::windows::core::Vtable::as_raw(self), name.into(), r#type, elementcount, elementbytesize, ::core::mem::transmute(value)).ok()
190+
(::windows::core::Vtable::vtable(self).base__.GetAttribute)(::windows::core::Vtable::as_raw(self), name.into(), r#type, elementcount, elementbytesize, value).ok()
191191
}
192192
pub unsafe fn GetStringAttributeElementLength<'a, P0>(&self, name: P0, elementindex: u32) -> ::windows::core::Result<u32>
193193
where
@@ -320,14 +320,14 @@ impl IMLOperatorRegistry {
320320
P0: ::std::convert::Into<::windows::core::InParam<'a, IMLOperatorTypeInferrer>>,
321321
P1: ::std::convert::Into<::windows::core::InParam<'a, IMLOperatorShapeInferrer>>,
322322
{
323-
(::windows::core::Vtable::vtable(self).RegisterOperatorSetSchema)(::windows::core::Vtable::as_raw(self), ::core::mem::transmute(operatorsetid), baselineversion, ::core::mem::transmute(schema.as_deref().map_or(::core::ptr::null(), |slice| slice.as_ptr())), schema.as_deref().map_or(0, |slice| slice.len() as _), typeinferrer.into().abi(), shapeinferrer.into().abi()).ok()
323+
(::windows::core::Vtable::vtable(self).RegisterOperatorSetSchema)(::windows::core::Vtable::as_raw(self), operatorsetid, baselineversion, ::core::mem::transmute(schema.as_deref().map_or(::core::ptr::null(), |slice| slice.as_ptr())), schema.as_deref().map_or(0, |slice| slice.len() as _), typeinferrer.into().abi(), shapeinferrer.into().abi()).ok()
324324
}
325325
pub unsafe fn RegisterOperatorKernel<'a, P0, P1>(&self, operatorkernel: *const MLOperatorKernelDescription, operatorkernelfactory: P0, shapeinferrer: P1) -> ::windows::core::Result<()>
326326
where
327327
P0: ::std::convert::Into<::windows::core::InParam<'a, IMLOperatorKernelFactory>>,
328328
P1: ::std::convert::Into<::windows::core::InParam<'a, IMLOperatorShapeInferrer>>,
329329
{
330-
(::windows::core::Vtable::vtable(self).RegisterOperatorKernel)(::windows::core::Vtable::as_raw(self), ::core::mem::transmute(operatorkernel), operatorkernelfactory.into().abi(), shapeinferrer.into().abi()).ok()
330+
(::windows::core::Vtable::vtable(self).RegisterOperatorKernel)(::windows::core::Vtable::as_raw(self), operatorkernel, operatorkernelfactory.into().abi(), shapeinferrer.into().abi()).ok()
331331
}
332332
}
333333
::windows::core::interface_hierarchy!(IMLOperatorRegistry, ::windows::core::IUnknown);
@@ -375,7 +375,7 @@ impl IMLOperatorShapeInferenceContext {
375375
where
376376
P0: ::std::convert::Into<::windows::core::PCSTR>,
377377
{
378-
(::windows::core::Vtable::vtable(self).base__.GetAttribute)(::windows::core::Vtable::as_raw(self), name.into(), r#type, elementcount, elementbytesize, ::core::mem::transmute(value)).ok()
378+
(::windows::core::Vtable::vtable(self).base__.GetAttribute)(::windows::core::Vtable::as_raw(self), name.into(), r#type, elementcount, elementbytesize, value).ok()
379379
}
380380
pub unsafe fn GetStringAttributeElementLength<'a, P0>(&self, name: P0, elementindex: u32) -> ::windows::core::Result<u32>
381381
where
@@ -414,7 +414,7 @@ impl IMLOperatorShapeInferenceContext {
414414
(::windows::core::Vtable::vtable(self).GetInputTensorShape)(::windows::core::Vtable::as_raw(self), inputindex, dimensions.len() as _, ::core::mem::transmute(dimensions.as_ptr())).ok()
415415
}
416416
pub unsafe fn SetOutputTensorShape(&self, outputindex: u32, dimensioncount: u32, dimensions: *const u32) -> ::windows::core::Result<()> {
417-
(::windows::core::Vtable::vtable(self).SetOutputTensorShape)(::windows::core::Vtable::as_raw(self), outputindex, dimensioncount, ::core::mem::transmute(dimensions)).ok()
417+
(::windows::core::Vtable::vtable(self).SetOutputTensorShape)(::windows::core::Vtable::as_raw(self), outputindex, dimensioncount, dimensions).ok()
418418
}
419419
}
420420
::windows::core::interface_hierarchy!(IMLOperatorShapeInferenceContext, ::windows::core::IUnknown, IMLOperatorAttributes);
@@ -624,7 +624,7 @@ impl IMLOperatorTypeInferenceContext {
624624
where
625625
P0: ::std::convert::Into<::windows::core::PCSTR>,
626626
{
627-
(::windows::core::Vtable::vtable(self).base__.GetAttribute)(::windows::core::Vtable::as_raw(self), name.into(), r#type, elementcount, elementbytesize, ::core::mem::transmute(value)).ok()
627+
(::windows::core::Vtable::vtable(self).base__.GetAttribute)(::windows::core::Vtable::as_raw(self), name.into(), r#type, elementcount, elementbytesize, value).ok()
628628
}
629629
pub unsafe fn GetStringAttributeElementLength<'a, P0>(&self, name: P0, elementindex: u32) -> ::windows::core::Result<u32>
630630
where
@@ -656,7 +656,7 @@ impl IMLOperatorTypeInferenceContext {
656656
(::windows::core::Vtable::vtable(self).GetInputEdgeDescription)(::windows::core::Vtable::as_raw(self), inputindex, result__.as_mut_ptr()).from_abi(result__)
657657
}
658658
pub unsafe fn SetOutputEdgeDescription(&self, outputindex: u32, edgedescription: *const MLOperatorEdgeDescription) -> ::windows::core::Result<()> {
659-
(::windows::core::Vtable::vtable(self).SetOutputEdgeDescription)(::windows::core::Vtable::as_raw(self), outputindex, ::core::mem::transmute(edgedescription)).ok()
659+
(::windows::core::Vtable::vtable(self).SetOutputEdgeDescription)(::windows::core::Vtable::as_raw(self), outputindex, edgedescription).ok()
660660
}
661661
}
662662
::windows::core::interface_hierarchy!(IMLOperatorTypeInferenceContext, ::windows::core::IUnknown, IMLOperatorAttributes);
@@ -801,7 +801,7 @@ impl IWinMLModel {
801801
(::windows::core::Vtable::vtable(self).GetDescription)(::windows::core::Vtable::as_raw(self), result__.as_mut_ptr()).from_abi(result__)
802802
}
803803
pub unsafe fn EnumerateMetadata(&self, index: u32, pkey: *mut ::windows::core::PWSTR, pvalue: *mut ::windows::core::PWSTR) -> ::windows::core::Result<()> {
804-
(::windows::core::Vtable::vtable(self).EnumerateMetadata)(::windows::core::Vtable::as_raw(self), index, ::core::mem::transmute(pkey), ::core::mem::transmute(pvalue)).ok()
804+
(::windows::core::Vtable::vtable(self).EnumerateMetadata)(::windows::core::Vtable::as_raw(self), index, pkey, pvalue).ok()
805805
}
806806
#[doc = "*Required features: `\"Win32_Foundation\"`*"]
807807
#[cfg(feature = "Win32_Foundation")]

crates/libs/windows/src/Windows/Win32/Data/HtmlHelp/impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl IITPropList_Vtbl {
194194
#[cfg(feature = "Win32_Foundation")]
195195
pub trait IITResultSet_Impl: Sized {
196196
fn SetColumnPriority(&self, lcolumnindex: i32, columnpriority: PRIORITY) -> ::windows::core::Result<()>;
197-
fn SetColumnHeap(&self, lcolumnindex: i32, lpvheap: *mut ::core::ffi::c_void, pfncolheapfree: &PFNCOLHEAPFREE) -> ::windows::core::Result<()>;
197+
fn SetColumnHeap(&self, lcolumnindex: i32, lpvheap: *mut ::core::ffi::c_void, pfncolheapfree: PFNCOLHEAPFREE) -> ::windows::core::Result<()>;
198198
fn SetKeyProp(&self, propid: u32) -> ::windows::core::Result<()>;
199199
fn Add(&self, propid: u32, dwdefaultdata: u32, priority: PRIORITY) -> ::windows::core::Result<()>;
200200
fn Add2(&self, propid: u32, lpszwdefault: &::windows::core::PCWSTR, priority: PRIORITY) -> ::windows::core::Result<()>;
@@ -234,10 +234,10 @@ impl IITResultSet_Vtbl {
234234
let this = (*this).get_impl();
235235
this.SetColumnPriority(::core::mem::transmute_copy(&lcolumnindex), ::core::mem::transmute_copy(&columnpriority)).into()
236236
}
237-
unsafe extern "system" fn SetColumnHeap<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IITResultSet_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, lcolumnindex: i32, lpvheap: *mut ::core::ffi::c_void, pfncolheapfree: *mut ::core::ffi::c_void) -> ::windows::core::HRESULT {
237+
unsafe extern "system" fn SetColumnHeap<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IITResultSet_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, lcolumnindex: i32, lpvheap: *mut ::core::ffi::c_void, pfncolheapfree: PFNCOLHEAPFREE) -> ::windows::core::HRESULT {
238238
let this = (this as *const *const ()).offset(OFFSET) as *const Identity;
239239
let this = (*this).get_impl();
240-
this.SetColumnHeap(::core::mem::transmute_copy(&lcolumnindex), ::core::mem::transmute_copy(&lpvheap), ::core::mem::transmute(&pfncolheapfree)).into()
240+
this.SetColumnHeap(::core::mem::transmute_copy(&lcolumnindex), ::core::mem::transmute_copy(&lpvheap), ::core::mem::transmute_copy(&pfncolheapfree)).into()
241241
}
242242
unsafe extern "system" fn SetKeyProp<Identity: ::windows::core::IUnknownImpl<Impl = Impl>, Impl: IITResultSet_Impl, const OFFSET: isize>(this: *mut ::core::ffi::c_void, propid: u32) -> ::windows::core::HRESULT {
243243
let this = (this as *const *const ()).offset(OFFSET) as *const Identity;

0 commit comments

Comments
 (0)