From 266b651b34bab63c1723d43226cd48eea44b18a6 Mon Sep 17 00:00:00 2001 From: Ali Chraghi Date: Tue, 28 Mar 2023 15:11:13 +0330 Subject: [PATCH] all: use explicit backing integers for packed structs --- libs/basisu/src/encoder.zig | 2 +- libs/basisu/src/transcoder.zig | 2 +- libs/core/src/Core.zig | 4 ++-- libs/glfw/src/hat.zig | 12 ++++++------ libs/glfw/src/mod.zig | 4 ++-- libs/gpu/src/buffer.zig | 2 +- libs/gpu/src/texture.zig | 2 +- libs/gpu/src/types.zig | 6 +++--- libs/model3d/src/main.zig | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libs/basisu/src/encoder.zig b/libs/basisu/src/encoder.zig index 428585cd..8550d7f2 100644 --- a/libs/basisu/src/encoder.zig +++ b/libs/basisu/src/encoder.zig @@ -203,7 +203,7 @@ pub const Image = struct { } }; -pub const PackUASTCFlags = packed struct { +pub const PackUASTCFlags = packed struct(u32) { fastest: bool = false, faster: bool = false, default: bool = false, diff --git a/libs/basisu/src/transcoder.zig b/libs/basisu/src/transcoder.zig index dd44804b..08302835 100644 --- a/libs/basisu/src/transcoder.zig +++ b/libs/basisu/src/transcoder.zig @@ -117,7 +117,7 @@ pub const Transcoder = struct { block_count: u32, }; - pub const DecodeFlags = packed struct { + pub const DecodeFlags = packed struct(u32) { _padding: u1 = 0, pvrtc_decode_to_next_pow_2: bool = false, transcode_alpha_data_to_opaque_formats: bool = false, diff --git a/libs/core/src/Core.zig b/libs/core/src/Core.zig index 7bfa7079..943d50f1 100644 --- a/libs/core/src/Core.zig +++ b/libs/core/src/Core.zig @@ -362,14 +362,14 @@ pub const Key = enum { unknown, }; -pub const KeyMods = packed struct { +pub const KeyMods = packed struct(u8) { shift: bool, control: bool, alt: bool, super: bool, caps_lock: bool, num_lock: bool, - _reserved: u2 = 0, + _padding: u2 = 0, }; pub const DisplayMode = enum { diff --git a/libs/glfw/src/hat.zig b/libs/glfw/src/hat.zig index 52101595..270aeb0a 100644 --- a/libs/glfw/src/hat.zig +++ b/libs/glfw/src/hat.zig @@ -4,12 +4,12 @@ const c = @import("c.zig").c; /// A bitmask of all Joystick hat states /// /// See glfw.Joystick.getHats for how these are used. -pub const Hat = packed struct { +pub const Hat = packed struct(u8) { up: bool = false, right: bool = false, down: bool = false, left: bool = false, - _reserved: u4 = 0, + _padding: u4 = 0, pub inline fn centered(self: Hat) bool { return self.up == false and self.right == false and self.down == false and self.left == false; @@ -57,7 +57,7 @@ test "from int, single" { .right = false, .down = false, .left = false, - ._reserved = 0, + ._padding = 0, }, Hat.fromInt(RawHat.up)); } @@ -69,7 +69,7 @@ test "from int, multi" { .right = false, .down = true, .left = true, - ._reserved = 0, + ._padding = 0, }, Hat.fromInt(RawHat.up | RawHat.down | RawHat.left)); } @@ -81,7 +81,7 @@ test "to int, single" { .right = false, .down = false, .left = false, - ._reserved = 0, + ._padding = 0, }; try std.testing.expectEqual(v.toInt(c_int), RawHat.up); } @@ -94,7 +94,7 @@ test "to int, multi" { .right = false, .down = true, .left = true, - ._reserved = 0, + ._padding = 0, }; try std.testing.expectEqual(v.toInt(c_int), RawHat.up | RawHat.down | RawHat.left); } diff --git a/libs/glfw/src/mod.zig b/libs/glfw/src/mod.zig index d1cd45df..4d7711c8 100644 --- a/libs/glfw/src/mod.zig +++ b/libs/glfw/src/mod.zig @@ -6,14 +6,14 @@ const c = @import("c.zig").c; // must be in sync with GLFW C constants in modifier group, search for "@defgroup mods Modifier key flags" /// A bitmask of all key modifiers -pub const Mods = packed struct { +pub const Mods = packed struct(u8) { shift: bool = false, control: bool = false, alt: bool = false, super: bool = false, caps_lock: bool = false, num_lock: bool = false, - _reserved: u2 = 0, + _padding: u2 = 0, inline fn verifyIntType(comptime IntType: type) void { comptime { diff --git a/libs/gpu/src/buffer.zig b/libs/gpu/src/buffer.zig index 0d5539af..f88e395d 100644 --- a/libs/gpu/src/buffer.zig +++ b/libs/gpu/src/buffer.zig @@ -29,7 +29,7 @@ pub const Buffer = opaque { unmapped_before_callback = 0x00000005, }; - pub const UsageFlags = packed struct { + pub const UsageFlags = packed struct(u32) { map_read: bool = false, map_write: bool = false, copy_src: bool = false, diff --git a/libs/gpu/src/texture.zig b/libs/gpu/src/texture.zig index ed5254d0..07574ec3 100644 --- a/libs/gpu/src/texture.zig +++ b/libs/gpu/src/texture.zig @@ -136,7 +136,7 @@ pub const Texture = opaque { uint = 0x00000005, }; - pub const UsageFlags = packed struct { + pub const UsageFlags = packed struct(u32) { copy_src: bool = false, copy_dst: bool = false, texture_binding: bool = false, diff --git a/libs/gpu/src/types.zig b/libs/gpu/src/types.zig index 4f3b258a..c094bdfa 100644 --- a/libs/gpu/src/types.zig +++ b/libs/gpu/src/types.zig @@ -410,7 +410,7 @@ pub const VertexStepMode = enum(u32) { vertex_buffer_not_used = 0x00000002, }; -pub const ColorWriteMaskFlags = packed struct { +pub const ColorWriteMaskFlags = packed struct(u32) { red: bool = false, green: bool = false, blue: bool = false, @@ -437,7 +437,7 @@ pub const ColorWriteMaskFlags = packed struct { } }; -pub const MapModeFlags = packed struct { +pub const MapModeFlags = packed struct(u32) { read: bool = false, write: bool = false, @@ -457,7 +457,7 @@ pub const MapModeFlags = packed struct { } }; -pub const ShaderStageFlags = packed struct { +pub const ShaderStageFlags = packed struct(u32) { vertex: bool = false, fragment: bool = false, compute: bool = false, diff --git a/libs/model3d/src/main.zig b/libs/model3d/src/main.zig index 2b98a789..142063cc 100644 --- a/libs/model3d/src/main.zig +++ b/libs/model3d/src/main.zig @@ -154,7 +154,7 @@ pub const Quality = enum(u2) { double = c.M3D_EXP_DOUBLE, }; -pub const Flags = packed struct { +pub const Flags = packed struct(u32) { // don't export color map nocmap: bool = false, // don't export materials