diff --git a/crates/libs/bindgen/src/rust/delegates.rs b/crates/libs/bindgen/src/rust/delegates.rs index 40d952037e..bcb7bcdf87 100644 --- a/crates/libs/bindgen/src/rust/delegates.rs +++ b/crates/libs/bindgen/src/rust/delegates.rs @@ -102,12 +102,12 @@ fn gen_win_delegate(writer: &Writer, def: TypeDef) -> TokenStream { Invoke: Self::Invoke, #(#named_phantoms)* }; - unsafe extern "system" fn QueryInterface(this: *mut ::core::ffi::c_void, iid: &::windows_core::GUID, interface: *mut *const ::core::ffi::c_void) -> ::windows_core::HRESULT { + unsafe extern "system" fn QueryInterface(this: *mut ::core::ffi::c_void, iid: *const ::windows_core::GUID, interface: *mut *mut ::core::ffi::c_void) -> ::windows_core::HRESULT { let this = this as *mut *mut ::core::ffi::c_void as *mut Self; - *interface = if iid == &<#ident as ::windows_core::ComInterface>::IID || - iid == &<::windows_core::IUnknown as ::windows_core::ComInterface>::IID || - iid == &<::windows_core::imp::IAgileObject as ::windows_core::ComInterface>::IID { + *interface = if *iid == <#ident as ::windows_core::ComInterface>::IID || + *iid == <::windows_core::IUnknown as ::windows_core::ComInterface>::IID || + *iid == <::windows_core::imp::IAgileObject as ::windows_core::ComInterface>::IID { &mut (*this).vtable as *mut _ as _ } else { ::core::ptr::null_mut() diff --git a/crates/libs/bindgen/src/rust/implements.rs b/crates/libs/bindgen/src/rust/implements.rs index 742ae99842..f4a0b4b794 100644 --- a/crates/libs/bindgen/src/rust/implements.rs +++ b/crates/libs/bindgen/src/rust/implements.rs @@ -28,7 +28,7 @@ pub fn writer(writer: &Writer, def: 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(Type::TypeDef(def, _)) = vtables.last() { requires.combine(&gen_required_trait(writer, *def, &[])) @@ -39,7 +39,7 @@ pub fn writer(writer: &Writer, def: TypeDef) -> TokenStream { let name = writer.type_def_name(*def, generics); matches.combine("e! { - || iid == &<#name as ::windows_core::ComInterface>::IID + || *iid == <#name as ::windows_core::ComInterface>::IID }) } } @@ -142,7 +142,7 @@ pub fn writer(writer: &Writer, def: TypeDef) -> TokenStream { #(#named_phantoms)* } } - pub fn matches(iid: &::windows_core::GUID) -> bool { + pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool { #matches } } diff --git a/crates/libs/core/src/com_interface.rs b/crates/libs/core/src/com_interface.rs index 5eae5a1e9c..5259238b9e 100644 --- a/crates/libs/core/src/com_interface.rs +++ b/crates/libs/core/src/com_interface.rs @@ -43,9 +43,8 @@ pub unsafe trait ComInterface: Interface + Clone { /// /// # Safety /// - /// `interface` must be a non-null, valid pointer for writing an interface pointer - #[doc(hidden)] - unsafe fn query(&self, iid: &GUID, interface: *mut *const std::ffi::c_void) -> HRESULT { + /// `interface` must be a non-null, valid pointer for writing an interface pointer. + unsafe fn query(&self, iid: *const GUID, interface: *mut *mut std::ffi::c_void) -> HRESULT { (self.assume_vtable::().QueryInterface)(self.as_raw(), iid, interface) } } diff --git a/crates/libs/core/src/imp/weak_ref_count.rs b/crates/libs/core/src/imp/weak_ref_count.rs index 2f28e7f97b..ee46a6bc33 100644 --- a/crates/libs/core/src/imp/weak_ref_count.rs +++ b/crates/libs/core/src/imp/weak_ref_count.rs @@ -32,8 +32,8 @@ impl WeakRefCount { } /// # Safety - pub unsafe fn query(&self, iid: &crate::GUID, object: *mut std::ffi::c_void) -> *mut std::ffi::c_void { - if iid != &IWeakReferenceSource::IID { + pub unsafe fn query(&self, iid: *const crate::GUID, object: *mut std::ffi::c_void) -> *mut std::ffi::c_void { + if *iid != IWeakReferenceSource::IID { return std::ptr::null_mut(); } @@ -119,16 +119,16 @@ impl TearOff { std::mem::transmute(value << 1) } - unsafe fn query_interface(&self, iid: &crate::GUID, interface: *mut *const std::ffi::c_void) -> crate::HRESULT { + unsafe fn query_interface(&self, iid: *const crate::GUID, interface: *mut *mut std::ffi::c_void) -> crate::HRESULT { ((*(*(self.object as *mut *mut crate::IUnknown_Vtbl))).QueryInterface)(self.object, iid, interface) } - unsafe extern "system" fn StrongQueryInterface(ptr: *mut std::ffi::c_void, iid: &crate::GUID, interface: *mut *const std::ffi::c_void) -> crate::HRESULT { + unsafe extern "system" fn StrongQueryInterface(ptr: *mut std::ffi::c_void, iid: *const crate::GUID, interface: *mut *mut std::ffi::c_void) -> crate::HRESULT { let this = Self::from_strong_ptr(ptr); // Only directly respond to queries for the the tear-off's strong interface. This is // effectively a self-query. - if iid == &IWeakReferenceSource::IID { + if *iid == IWeakReferenceSource::IID { *interface = ptr; this.strong_count.add_ref(); return crate::HRESULT(0); @@ -139,14 +139,14 @@ impl TearOff { this.query_interface(iid, interface) } - unsafe extern "system" fn WeakQueryInterface(ptr: *mut std::ffi::c_void, iid: &crate::GUID, interface: *mut *const std::ffi::c_void) -> crate::HRESULT { + unsafe extern "system" fn WeakQueryInterface(ptr: *mut std::ffi::c_void, iid: *const crate::GUID, interface: *mut *mut std::ffi::c_void) -> crate::HRESULT { let this = Self::from_weak_ptr(ptr); // While the weak vtable is packed into the same allocation as the strong vtable and // tear-off, it represents a distinct COM identity and thus does not share or delegate to // the object. - *interface = if iid == &IWeakReference::IID || iid == &crate::IUnknown::IID || iid == &IAgileObject::IID { ptr } else { std::ptr::null_mut() }; + *interface = if *iid == IWeakReference::IID || *iid == crate::IUnknown::IID || *iid == IAgileObject::IID { ptr } else { std::ptr::null_mut() }; // TODO: implement IMarshal @@ -218,7 +218,7 @@ impl TearOff { }) .map(|_| { // Let the object respond to the upgrade query. - let result = this.query_interface(&*iid, interface as *mut _); + let result = this.query_interface(iid, interface); // Decrement the temporary reference account used to stabilize the object. this.strong_count.0.fetch_sub(1, Ordering::Relaxed); // Return the result of the query. diff --git a/crates/libs/core/src/unknown.rs b/crates/libs/core/src/unknown.rs index a9374c830f..3d3e6d92e6 100644 --- a/crates/libs/core/src/unknown.rs +++ b/crates/libs/core/src/unknown.rs @@ -10,7 +10,7 @@ pub struct IUnknown(std::ptr::NonNull); #[doc(hidden)] #[repr(C)] pub struct IUnknown_Vtbl { - pub QueryInterface: unsafe extern "system" fn(this: *mut std::ffi::c_void, iid: &GUID, interface: *mut *const std::ffi::c_void) -> HRESULT, + pub QueryInterface: unsafe extern "system" fn(this: *mut std::ffi::c_void, iid: *const GUID, interface: *mut *mut std::ffi::c_void) -> HRESULT, pub AddRef: unsafe extern "system" fn(this: *mut std::ffi::c_void) -> u32, pub Release: unsafe extern "system" fn(this: *mut std::ffi::c_void) -> u32, } @@ -71,7 +71,7 @@ pub trait IUnknownImpl { /// /// This function is safe to call as long as the interface pointer is non-null and valid for writes /// of an interface pointer. - unsafe fn QueryInterface(&self, iid: &GUID, interface: *mut *const std::ffi::c_void) -> HRESULT; + unsafe fn QueryInterface(&self, iid: *const GUID, interface: *mut *mut std::ffi::c_void) -> HRESULT; /// Increments the reference count of the interface fn AddRef(&self) -> u32; /// Decrements the reference count causing the interface's memory to be freed when the count is 0 @@ -86,7 +86,7 @@ pub trait IUnknownImpl { #[cfg(feature = "implement")] impl IUnknown_Vtbl { pub const fn new() -> Self { - unsafe extern "system" fn QueryInterface(this: *mut std::ffi::c_void, iid: &GUID, interface: *mut *const std::ffi::c_void) -> HRESULT { + unsafe extern "system" fn QueryInterface(this: *mut std::ffi::c_void, iid: *const GUID, interface: *mut *mut std::ffi::c_void) -> HRESULT { let this = (this as *mut *mut std::ffi::c_void).offset(OFFSET) as *mut T; (*this).QueryInterface(iid, interface) } diff --git a/crates/libs/implement/src/lib.rs b/crates/libs/implement/src/lib.rs index e54e573663..e26f8fc5a2 100644 --- a/crates/libs/implement/src/lib.rs +++ b/crates/libs/implement/src/lib.rs @@ -45,7 +45,7 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: let offset = proc_macro2::Literal::usize_unsuffixed(count); quote! { else if #vtbl_ident::matches(iid) { - &self.vtables.#offset as *const _ as *const _ + &self.vtables.#offset as *const _ as *mut _ } } }); @@ -104,12 +104,12 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro: fn get_impl(&self) -> &Self::Impl { &self.this } - unsafe fn QueryInterface(&self, iid: &::windows::core::GUID, interface: *mut *const ::core::ffi::c_void) -> ::windows::core::HRESULT { + unsafe fn QueryInterface(&self, iid: *const ::windows::core::GUID, interface: *mut *mut ::core::ffi::c_void) -> ::windows::core::HRESULT { unsafe { - *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 *const _ + *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() }; diff --git a/crates/libs/interface/src/lib.rs b/crates/libs/interface/src/lib.rs index 4d1b7f11bf..329740c387 100644 --- a/crates/libs/interface/src/lib.rs +++ b/crates/libs/interface/src/lib.rs @@ -244,8 +244,8 @@ impl Interface { Self { base__: #parent_vtable::new::<#parent_vtable_generics>(), #(#entries),* } } - pub fn matches(iid: &windows::core::GUID) -> bool { - iid == &<#name as ::windows::core::ComInterface>::IID + pub unsafe fn matches(iid: *const windows::core::GUID) -> bool { + *iid == <#name as ::windows::core::ComInterface>::IID } } }