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

Make the matches function safe #2761

Merged
merged 4 commits into from
Dec 29, 2023
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
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/rust/implements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
}
}

let mut matches = quote! { *iid == <#type_ident as ::windows_core::ComInterface>::IID };
let mut matches = quote! { iid == &<#type_ident as ::windows_core::ComInterface>::IID };

if let Some(metadata::Type::TypeDef(def, _)) = vtables.last() {
requires.combine(&gen_required_trait(writer, *def, &[]))
Expand All @@ -40,7 +40,7 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
let name = writer.type_def_name(*def, generics);

matches.combine(&quote! {
|| *iid == <#name as ::windows_core::ComInterface>::IID
|| iid == &<#name as ::windows_core::ComInterface>::IID
})
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
#(#named_phantoms)*
}
}
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
pub fn matches(iid: &::windows_core::GUID) -> bool {
#matches
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/src/imp/weak_ref_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl WeakRefCount {
}

/// # Safety
pub unsafe fn query(&self, iid: *const crate::GUID, object: *mut std::ffi::c_void) -> *mut std::ffi::c_void {
if *iid != IWeakReferenceSource::IID {
pub unsafe fn query(&self, iid: &crate::GUID, object: *mut std::ffi::c_void) -> *mut std::ffi::c_void {
if iid != &IWeakReferenceSource::IID {
return std::ptr::null_mut();
}

Expand Down
8 changes: 5 additions & 3 deletions crates/libs/implement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro:
return ::windows::core::HRESULT(-2147467261); // E_POINTER
}

*interface = if *iid == <::windows::core::IUnknown as ::windows::core::ComInterface>::IID
|| *iid == <::windows::core::IInspectable as ::windows::core::ComInterface>::IID
|| *iid == <::windows::core::imp::IAgileObject as ::windows::core::ComInterface>::IID {
let iid = &*iid;

*interface = if iid == &<::windows::core::IUnknown as ::windows::core::ComInterface>::IID
|| iid == &<::windows::core::IInspectable as ::windows::core::ComInterface>::IID
|| iid == &<::windows::core::imp::IAgileObject as ::windows::core::ComInterface>::IID {
&self.identity as *const _ as *mut _
} #(#queries)* else {
::core::ptr::null_mut()
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ impl Interface {
Self { base__: #parent_vtable::new::<#parent_vtable_generics>(), #(#entries),* }
}

pub unsafe fn matches(iid: *const windows::core::GUID) -> bool {
*iid == <#name as ::windows::core::ComInterface>::IID
pub fn matches(iid: &windows::core::GUID) -> bool {
iid == &<#name as ::windows::core::ComInterface>::IID
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/libs/windows/src/Windows/AI/MachineLearning/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl ILearningModelFeatureDescriptor_Vtbl {
IsRequired: IsRequired::<Identity, Impl, OFFSET>,
}
}
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
*iid == <ILearningModelFeatureDescriptor as ::windows_core::ComInterface>::IID
pub fn matches(iid: &::windows_core::GUID) -> bool {
iid == &<ILearningModelFeatureDescriptor as ::windows_core::ComInterface>::IID
}
}
pub trait ILearningModelFeatureValue_Impl: Sized {
Expand All @@ -88,8 +88,8 @@ impl ILearningModelFeatureValue_Vtbl {
}
Self { base__: ::windows_core::IInspectable_Vtbl::new::<Identity, ILearningModelFeatureValue, OFFSET>(), Kind: Kind::<Identity, Impl, OFFSET> }
}
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
*iid == <ILearningModelFeatureValue as ::windows_core::ComInterface>::IID
pub fn matches(iid: &::windows_core::GUID) -> bool {
iid == &<ILearningModelFeatureValue as ::windows_core::ComInterface>::IID
}
}
pub trait ILearningModelOperatorProvider_Impl: Sized {}
Expand All @@ -100,8 +100,8 @@ impl ILearningModelOperatorProvider_Vtbl {
pub const fn new<Identity: ::windows_core::IUnknownImpl<Impl = Impl>, Impl: ILearningModelOperatorProvider_Impl, const OFFSET: isize>() -> ILearningModelOperatorProvider_Vtbl {
Self { base__: ::windows_core::IInspectable_Vtbl::new::<Identity, ILearningModelOperatorProvider, OFFSET>() }
}
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
*iid == <ILearningModelOperatorProvider as ::windows_core::ComInterface>::IID
pub fn matches(iid: &::windows_core::GUID) -> bool {
iid == &<ILearningModelOperatorProvider as ::windows_core::ComInterface>::IID
}
}
#[doc = "Required features: `\"Foundation_Collections\"`"]
Expand Down Expand Up @@ -146,7 +146,7 @@ impl ITensor_Vtbl {
Shape: Shape::<Identity, Impl, OFFSET>,
}
}
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
*iid == <ITensor as ::windows_core::ComInterface>::IID
pub fn matches(iid: &::windows_core::GUID) -> bool {
iid == &<ITensor as ::windows_core::ComInterface>::IID
}
}
Loading