commit 8bb2e96ac3b61a8aa393f250144fb9e1195ca60a (tree)
parent e4e1c21e1fa599c1f243cad9236c88676023f6a8
Author: Ryan Liptak <squeek502@hotmail.com>
Date: Thu, 13 Oct 2022 21:11:58 -0700
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.
Diffstat:
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
@@ -2868,10 +2868,7 @@ pub const PROV_RSA_FULL = 1;
pub const REGSAM = ACCESS_MASK;
pub const ACCESS_MASK = DWORD;
-pub const HKEY = *HKEY__;
-pub const HKEY__ = extern struct {
- unused: c_int,
-};
+pub const HKEY = *opaque {};
pub const LSTATUS = LONG;
pub const FILE_NOTIFY_INFORMATION = extern struct {