Skip to content

Commit

Permalink
Fix regression with empty structs (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jan 28, 2021
1 parent ecc77d3 commit e28897d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/gen/src/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Struct {
let guid = TypeGuid::from_type_def(&name.def);

// The C/C++ ABI assumes an empty struct occupies a single byte in memory.
if fields.is_empty() && guid != TypeGuid::default() {
if fields.is_empty() && guid == TypeGuid::default() {
let t = Type {
kind: TypeKind::U8,
pointers: 0,
Expand Down
2 changes: 2 additions & 0 deletions crates/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ fn main() {
windows::win32::com::{IUri, CreateUri},
windows::win32::structured_storage::{CreateStreamOnHGlobal, STREAM_SEEK},
windows::win32::upnp::UIAnimationTransitionLibrary,
windows::win32::ldap::ldapsearch,
windows::win32::upnp::UIAnimationManager,
);
}
12 changes: 12 additions & 0 deletions crates/tests/tests/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ use tests::{
CreateDXGIFactory1, IDXGIFactory7, DXGI_ADAPTER_FLAG, DXGI_FORMAT, DXGI_MODE_DESC,
DXGI_MODE_SCALING, DXGI_MODE_SCANLINE_ORDER, DXGI_RATIONAL,
},
windows::win32::ldap::ldapsearch,
windows::win32::security::ACCESS_MODE,
windows::win32::structured_storage::{CreateStreamOnHGlobal, STREAM_SEEK},
windows::win32::system_services::{
CreateEventW, SetEvent, WaitForSingleObject, DXGI_ERROR_INVALID_CALL, HANDLE, WM_KEYUP,
},
windows::win32::upnp::UIAnimationManager,
windows::win32::upnp::UIAnimationTransitionLibrary,
windows::win32::windows_accessibility::UIA_ScrollPatternNoScroll,
windows::win32::windows_and_messaging::{CHOOSECOLORW, HWND, PROPENUMPROCA, PROPENUMPROCW},
windows::win32::windows_programming::CloseHandle,
};
use windows::Guid;
use windows::Interface;
use windows::BOOL;

Expand Down Expand Up @@ -330,3 +333,12 @@ extern "system" fn callback_w(param0: HWND, param1: *const u16, param2: HANDLE)
BOOL(789)
}
}

#[test]
fn empty_struct() {
let ldap = ldapsearch { reserved: 123 };
assert!(ldap.reserved == 123);
assert!(std::mem::size_of::<ldapsearch>() == 1);

assert!(UIAnimationManager == Guid::from("4C1FC63A-695C-47E8-A339-1A194BE3D0B8"));
}

0 comments on commit e28897d

Please sign in to comment.