Skip to content

Commit

Permalink
We can now derive Eq and PartialEq for structs containing callbac…
Browse files Browse the repository at this point in the history
…ks (#3270)
  • Loading branch information
kennykerr authored Sep 12, 2024
1 parent 1b46399 commit cc08c6c
Show file tree
Hide file tree
Showing 80 changed files with 443 additions and 484 deletions.
40 changes: 0 additions & 40 deletions crates/libs/bindgen/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,46 +495,6 @@ fn type_def_is_callback(row: TypeDef) -> bool {
!row.flags().contains(TypeAttributes::WindowsRuntime) && row.kind() == TypeKind::Delegate
}

pub fn type_has_callback(ty: &Type) -> bool {
match ty {
Type::TypeDef(row, _) => type_def_has_callback(*row),
Type::Win32Array(ty, _) => type_has_callback(ty),
_ => false,
}
}

pub fn type_def_has_callback(row: TypeDef) -> bool {
if type_def_is_callback(row) {
return true;
}
if row.kind() != TypeKind::Struct {
return false;
}
fn check(row: TypeDef) -> bool {
if row
.fields()
.any(|field| type_has_callback(&field.ty(Some(row))))
{
return true;
}
false
}
let type_name = row.type_name();
if type_name.namespace().is_empty() {
check(row)
} else {
for row in row
.reader()
.get_type_def(type_name.namespace(), type_name.name())
{
if check(row) {
return true;
}
}
false
}
}

pub fn type_def_has_float(def: TypeDef) -> bool {
def.kind() == TypeKind::Struct
&& def
Expand Down
1 change: 0 additions & 1 deletion crates/libs/bindgen/src/rust/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ fn gen_derive(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
if !writer.sys
&& !metadata::type_def_has_explicit_layout(def)
&& !metadata::type_def_has_packing(def)
&& !metadata::type_def_has_callback(def)
{
derive.insert(to_ident("PartialEq"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Default for HID_XFER_PACKET {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct VHF_CONFIG {
pub Size: u32,
pub VhfClientContext: *mut core::ffi::c_void,
Expand Down
8 changes: 4 additions & 4 deletions crates/libs/windows/src/Windows/Wdk/Foundation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ impl windows_core::TypeKind for DMA_COMMON_BUFFER_VECTOR {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Storage_FileSystem", feature = "Wdk_System_SystemServices", feature = "Win32_Security", feature = "Win32_System_IO", feature = "Win32_System_Kernel", feature = "Win32_System_Power"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DRIVER_EXTENSION {
pub DriverObject: *mut DRIVER_OBJECT,
pub AddDevice: DRIVER_ADD_DEVICE,
Expand All @@ -655,7 +655,7 @@ impl Default for DRIVER_EXTENSION {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Storage_FileSystem", feature = "Wdk_System_SystemServices", feature = "Win32_Security", feature = "Win32_System_IO", feature = "Win32_System_Kernel", feature = "Win32_System_Power"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DRIVER_OBJECT {
pub Type: i16,
pub Size: i16,
Expand Down Expand Up @@ -786,7 +786,7 @@ impl Default for ERESOURCE_1 {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Storage_FileSystem", feature = "Wdk_System_SystemServices", feature = "Win32_Security", feature = "Win32_System_IO", feature = "Win32_System_Kernel", feature = "Win32_System_Power"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FAST_IO_DISPATCH {
pub SizeOfFastIoDispatch: u32,
pub FastIoCheckIfPossible: FAST_IO_CHECK_IF_POSSIBLE,
Expand Down Expand Up @@ -2844,7 +2844,7 @@ impl Default for VPB {
}
#[repr(C)]
#[cfg(feature = "Win32_System_Kernel")]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct WORK_QUEUE_ITEM {
pub List: super::super::Win32::System::Kernel::LIST_ENTRY,
pub WorkerRoutine: PWORKER_THREAD_ROUTINE,
Expand Down
22 changes: 11 additions & 11 deletions crates/libs/windows/src/Windows/Wdk/Graphics/Direct3D/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6297,7 +6297,7 @@ impl Default for D3DGPU_PHYSICAL_ADDRESS {
}
#[repr(C)]
#[cfg(all(feature = "Win32_Graphics_Direct3D9", feature = "Win32_Graphics_DirectDraw", feature = "Win32_Graphics_Gdi"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DHAL_CALLBACKS {
pub dwSize: u32,
pub ContextCreate: LPD3DHAL_CONTEXTCREATECB,
Expand Down Expand Up @@ -6347,7 +6347,7 @@ impl Default for D3DHAL_CALLBACKS {
}
#[repr(C)]
#[cfg(all(feature = "Win32_Graphics_Direct3D9", feature = "Win32_Graphics_DirectDraw", feature = "Win32_Graphics_Gdi"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DHAL_CALLBACKS2 {
pub dwSize: u32,
pub dwFlags: u32,
Expand All @@ -6369,7 +6369,7 @@ impl Default for D3DHAL_CALLBACKS2 {
}
#[repr(C)]
#[cfg(all(feature = "Win32_Graphics_Direct3D9", feature = "Win32_Graphics_DirectDraw", feature = "Win32_Graphics_Gdi"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DHAL_CALLBACKS3 {
pub dwSize: u32,
pub dwFlags: u32,
Expand Down Expand Up @@ -14951,7 +14951,7 @@ impl Default for D3DKMT_RECLAIMALLOCATIONS2_0 {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DKMT_REGISTERBUDGETCHANGENOTIFICATION {
pub hDevice: u32,
pub Callback: PFND3DKMT_BUDGETCHANGENOTIFICATIONCALLBACK,
Expand All @@ -14967,7 +14967,7 @@ impl Default for D3DKMT_REGISTERBUDGETCHANGENOTIFICATION {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DKMT_REGISTERTRIMNOTIFICATION {
pub AdapterLuid: super::super::super::Win32::Foundation::LUID,
pub hDevice: u32,
Expand Down Expand Up @@ -16032,7 +16032,7 @@ impl Default for D3DKMT_UNREGISTERBUDGETCHANGENOTIFICATION {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DKMT_UNREGISTERTRIMNOTIFICATION {
pub Handle: *mut core::ffi::c_void,
pub Callback: PFND3DKMT_TRIMNOTIFICATIONCALLBACK,
Expand Down Expand Up @@ -17216,7 +17216,7 @@ impl Default for D3DNTHALDEVICEDESC_V2 {
}
#[repr(C)]
#[cfg(feature = "Win32_Graphics_DirectDraw")]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DNTHAL_CALLBACKS {
pub dwSize: u32,
pub ContextCreate: LPD3DNTHAL_CONTEXTCREATECB,
Expand Down Expand Up @@ -17266,7 +17266,7 @@ impl Default for D3DNTHAL_CALLBACKS {
}
#[repr(C)]
#[cfg(feature = "Win32_Graphics_DirectDraw")]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DNTHAL_CALLBACKS2 {
pub dwSize: u32,
pub dwFlags: u32,
Expand All @@ -17288,7 +17288,7 @@ impl Default for D3DNTHAL_CALLBACKS2 {
}
#[repr(C)]
#[cfg(all(feature = "Win32_Graphics_Direct3D9", feature = "Win32_Graphics_DirectDraw"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct D3DNTHAL_CALLBACKS3 {
pub dwSize: u32,
pub dwFlags: u32,
Expand Down Expand Up @@ -20203,7 +20203,7 @@ impl Default for DXGK_GPUVERSION {
}
#[repr(C)]
#[cfg(feature = "Win32_System_Power")]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DXGK_GRAPHICSPOWER_REGISTER_INPUT_V_1_2 {
pub Version: u32,
pub PrivateHandle: *mut core::ffi::c_void,
Expand All @@ -20224,7 +20224,7 @@ impl Default for DXGK_GRAPHICSPOWER_REGISTER_INPUT_V_1_2 {
}
#[repr(C)]
#[cfg(feature = "Win32_System_Power")]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DXGK_GRAPHICSPOWER_REGISTER_OUTPUT {
pub DeviceHandle: *mut core::ffi::c_void,
pub InitialGrfxPowerState: super::super::super::Win32::System::Power::DEVICE_POWER_STATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5865,7 +5865,7 @@ impl Default for NDIS_WMI_TCP_LARGE_SEND_OFFLOAD_V2_1 {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct NDIS_WORK_ITEM {
pub Context: *mut core::ffi::c_void,
pub Routine: NDIS_PROC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,7 @@ impl Default for FLT_CALLBACK_DATA_0_0 {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Foundation", feature = "Wdk_System_SystemServices", feature = "Win32_Security", feature = "Win32_System_IO", feature = "Win32_System_Kernel", feature = "Win32_System_Power"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FLT_CALLBACK_DATA_QUEUE {
pub Csq: super::super::super::System::SystemServices::IO_CSQ,
pub Flags: FLT_CALLBACK_DATA_QUEUE_FLAGS,
Expand All @@ -2252,7 +2252,7 @@ impl Default for FLT_CALLBACK_DATA_QUEUE {
}
#[repr(C)]
#[cfg(feature = "Wdk_Foundation")]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FLT_CONTEXT_REGISTRATION {
pub ContextType: u16,
pub Flags: u16,
Expand Down Expand Up @@ -2349,7 +2349,7 @@ impl Default for FLT_NAME_CONTROL {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Foundation", feature = "Wdk_System_SystemServices", feature = "Win32_Security", feature = "Win32_System_IO", feature = "Win32_System_Kernel", feature = "Win32_System_Power"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FLT_OPERATION_REGISTRATION {
pub MajorFunction: u8,
pub Flags: u32,
Expand Down Expand Up @@ -3510,7 +3510,7 @@ impl Default for FLT_PARAMETERS_32 {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Foundation", feature = "Wdk_System_SystemServices", feature = "Win32_Security", feature = "Win32_Storage_InstallableFileSystems", feature = "Win32_System_IO", feature = "Win32_System_Kernel", feature = "Win32_System_Power"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FLT_REGISTRATION {
pub Size: u16,
pub Version: u16,
Expand Down
20 changes: 10 additions & 10 deletions crates/libs/windows/src/Windows/Wdk/Storage/FileSystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6254,7 +6254,7 @@ impl Default for BOOT_AREA_INFO_0 {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CACHE_MANAGER_CALLBACKS {
pub AcquireForLazyWrite: PACQUIRE_FOR_LAZY_WRITE,
pub ReleaseFromLazyWrite: PRELEASE_FROM_LAZY_WRITE,
Expand All @@ -6270,7 +6270,7 @@ impl Default for CACHE_MANAGER_CALLBACKS {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CACHE_MANAGER_CALLBACKS_EX {
pub Version: u16,
pub Size: u16,
Expand All @@ -6285,7 +6285,7 @@ impl Default for CACHE_MANAGER_CALLBACKS_EX {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CACHE_MANAGER_CALLBACK_FUNCTIONS {
pub AcquireForLazyWriteEx: PACQUIRE_FOR_LAZY_WRITE_EX,
pub ReleaseFromLazyWrite: PRELEASE_FROM_LAZY_WRITE,
Expand Down Expand Up @@ -6319,7 +6319,7 @@ impl Default for CACHE_UNINITIALIZE_EVENT {
}
#[repr(C)]
#[cfg(feature = "Wdk_Foundation")]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CC_ASYNC_READ_CONTEXT {
pub CompletionRoutine: PASYNC_READ_COMPLETION_CALLBACK,
pub Context: *mut core::ffi::c_void,
Expand Down Expand Up @@ -7332,7 +7332,7 @@ impl Default for FILE_LINK_INFORMATION_0 {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Foundation", feature = "Wdk_System_SystemServices", feature = "Win32_Security", feature = "Win32_System_IO", feature = "Win32_System_Kernel", feature = "Win32_System_Power"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FILE_LOCK {
pub CompleteLockIrpRoutine: PCOMPLETE_LOCK_IRP_ROUTINE,
pub UnlockRoutine: PUNLOCK_ROUTINE,
Expand Down Expand Up @@ -8295,7 +8295,7 @@ impl Default for FSRTL_PER_FILEOBJECT_CONTEXT {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Foundation", feature = "Win32_System_Kernel"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FSRTL_PER_FILE_CONTEXT {
pub Links: super::super::super::Win32::System::Kernel::LIST_ENTRY,
pub OwnerId: *mut core::ffi::c_void,
Expand All @@ -8314,7 +8314,7 @@ impl Default for FSRTL_PER_FILE_CONTEXT {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Foundation", feature = "Win32_System_Kernel"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FSRTL_PER_STREAM_CONTEXT {
pub Links: super::super::super::Win32::System::Kernel::LIST_ENTRY,
pub OwnerId: *mut core::ffi::c_void,
Expand Down Expand Up @@ -8437,7 +8437,7 @@ impl Default for FS_BPIO_INPUT {
}
#[repr(C)]
#[cfg(all(feature = "Wdk_Foundation", feature = "Wdk_System_SystemServices", feature = "Win32_Security", feature = "Win32_System_IO", feature = "Win32_System_Kernel", feature = "Win32_System_Power"))]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FS_FILTER_CALLBACKS {
pub SizeOfFsFilterCallbacks: u32,
pub Reserved: u32,
Expand Down Expand Up @@ -10208,7 +10208,7 @@ impl Default for RTL_HEAP_MEMORY_LIMIT_INFO {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RTL_HEAP_PARAMETERS {
pub Length: u32,
pub SegmentReserve: usize,
Expand Down Expand Up @@ -10300,7 +10300,7 @@ impl Default for RTL_SEGMENT_HEAP_PARAMETERS {
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RTL_SEGMENT_HEAP_VA_CALLBACKS {
pub CallbackContext: super::super::super::Win32::Foundation::HANDLE,
pub AllocateVirtualMemory: PALLOCATE_VIRTUAL_MEMORY_EX_CALLBACK,
Expand Down
Loading

0 comments on commit cc08c6c

Please sign in to comment.