mirror of
https://github.com/zoriya/zig-wayland.git
synced 2026-05-28 17:03:59 +00:00
Enforce alignment of Array.slice() at compile time
This commit is contained in:
+2
-2
@@ -32,10 +32,10 @@ pub const Array = extern struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn slice(array: Array, comptime T: type) []T {
|
||||
pub fn slice(array: Array, comptime T: type) []align(4) T {
|
||||
const data = array.data orelse return &[0]T{};
|
||||
// The wire protocol/libwayland only guarantee 32-bit word alignment.
|
||||
const ptr: [*]T = @ptrCast(@alignCast(data));
|
||||
const ptr: [*]align(4) T = @ptrCast(@alignCast(data));
|
||||
return ptr[0..@divExact(array.size, @sizeOf(T))];
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user