authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-10-13 21:11:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-14 15:23:13-04:00
log8bb2e96ac3b61a8aa393f250144fb9e1195ca60a
treecf37940f5d9711cbacb6ae2d6618e9c62b1b05bb
parente4e1c21e1fa599c1f243cad9236c88676023f6a8

std.os.windows: Change HKEY to *opaque {}

The definition of HKEY__ as a struct with an unused int field is only the case in the Windows headers when `STRICT` is defined. From https://learn.microsoft.com/en-us/windows/win32/winprog/enabling-strict: > When STRICT is defined, data type definitions change as follows: > > - Specific handle types are defined to be mutually exclusive; for example, you will not be able to pass an HWND where an HDC type argument is required. Without STRICT, all handles are defined as HANDLE, so the compiler does not prevent you from using one type of handle where another type is expected. Zig's `opaque {}` already gives this benefit to us, so the usage of a struct with an unused field is unnecessary, and it was causing HKEY to have an alignment of 4, which is a problem because there are HKEY constants like HKEY_LOCAL_MACHINE (0x80000002) that are not 4-byte aligned. Without this change, the compiler would not allow something like HKEY_LOCAL_MACHINE to be defined since it enforces pointer alignment.

1 files changed, 1 insertions(+), 4 deletions(-)

lib/std/os/windows.zig+1-4
......@@ -2868,10 +2868,7 @@ pub const PROV_RSA_FULL = 1;
28682868
28692869pub const REGSAM = ACCESS_MASK;
28702870pub const ACCESS_MASK = DWORD;
2871pub const HKEY = *HKEY__;
2872pub const HKEY__ = extern struct {
2873 unused: c_int,
2874};
2871pub const HKEY = *opaque {};
28752872pub const LSTATUS = LONG;
28762873
28772874pub const FILE_NOTIFY_INFORMATION = extern struct {