Skip to content

Commit

Permalink
Consolidate internal interface and com_interface macros (#2914)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Mar 6, 2024
1 parent f6edc73 commit 70b2dd0
Show file tree
Hide file tree
Showing 506 changed files with 12,603 additions and 12,605 deletions.
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/delegates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn gen_win_delegate(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
let iid = writer.guid_literal(metadata::type_def_guid(def));
quote! {
#features
windows_core::imp::com_interface!(#ident, #vtbl, #iid);
windows_core::imp::define_interface!(#ident, #vtbl, #iid);
}
} else {
quote! {
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/rust/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn gen_win_interface(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
let iid = writer.guid_literal(metadata::type_def_guid(def));
tokens.combine(&quote! {
#features
windows_core::imp::com_interface!(#ident, #vtbl_ident, #iid);
windows_core::imp::define_interface!(#ident, #vtbl_ident, #iid);
});
} else {
tokens.combine(&quote! {
Expand All @@ -64,7 +64,7 @@ fn gen_win_interface(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
} else {
tokens.combine(&quote! {
#features
windows_core::imp::interface!(#ident, #vtbl_ident);
windows_core::imp::define_interface!(#ident, #vtbl_ident);
});
}

Expand Down
14 changes: 7 additions & 7 deletions crates/libs/core/src/imp/com_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ impl Default for DateTime {
pub const E_BOUNDS: windows_core::HRESULT = windows_core::HRESULT(0x8000000B_u32 as _);
pub const E_NOINTERFACE: windows_core::HRESULT = windows_core::HRESULT(0x80004002_u32 as _);
pub const E_OUTOFMEMORY: windows_core::HRESULT = windows_core::HRESULT(0x8007000E_u32 as _);
windows_core::imp::com_interface!(IAgileObject, IAgileObject_Vtbl, 0x94ea2b94_e9cc_49e0_c0ff_ee64ca8f5b90);
windows_core::imp::define_interface!(IAgileObject, IAgileObject_Vtbl, 0x94ea2b94_e9cc_49e0_c0ff_ee64ca8f5b90);
windows_core::imp::interface_hierarchy!(IAgileObject, windows_core::IUnknown);
impl IAgileObject {}
#[repr(C)]
pub struct IAgileObject_Vtbl {
pub base__: windows_core::IUnknown_Vtbl,
}
windows_core::imp::com_interface!(IAgileReference, IAgileReference_Vtbl, 0xc03f6a43_65a4_9818_987e_e0b810d2a6f2);
windows_core::imp::define_interface!(IAgileReference, IAgileReference_Vtbl, 0xc03f6a43_65a4_9818_987e_e0b810d2a6f2);
windows_core::imp::interface_hierarchy!(IAgileReference, windows_core::IUnknown);
impl IAgileReference {
pub unsafe fn Resolve<T>(&self) -> windows_core::Result<T>
Expand All @@ -85,7 +85,7 @@ pub struct IAgileReference_Vtbl {
pub base__: windows_core::IUnknown_Vtbl,
pub Resolve: unsafe extern "system" fn(*mut core::ffi::c_void, *const windows_core::GUID, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
}
windows_core::imp::com_interface!(IPropertyValue, IPropertyValue_Vtbl, 0x4bd682dd_7554_40e9_9a9b_82654ede7e62);
windows_core::imp::define_interface!(IPropertyValue, IPropertyValue_Vtbl, 0x4bd682dd_7554_40e9_9a9b_82654ede7e62);
windows_core::imp::interface_hierarchy!(IPropertyValue, windows_core::IUnknown, windows_core::IInspectable);
impl IPropertyValue {
pub fn Type(&self) -> windows_core::Result<PropertyType> {
Expand Down Expand Up @@ -351,7 +351,7 @@ pub struct IPropertyValue_Vtbl {
pub GetSizeArray: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32, *mut *mut Size) -> windows_core::HRESULT,
pub GetRectArray: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32, *mut *mut Rect) -> windows_core::HRESULT,
}
windows_core::imp::com_interface!(IPropertyValueStatics, IPropertyValueStatics_Vtbl, 0x629bdbc8_d932_4ff4_96b9_8d96c5c1e858);
windows_core::imp::define_interface!(IPropertyValueStatics, IPropertyValueStatics_Vtbl, 0x629bdbc8_d932_4ff4_96b9_8d96c5c1e858);
#[repr(C)]
pub struct IPropertyValueStatics_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
Expand Down Expand Up @@ -646,7 +646,7 @@ where
pub Value: unsafe extern "system" fn(*mut core::ffi::c_void, *mut windows_core::AbiType<T>) -> windows_core::HRESULT,
pub T: core::marker::PhantomData<T>,
}
windows_core::imp::com_interface!(IStringable, IStringable_Vtbl, 0x96369f54_8eb6_48f0_abce_c1b211e627c3);
windows_core::imp::define_interface!(IStringable, IStringable_Vtbl, 0x96369f54_8eb6_48f0_abce_c1b211e627c3);
windows_core::imp::interface_hierarchy!(IStringable, windows_core::IUnknown, windows_core::IInspectable);
impl IStringable {
pub fn ToString(&self) -> windows_core::Result<windows_core::HSTRING> {
Expand All @@ -665,7 +665,7 @@ pub struct IStringable_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub ToString: unsafe extern "system" fn(*mut core::ffi::c_void, *mut std::mem::MaybeUninit<windows_core::HSTRING>) -> windows_core::HRESULT,
}
windows_core::imp::com_interface!(IWeakReference, IWeakReference_Vtbl, 0x00000037_0000_0000_c000_000000000046);
windows_core::imp::define_interface!(IWeakReference, IWeakReference_Vtbl, 0x00000037_0000_0000_c000_000000000046);
windows_core::imp::interface_hierarchy!(IWeakReference, windows_core::IUnknown);
impl IWeakReference {
pub unsafe fn Resolve<T>(&self) -> windows_core::Result<T>
Expand All @@ -681,7 +681,7 @@ pub struct IWeakReference_Vtbl {
pub base__: windows_core::IUnknown_Vtbl,
pub Resolve: unsafe extern "system" fn(*mut core::ffi::c_void, *const windows_core::GUID, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
}
windows_core::imp::com_interface!(IWeakReferenceSource, IWeakReferenceSource_Vtbl, 0x00000038_0000_0000_c000_000000000046);
windows_core::imp::define_interface!(IWeakReferenceSource, IWeakReferenceSource_Vtbl, 0x00000038_0000_0000_c000_000000000046);
windows_core::imp::interface_hierarchy!(IWeakReferenceSource, windows_core::IUnknown);
impl IWeakReferenceSource {
pub unsafe fn GetWeakReference(&self) -> windows_core::Result<IWeakReference> {
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/core/src/imp/generic_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::Interface;

// A streamlined version of the IActivationFactory interface used by WinRT class factories used internally by the windows crate
// to simplify code generation. Components should implement the `IActivationFactory` interface published by the windows crate.
super::com_interface!(IGenericFactory, IGenericFactory_Vtbl, 0x00000035_0000_0000_c000_000000000046);
super::define_interface!(IGenericFactory, IGenericFactory_Vtbl, 0x00000035_0000_0000_c000_000000000046);
super::interface_hierarchy!(IGenericFactory, crate::IUnknown, crate::IInspectable);

impl IGenericFactory {
Expand Down
28 changes: 9 additions & 19 deletions crates/libs/core/src/imp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,27 @@ pub use required_hierarchy;

#[doc(hidden)]
#[macro_export]
macro_rules! interface {
($(#[$doc:meta])? $name:ident, $vtbl:ident) => {
$(#[$doc])?
macro_rules! define_interface {
($name:ident, $vtbl:ident, $iid:literal) => {
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::fmt::Debug, ::core::clone::Clone)]
pub struct $name(::std::ptr::NonNull<::std::ffi::c_void>);
pub struct $name(::windows_core::IUnknown);
unsafe impl ::windows_core::Interface for $name {
type Vtable = $vtbl;
const IID: ::windows_core::GUID = ::windows_core::GUID::zeroed();
const UNKNOWN: bool = false;
const IID: ::windows_core::GUID = ::windows_core::GUID::from_u128($iid);
}
};
}

#[doc(hidden)]
pub use interface;

#[doc(hidden)]
#[macro_export]
macro_rules! com_interface {
($(#[$doc:meta])? $name:ident, $vtbl:ident, $iid:literal) => {
$(#[$doc])?
($name:ident, $vtbl:ident) => {
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::fmt::Debug, ::core::clone::Clone)]
pub struct $name(::windows_core::IUnknown);
pub struct $name(::std::ptr::NonNull<::std::ffi::c_void>);
unsafe impl ::windows_core::Interface for $name {
type Vtable = $vtbl;
const IID: ::windows_core::GUID = ::windows_core::GUID::from_u128($iid);
const IID: ::windows_core::GUID = ::windows_core::GUID::zeroed();
const UNKNOWN: bool = false;
}
};
}

#[doc(hidden)]
pub use com_interface;
pub use define_interface;
Loading

0 comments on commit 70b2dd0

Please sign in to comment.