From 40d74e428759d473b1704878814bd4a25bb0245c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 9 Jul 2025 23:07:18 -0700 Subject: [PATCH] std: refactor to use Alignment.of --- lib/std/heap.zig | 2 +- lib/std/heap/arena_allocator.zig | 2 +- lib/std/mem/Allocator.zig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/heap.zig b/lib/std/heap.zig index 2f5332be9f..51e4fe44a2 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -287,7 +287,7 @@ fn rawCAlloc( ) ?[*]u8 { _ = context; _ = return_address; - assert(alignment.compare(.lte, comptime .fromByteUnits(@alignOf(std.c.max_align_t)))); + assert(alignment.compare(.lte, .of(std.c.max_align_t))); // Note that this pointer cannot be aligncasted to max_align_t because if // len is < max_align_t then the alignment can be smaller. For example, if // max_align_t is 16, but the user requests 8 bytes, there is no built-in diff --git a/lib/std/heap/arena_allocator.zig b/lib/std/heap/arena_allocator.zig index e3a76a06c1..130eae66f8 100644 --- a/lib/std/heap/arena_allocator.zig +++ b/lib/std/heap/arena_allocator.zig @@ -42,7 +42,7 @@ pub const ArenaAllocator = struct { data: usize, node: std.SinglyLinkedList.Node = .{}, }; - const BufNode_alignment: Alignment = .fromByteUnits(@alignOf(BufNode)); + const BufNode_alignment: Alignment = .of(BufNode); pub fn init(child_allocator: Allocator) ArenaAllocator { return (State{}).promote(child_allocator); diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index dc3e3f0325..b81a916702 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -253,7 +253,7 @@ pub inline fn allocAdvancedWithRetAddr( n: usize, return_address: usize, ) Error![]align(if (alignment) |a| a.toByteUnits() else @alignOf(T)) T { - const a = comptime (alignment orelse Alignment.fromByteUnits(@alignOf(T))); + const a = comptime (alignment orelse Alignment.of(T)); const ptr: [*]align(a.toByteUnits()) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address)); return ptr[0..n]; }