Skip to content

Commit

Permalink
Unhide query method on ComInterface trait (#2659)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Sep 15, 2023
1 parent 0502c95 commit bb64389
Show file tree
Hide file tree
Showing 317 changed files with 14,692 additions and 14,693 deletions.
8 changes: 4 additions & 4 deletions crates/libs/bindgen/src/rust/delegates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
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 @@ -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, &[]))
Expand All @@ -39,7 +39,7 @@ pub fn writer(writer: &Writer, def: 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 @@ -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
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/libs/core/src/com_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<IUnknown>().QueryInterface)(self.as_raw(), iid, interface)
}
}
16 changes: 8 additions & 8 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: &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();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/core/src/unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct IUnknown(std::ptr::NonNull<std::ffi::c_void>);
#[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,
}
Expand Down Expand Up @@ -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
Expand All @@ -86,7 +86,7 @@ pub trait IUnknownImpl {
#[cfg(feature = "implement")]
impl IUnknown_Vtbl {
pub const fn new<T: IUnknownImpl, const OFFSET: isize>() -> Self {
unsafe extern "system" fn QueryInterface<T: IUnknownImpl, const OFFSET: isize>(this: *mut std::ffi::c_void, iid: &GUID, interface: *mut *const std::ffi::c_void) -> HRESULT {
unsafe extern "system" fn QueryInterface<T: IUnknownImpl, const OFFSET: isize>(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)
}
Expand Down
12 changes: 6 additions & 6 deletions crates/libs/implement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
}
}
});
Expand Down Expand Up @@ -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()
};
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 @@ -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
}
}
}
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 @@ -64,8 +64,8 @@ impl ILearningModelFeatureDescriptor_Vtbl {
IsRequired: IsRequired::<Identity, Impl, OFFSET>,
}
}
pub fn matches(iid: &::windows_core::GUID) -> bool {
iid == &<ILearningModelFeatureDescriptor as ::windows_core::ComInterface>::IID
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
*iid == <ILearningModelFeatureDescriptor as ::windows_core::ComInterface>::IID
}
}
#[doc = "*Required features: `\"AI_MachineLearning\"`, `\"implement\"`*"]
Expand All @@ -90,8 +90,8 @@ impl ILearningModelFeatureValue_Vtbl {
}
Self { base__: ::windows_core::IInspectable_Vtbl::new::<Identity, ILearningModelFeatureValue, OFFSET>(), Kind: Kind::<Identity, Impl, OFFSET> }
}
pub fn matches(iid: &::windows_core::GUID) -> bool {
iid == &<ILearningModelFeatureValue as ::windows_core::ComInterface>::IID
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
*iid == <ILearningModelFeatureValue as ::windows_core::ComInterface>::IID
}
}
#[doc = "*Required features: `\"AI_MachineLearning\"`, `\"implement\"`*"]
Expand All @@ -103,8 +103,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 fn matches(iid: &::windows_core::GUID) -> bool {
iid == &<ILearningModelOperatorProvider as ::windows_core::ComInterface>::IID
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
*iid == <ILearningModelOperatorProvider as ::windows_core::ComInterface>::IID
}
}
#[doc = "*Required features: `\"AI_MachineLearning\"`, `\"Foundation_Collections\"`, `\"implement\"`*"]
Expand Down Expand Up @@ -149,7 +149,7 @@ impl ITensor_Vtbl {
Shape: Shape::<Identity, Impl, OFFSET>,
}
}
pub fn matches(iid: &::windows_core::GUID) -> bool {
iid == &<ITensor as ::windows_core::ComInterface>::IID
pub unsafe fn matches(iid: *const ::windows_core::GUID) -> bool {
*iid == <ITensor as ::windows_core::ComInterface>::IID
}
}
Loading

0 comments on commit bb64389

Please sign in to comment.