| author | |
| committer | |
| log | f32a5d349d2c359a2a1f627aa70e1a7a6f6330ea |
| tree | 05a0fe7de04e6aa91775e954f78dd1a478d7e675 |
| parent | ec2888858102035f296c01df5aacbd255c35d06f |
32 files changed, 153 insertions(+), 156 deletions(-)
lib/compiler/aro/aro/Parser.zig+2-2| ... | ... | @@ -101,7 +101,7 @@ value_map: Tree.ValueMap, |
| 101 | 101 | |
| 102 | 102 | // buffers used during compilation |
| 103 | 103 | syms: SymbolStack = .{}, |
| 104 | strings: std.ArrayListAligned(u8, 4), | |
| 104 | strings: std.ArrayListAligned(u8, .@"4"), | |
| 105 | 105 | labels: std.ArrayList(Label), |
| 106 | 106 | list_buf: NodeList, |
| 107 | 107 | decl_buf: NodeList, |
| ... | ... | @@ -693,7 +693,7 @@ pub fn parse(pp: *Preprocessor) Compilation.Error!Tree { |
| 693 | 693 | .gpa = pp.comp.gpa, |
| 694 | 694 | .arena = arena.allocator(), |
| 695 | 695 | .tok_ids = pp.tokens.items(.id), |
| 696 | .strings = std.ArrayListAligned(u8, 4).init(pp.comp.gpa), | |
| 696 | .strings = std.ArrayListAligned(u8, .@"4").init(pp.comp.gpa), | |
| 697 | 697 | .value_map = Tree.ValueMap.init(pp.comp.gpa), |
| 698 | 698 | .data = NodeList.init(pp.comp.gpa), |
| 699 | 699 | .labels = std.ArrayList(Label).init(pp.comp.gpa), |
lib/compiler/aro/aro/Preprocessor.zig+1-1| ... | ... | @@ -983,7 +983,7 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool { |
| 983 | 983 | .tok_i = @intCast(token_state.tokens_len), |
| 984 | 984 | .arena = pp.arena.allocator(), |
| 985 | 985 | .in_macro = true, |
| 986 | .strings = std.ArrayListAligned(u8, 4).init(pp.comp.gpa), | |
| 986 | .strings = std.ArrayListAligned(u8, .@"4").init(pp.comp.gpa), | |
| 987 | 987 | |
| 988 | 988 | .data = undefined, |
| 989 | 989 | .value_map = undefined, |
lib/compiler/objcopy.zig+5-5| ... | ... | @@ -841,12 +841,12 @@ fn ElfFile(comptime is_64: bool) type { |
| 841 | 841 | arena: std.heap.ArenaAllocator, |
| 842 | 842 | |
| 843 | 843 | const SectionCategory = ElfFileHelper.SectionCategory; |
| 844 | const section_memory_align = @alignOf(Elf_Sym); // most restrictive of what we may load in memory | |
| 844 | const section_memory_align: std.mem.Alignment = .of(Elf_Sym); // most restrictive of what we may load in memory | |
| 845 | 845 | const Section = struct { |
| 846 | 846 | section: Elf_Shdr, |
| 847 | 847 | name: []const u8 = "", |
| 848 | 848 | segment: ?*const Elf_Phdr = null, // if the section is used by a program segment (there can be more than one) |
| 849 | payload: ?[]align(section_memory_align) const u8 = null, // if we need the data in memory | |
| 849 | payload: ?[]align(section_memory_align.toByteUnits()) const u8 = null, // if we need the data in memory | |
| 850 | 850 | category: SectionCategory = .none, // should the section be kept in the exe or stripped to the debug database, or both. |
| 851 | 851 | }; |
| 852 | 852 | |
| ... | ... | @@ -999,7 +999,7 @@ fn ElfFile(comptime is_64: bool) type { |
| 999 | 999 | remap_idx: u16, |
| 1000 | 1000 | |
| 1001 | 1001 | // optionally overrides the payload from the source file |
| 1002 | payload: ?[]align(section_memory_align) const u8 = null, | |
| 1002 | payload: ?[]align(section_memory_align.toByteUnits()) const u8 = null, | |
| 1003 | 1003 | section: ?Elf_Shdr = null, |
| 1004 | 1004 | }; |
| 1005 | 1005 | const sections_update = try allocator.alloc(Update, self.sections.len); |
| ... | ... | @@ -1219,7 +1219,7 @@ fn ElfFile(comptime is_64: bool) type { |
| 1219 | 1219 | if (options.debuglink) |link| { |
| 1220 | 1220 | const payload = payload: { |
| 1221 | 1221 | const crc_offset = std.mem.alignForward(usize, link.name.len + 1, 4); |
| 1222 | const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4); | |
| 1222 | const buf = try allocator.alignedAlloc(u8, .@"4", crc_offset + 4); | |
| 1223 | 1223 | @memcpy(buf[0..link.name.len], link.name); |
| 1224 | 1224 | @memset(buf[link.name.len..crc_offset], 0); |
| 1225 | 1225 | @memcpy(buf[crc_offset..], std.mem.asBytes(&link.crc32)); |
| ... | ... | @@ -1498,7 +1498,7 @@ const ElfFileHelper = struct { |
| 1498 | 1498 | var section_reader = std.io.limitedReader(in_file.reader(), size); |
| 1499 | 1499 | |
| 1500 | 1500 | // allocate as large as decompressed data. if the compression doesn't fit, keep the data uncompressed. |
| 1501 | const compressed_data = try allocator.alignedAlloc(u8, 8, @intCast(size)); | |
| 1501 | const compressed_data = try allocator.alignedAlloc(u8, .@"8", @intCast(size)); | |
| 1502 | 1502 | var compressed_stream = std.io.fixedBufferStream(compressed_data); |
| 1503 | 1503 | |
| 1504 | 1504 | try compressed_stream.writer().writeAll(prefix); |
lib/std/Build/Step/CheckObject.zig+1-1| ... | ... | @@ -563,7 +563,7 @@ fn make(step: *Step, make_options: Step.MakeOptions) !void { |
| 563 | 563 | src_path.sub_path, |
| 564 | 564 | check_object.max_bytes, |
| 565 | 565 | null, |
| 566 | @alignOf(u64), | |
| 566 | .of(u64), | |
| 567 | 567 | null, |
| 568 | 568 | ) catch |err| return step.fail("unable to read '{'}': {s}", .{ src_path, @errorName(err) }); |
| 569 | 569 |
lib/std/Build/Watch.zig+1-1| ... | ... | @@ -56,7 +56,7 @@ const Os = switch (builtin.os.tag) { |
| 56 | 56 | const bytes = lfh.slice(); |
| 57 | 57 | const new_ptr = try gpa.alignedAlloc( |
| 58 | 58 | u8, |
| 59 | @alignOf(std.os.linux.file_handle), | |
| 59 | .of(std.os.linux.file_handle), | |
| 60 | 60 | @sizeOf(std.os.linux.file_handle) + bytes.len, |
| 61 | 61 | ); |
| 62 | 62 | const new_header: *std.os.linux.file_handle = @ptrCast(new_ptr); |
lib/std/array_hash_map.zig+1-1| ... | ... | @@ -2129,7 +2129,7 @@ const IndexHeader = struct { |
| 2129 | 2129 | const len = @as(usize, 1) << @as(math.Log2Int(usize), @intCast(new_bit_index)); |
| 2130 | 2130 | const index_size = hash_map.capacityIndexSize(new_bit_index); |
| 2131 | 2131 | const nbytes = @sizeOf(IndexHeader) + index_size * len; |
| 2132 | const bytes = try gpa.alignedAlloc(u8, @alignOf(IndexHeader), nbytes); | |
| 2132 | const bytes = try gpa.alignedAlloc(u8, .of(IndexHeader), nbytes); | |
| 2133 | 2133 | @memset(bytes[@sizeOf(IndexHeader)..], 0xff); |
| 2134 | 2134 | const result: *IndexHeader = @alignCast(@ptrCast(bytes.ptr)); |
| 2135 | 2135 | result.* = .{ |
lib/std/array_list.zig+12-12| ... | ... | @@ -22,9 +22,9 @@ pub fn ArrayList(comptime T: type) type { |
| 22 | 22 | /// |
| 23 | 23 | /// This struct internally stores a `std.mem.Allocator` for memory management. |
| 24 | 24 | /// To manually specify an allocator with each function call see `ArrayListAlignedUnmanaged`. |
| 25 | pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | |
| 25 | pub fn ArrayListAligned(comptime T: type, comptime alignment: ?mem.Alignment) type { | |
| 26 | 26 | if (alignment) |a| { |
| 27 | if (a == @alignOf(T)) { | |
| 27 | if (a.toByteUnits() == @alignOf(T)) { | |
| 28 | 28 | return ArrayListAligned(T, null); |
| 29 | 29 | } |
| 30 | 30 | } |
| ... | ... | @@ -43,10 +43,10 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 43 | 43 | capacity: usize, |
| 44 | 44 | allocator: Allocator, |
| 45 | 45 | |
| 46 | pub const Slice = if (alignment) |a| ([]align(a) T) else []T; | |
| 46 | pub const Slice = if (alignment) |a| ([]align(a.toByteUnits()) T) else []T; | |
| 47 | 47 | |
| 48 | 48 | pub fn SentinelSlice(comptime s: T) type { |
| 49 | return if (alignment) |a| ([:s]align(a) T) else [:s]T; | |
| 49 | return if (alignment) |a| ([:s]align(a.toByteUnits()) T) else [:s]T; | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| ... | ... | @@ -611,9 +611,9 @@ pub fn ArrayListUnmanaged(comptime T: type) type { |
| 611 | 611 | /// or use `toOwnedSlice`. |
| 612 | 612 | /// |
| 613 | 613 | /// Default initialization of this struct is deprecated; use `.empty` instead. |
| 614 | pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) type { | |
| 614 | pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?mem.Alignment) type { | |
| 615 | 615 | if (alignment) |a| { |
| 616 | if (a == @alignOf(T)) { | |
| 616 | if (a.toByteUnits() == @alignOf(T)) { | |
| 617 | 617 | return ArrayListAlignedUnmanaged(T, null); |
| 618 | 618 | } |
| 619 | 619 | } |
| ... | ... | @@ -637,10 +637,10 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 637 | 637 | .capacity = 0, |
| 638 | 638 | }; |
| 639 | 639 | |
| 640 | pub const Slice = if (alignment) |a| ([]align(a) T) else []T; | |
| 640 | pub const Slice = if (alignment) |a| ([]align(a.toByteUnits()) T) else []T; | |
| 641 | 641 | |
| 642 | 642 | pub fn SentinelSlice(comptime s: T) type { |
| 643 | return if (alignment) |a| ([:s]align(a) T) else [:s]T; | |
| 643 | return if (alignment) |a| ([:s]align(a.toByteUnits()) T) else [:s]T; | |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /// Initialize with capacity to hold `num` elements. |
| ... | ... | @@ -1913,7 +1913,7 @@ test "ArrayList(u8) implements writer" { |
| 1913 | 1913 | try testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items); |
| 1914 | 1914 | } |
| 1915 | 1915 | { |
| 1916 | var list = ArrayListAligned(u8, 2).init(a); | |
| 1916 | var list = ArrayListAligned(u8, .@"2").init(a); | |
| 1917 | 1917 | defer list.deinit(); |
| 1918 | 1918 | |
| 1919 | 1919 | const writer = list.writer(); |
| ... | ... | @@ -1940,7 +1940,7 @@ test "ArrayListUnmanaged(u8) implements writer" { |
| 1940 | 1940 | try testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items); |
| 1941 | 1941 | } |
| 1942 | 1942 | { |
| 1943 | var list: ArrayListAlignedUnmanaged(u8, 2) = .empty; | |
| 1943 | var list: ArrayListAlignedUnmanaged(u8, .@"2") = .empty; | |
| 1944 | 1944 | defer list.deinit(a); |
| 1945 | 1945 | |
| 1946 | 1946 | const writer = list.writer(a); |
| ... | ... | @@ -2126,7 +2126,7 @@ test "toOwnedSliceSentinel" { |
| 2126 | 2126 | test "accepts unaligned slices" { |
| 2127 | 2127 | const a = testing.allocator; |
| 2128 | 2128 | { |
| 2129 | var list = std.ArrayListAligned(u8, 8).init(a); | |
| 2129 | var list = std.ArrayListAligned(u8, .@"8").init(a); | |
| 2130 | 2130 | defer list.deinit(); |
| 2131 | 2131 | |
| 2132 | 2132 | try list.appendSlice(&.{ 0, 1, 2, 3 }); |
| ... | ... | @@ -2136,7 +2136,7 @@ test "accepts unaligned slices" { |
| 2136 | 2136 | try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 }); |
| 2137 | 2137 | } |
| 2138 | 2138 | { |
| 2139 | var list: std.ArrayListAlignedUnmanaged(u8, 8) = .empty; | |
| 2139 | var list: std.ArrayListAlignedUnmanaged(u8, .@"8") = .empty; | |
| 2140 | 2140 | defer list.deinit(a); |
| 2141 | 2141 | |
| 2142 | 2142 | try list.appendSlice(a, &.{ 0, 1, 2, 3 }); |
lib/std/bounded_array.zig+11-10| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const testing = std.testing; |
| 5 | const Alignment = std.mem.Alignment; | |
| 5 | 6 | |
| 6 | 7 | /// A structure with an array and a length, that can be used as a slice. |
| 7 | 8 | /// |
| ... | ... | @@ -16,7 +17,7 @@ const testing = std.testing; |
| 16 | 17 | /// var a_clone = a; // creates a copy - the structure doesn't use any internal pointers |
| 17 | 18 | /// ``` |
| 18 | 19 | pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type { |
| 19 | return BoundedArrayAligned(T, @alignOf(T), buffer_capacity); | |
| 20 | return BoundedArrayAligned(T, .of(T), buffer_capacity); | |
| 20 | 21 | } |
| 21 | 22 | |
| 22 | 23 | /// A structure with an array, length and alignment, that can be used as a |
| ... | ... | @@ -34,12 +35,12 @@ pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type { |
| 34 | 35 | /// ``` |
| 35 | 36 | pub fn BoundedArrayAligned( |
| 36 | 37 | comptime T: type, |
| 37 | comptime alignment: u29, | |
| 38 | comptime alignment: Alignment, | |
| 38 | 39 | comptime buffer_capacity: usize, |
| 39 | 40 | ) type { |
| 40 | 41 | return struct { |
| 41 | 42 | const Self = @This(); |
| 42 | buffer: [buffer_capacity]T align(alignment) = undefined, | |
| 43 | buffer: [buffer_capacity]T align(alignment.toByteUnits()) = undefined, | |
| 43 | 44 | len: usize = 0, |
| 44 | 45 | |
| 45 | 46 | /// Set the actual length of the slice. |
| ... | ... | @@ -51,15 +52,15 @@ pub fn BoundedArrayAligned( |
| 51 | 52 | |
| 52 | 53 | /// View the internal array as a slice whose size was previously set. |
| 53 | 54 | pub fn slice(self: anytype) switch (@TypeOf(&self.buffer)) { |
| 54 | *align(alignment) [buffer_capacity]T => []align(alignment) T, | |
| 55 | *align(alignment) const [buffer_capacity]T => []align(alignment) const T, | |
| 55 | *align(alignment.toByteUnits()) [buffer_capacity]T => []align(alignment.toByteUnits()) T, | |
| 56 | *align(alignment.toByteUnits()) const [buffer_capacity]T => []align(alignment.toByteUnits()) const T, | |
| 56 | 57 | else => unreachable, |
| 57 | 58 | } { |
| 58 | 59 | return self.buffer[0..self.len]; |
| 59 | 60 | } |
| 60 | 61 | |
| 61 | 62 | /// View the internal array as a constant slice whose size was previously set. |
| 62 | pub fn constSlice(self: *const Self) []align(alignment) const T { | |
| 63 | pub fn constSlice(self: *const Self) []align(alignment.toByteUnits()) const T { | |
| 63 | 64 | return self.slice(); |
| 64 | 65 | } |
| 65 | 66 | |
| ... | ... | @@ -120,7 +121,7 @@ pub fn BoundedArrayAligned( |
| 120 | 121 | |
| 121 | 122 | /// Resize the slice, adding `n` new elements, which have `undefined` values. |
| 122 | 123 | /// The return value is a pointer to the array of uninitialized elements. |
| 123 | pub fn addManyAsArray(self: *Self, comptime n: usize) error{Overflow}!*align(alignment) [n]T { | |
| 124 | pub fn addManyAsArray(self: *Self, comptime n: usize) error{Overflow}!*align(alignment.toByteUnits()) [n]T { | |
| 124 | 125 | const prev_len = self.len; |
| 125 | 126 | try self.resize(self.len + n); |
| 126 | 127 | return self.slice()[prev_len..][0..n]; |
| ... | ... | @@ -128,7 +129,7 @@ pub fn BoundedArrayAligned( |
| 128 | 129 | |
| 129 | 130 | /// Resize the slice, adding `n` new elements, which have `undefined` values. |
| 130 | 131 | /// The return value is a slice pointing to the uninitialized elements. |
| 131 | pub fn addManyAsSlice(self: *Self, n: usize) error{Overflow}![]align(alignment) T { | |
| 132 | pub fn addManyAsSlice(self: *Self, n: usize) error{Overflow}![]align(alignment.toByteUnits()) T { | |
| 132 | 133 | const prev_len = self.len; |
| 133 | 134 | try self.resize(self.len + n); |
| 134 | 135 | return self.slice()[prev_len..][0..n]; |
| ... | ... | @@ -146,7 +147,7 @@ pub fn BoundedArrayAligned( |
| 146 | 147 | /// This can be useful for writing directly into it. |
| 147 | 148 | /// Note that such an operation must be followed up with a |
| 148 | 149 | /// call to `resize()` |
| 149 | pub fn unusedCapacitySlice(self: *Self) []align(alignment) T { | |
| 150 | pub fn unusedCapacitySlice(self: *Self) []align(alignment.toByteUnits()) T { | |
| 150 | 151 | return self.buffer[self.len..]; |
| 151 | 152 | } |
| 152 | 153 | |
| ... | ... | @@ -399,7 +400,7 @@ test BoundedArray { |
| 399 | 400 | } |
| 400 | 401 | |
| 401 | 402 | test "BoundedArrayAligned" { |
| 402 | var a = try BoundedArrayAligned(u8, 16, 4).init(0); | |
| 403 | var a = try BoundedArrayAligned(u8, .@"16", 4).init(0); | |
| 403 | 404 | try a.append(0); |
| 404 | 405 | try a.append(0); |
| 405 | 406 | try a.append(255); |
lib/std/crypto/argon2.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ const pwhash = crypto.pwhash; |
| 14 | 14 | |
| 15 | 15 | const Thread = std.Thread; |
| 16 | 16 | const Blake2b512 = blake2.Blake2b512; |
| 17 | const Blocks = std.ArrayListAligned([block_length]u64, 16); | |
| 17 | const Blocks = std.ArrayListAligned([block_length]u64, .@"16"); | |
| 18 | 18 | const H0 = [Blake2b512.digest_length + 8]u8; |
| 19 | 19 | |
| 20 | 20 | const EncodingError = crypto.errors.EncodingError; |
lib/std/crypto/scrypt.zig+3-3| ... | ... | @@ -195,11 +195,11 @@ pub fn kdf( |
| 195 | 195 | params.r > max_int / 256 or |
| 196 | 196 | n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters; |
| 197 | 197 | |
| 198 | const xy = try allocator.alignedAlloc(u32, 16, 64 * params.r); | |
| 198 | const xy = try allocator.alignedAlloc(u32, .@"16", 64 * params.r); | |
| 199 | 199 | defer allocator.free(xy); |
| 200 | const v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r); | |
| 200 | const v = try allocator.alignedAlloc(u32, .@"16", 32 * n * params.r); | |
| 201 | 201 | defer allocator.free(v); |
| 202 | var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r); | |
| 202 | var dk = try allocator.alignedAlloc(u8, .@"16", params.p * 128 * params.r); | |
| 203 | 203 | defer allocator.free(dk); |
| 204 | 204 | |
| 205 | 205 | try pwhash.pbkdf2(dk, password, salt, 1, HmacSha256); |
lib/std/fs/Dir.zig+3-3| ... | ... | @@ -1960,7 +1960,7 @@ pub fn readFile(self: Dir, file_path: []const u8, buffer: []u8) ![]u8 { |
| 1960 | 1960 | /// On WASI, `file_path` should be encoded as valid UTF-8. |
| 1961 | 1961 | /// On other platforms, `file_path` is an opaque sequence of bytes with no particular encoding. |
| 1962 | 1962 | pub fn readFileAlloc(self: Dir, allocator: mem.Allocator, file_path: []const u8, max_bytes: usize) ![]u8 { |
| 1963 | return self.readFileAllocOptions(allocator, file_path, max_bytes, null, @alignOf(u8), null); | |
| 1963 | return self.readFileAllocOptions(allocator, file_path, max_bytes, null, .of(u8), null); | |
| 1964 | 1964 | } |
| 1965 | 1965 | |
| 1966 | 1966 | /// On success, caller owns returned buffer. |
| ... | ... | @@ -1977,9 +1977,9 @@ pub fn readFileAllocOptions( |
| 1977 | 1977 | file_path: []const u8, |
| 1978 | 1978 | max_bytes: usize, |
| 1979 | 1979 | size_hint: ?usize, |
| 1980 | comptime alignment: u29, | |
| 1980 | comptime alignment: std.mem.Alignment, | |
| 1981 | 1981 | comptime optional_sentinel: ?u8, |
| 1982 | ) !(if (optional_sentinel) |s| [:s]align(alignment) u8 else []align(alignment) u8) { | |
| 1982 | ) !(if (optional_sentinel) |s| [:s]align(alignment.toByteUnits()) u8 else []align(alignment.toByteUnits()) u8) { | |
| 1983 | 1983 | var file = try self.openFile(file_path, .{}); |
| 1984 | 1984 | defer file.close(); |
| 1985 | 1985 |
lib/std/fs/File.zig+4-3| ... | ... | @@ -1133,7 +1133,7 @@ pub fn updateTimes( |
| 1133 | 1133 | /// On success, caller owns returned buffer. |
| 1134 | 1134 | /// If the file is larger than `max_bytes`, returns `error.FileTooBig`. |
| 1135 | 1135 | pub fn readToEndAlloc(self: File, allocator: Allocator, max_bytes: usize) ![]u8 { |
| 1136 | return self.readToEndAllocOptions(allocator, max_bytes, null, @alignOf(u8), null); | |
| 1136 | return self.readToEndAllocOptions(allocator, max_bytes, null, .of(u8), null); | |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | /// Reads all the bytes from the current position to the end of the file. |
| ... | ... | @@ -1147,9 +1147,9 @@ pub fn readToEndAllocOptions( |
| 1147 | 1147 | allocator: Allocator, |
| 1148 | 1148 | max_bytes: usize, |
| 1149 | 1149 | size_hint: ?usize, |
| 1150 | comptime alignment: u29, | |
| 1150 | comptime alignment: Alignment, | |
| 1151 | 1151 | comptime optional_sentinel: ?u8, |
| 1152 | ) !(if (optional_sentinel) |s| [:s]align(alignment) u8 else []align(alignment) u8) { | |
| 1152 | ) !(if (optional_sentinel) |s| [:s]align(alignment.toByteUnits()) u8 else []align(alignment.toByteUnits()) u8) { | |
| 1153 | 1153 | // If no size hint is provided fall back to the size=0 code path |
| 1154 | 1154 | const size = size_hint orelse 0; |
| 1155 | 1155 | |
| ... | ... | @@ -1782,3 +1782,4 @@ const windows = std.os.windows; |
| 1782 | 1782 | const Os = std.builtin.Os; |
| 1783 | 1783 | const maxInt = std.math.maxInt; |
| 1784 | 1784 | const is_windows = builtin.os.tag == .windows; |
| 1785 | const Alignment = std.mem.Alignment; |
lib/std/hash_map.zig+3-2| ... | ... | @@ -6,6 +6,7 @@ const math = std.math; |
| 6 | 6 | const mem = std.mem; |
| 7 | 7 | const Allocator = mem.Allocator; |
| 8 | 8 | const Wyhash = std.hash.Wyhash; |
| 9 | const Alignment = std.mem.Alignment; | |
| 9 | 10 | |
| 10 | 11 | pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K) u64) { |
| 11 | 12 | comptime { |
| ... | ... | @@ -1460,7 +1461,7 @@ pub fn HashMapUnmanaged( |
| 1460 | 1461 | const header_align = @alignOf(Header); |
| 1461 | 1462 | const key_align = if (@sizeOf(K) == 0) 1 else @alignOf(K); |
| 1462 | 1463 | const val_align = if (@sizeOf(V) == 0) 1 else @alignOf(V); |
| 1463 | const max_align = comptime @max(header_align, key_align, val_align); | |
| 1464 | const max_align: Alignment = comptime .fromByteUnits(@max(header_align, key_align, val_align)); | |
| 1464 | 1465 | |
| 1465 | 1466 | const new_cap: usize = new_capacity; |
| 1466 | 1467 | const meta_size = @sizeOf(Header) + new_cap * @sizeOf(Metadata); |
| ... | ... | @@ -1472,7 +1473,7 @@ pub fn HashMapUnmanaged( |
| 1472 | 1473 | const vals_start = std.mem.alignForward(usize, keys_end, val_align); |
| 1473 | 1474 | const vals_end = vals_start + new_cap * @sizeOf(V); |
| 1474 | 1475 | |
| 1475 | const total_size = std.mem.alignForward(usize, vals_end, max_align); | |
| 1476 | const total_size = max_align.forward(vals_end); | |
| 1476 | 1477 | |
| 1477 | 1478 | const slice = try allocator.alignedAlloc(u8, max_align, total_size); |
| 1478 | 1479 | const ptr: [*]u8 = @ptrCast(slice.ptr); |
lib/std/heap.zig+19-18| ... | ... | @@ -7,6 +7,7 @@ const mem = std.mem; |
| 7 | 7 | const c = std.c; |
| 8 | 8 | const Allocator = std.mem.Allocator; |
| 9 | 9 | const windows = std.os.windows; |
| 10 | const Alignment = std.mem.Alignment; | |
| 10 | 11 | |
| 11 | 12 | pub const ArenaAllocator = @import("heap/arena_allocator.zig").ArenaAllocator; |
| 12 | 13 | pub const SmpAllocator = @import("heap/SmpAllocator.zig"); |
| ... | ... | @@ -153,7 +154,7 @@ const CAllocator = struct { |
| 153 | 154 | return @alignCast(@ptrCast(ptr - @sizeOf(usize))); |
| 154 | 155 | } |
| 155 | 156 | |
| 156 | fn alignedAlloc(len: usize, alignment: mem.Alignment) ?[*]u8 { | |
| 157 | fn alignedAlloc(len: usize, alignment: Alignment) ?[*]u8 { | |
| 157 | 158 | const alignment_bytes = alignment.toByteUnits(); |
| 158 | 159 | if (supports_posix_memalign) { |
| 159 | 160 | // The posix_memalign only accepts alignment values that are a |
| ... | ... | @@ -201,7 +202,7 @@ const CAllocator = struct { |
| 201 | 202 | fn alloc( |
| 202 | 203 | _: *anyopaque, |
| 203 | 204 | len: usize, |
| 204 | alignment: mem.Alignment, | |
| 205 | alignment: Alignment, | |
| 205 | 206 | return_address: usize, |
| 206 | 207 | ) ?[*]u8 { |
| 207 | 208 | _ = return_address; |
| ... | ... | @@ -212,7 +213,7 @@ const CAllocator = struct { |
| 212 | 213 | fn resize( |
| 213 | 214 | _: *anyopaque, |
| 214 | 215 | buf: []u8, |
| 215 | alignment: mem.Alignment, | |
| 216 | alignment: Alignment, | |
| 216 | 217 | new_len: usize, |
| 217 | 218 | return_address: usize, |
| 218 | 219 | ) bool { |
| ... | ... | @@ -233,7 +234,7 @@ const CAllocator = struct { |
| 233 | 234 | fn remap( |
| 234 | 235 | context: *anyopaque, |
| 235 | 236 | memory: []u8, |
| 236 | alignment: mem.Alignment, | |
| 237 | alignment: Alignment, | |
| 237 | 238 | new_len: usize, |
| 238 | 239 | return_address: usize, |
| 239 | 240 | ) ?[*]u8 { |
| ... | ... | @@ -245,7 +246,7 @@ const CAllocator = struct { |
| 245 | 246 | fn free( |
| 246 | 247 | _: *anyopaque, |
| 247 | 248 | buf: []u8, |
| 248 | alignment: mem.Alignment, | |
| 249 | alignment: Alignment, | |
| 249 | 250 | return_address: usize, |
| 250 | 251 | ) void { |
| 251 | 252 | _ = alignment; |
| ... | ... | @@ -281,7 +282,7 @@ const raw_c_allocator_vtable: Allocator.VTable = .{ |
| 281 | 282 | fn rawCAlloc( |
| 282 | 283 | context: *anyopaque, |
| 283 | 284 | len: usize, |
| 284 | alignment: mem.Alignment, | |
| 285 | alignment: Alignment, | |
| 285 | 286 | return_address: usize, |
| 286 | 287 | ) ?[*]u8 { |
| 287 | 288 | _ = context; |
| ... | ... | @@ -299,7 +300,7 @@ fn rawCAlloc( |
| 299 | 300 | fn rawCResize( |
| 300 | 301 | context: *anyopaque, |
| 301 | 302 | memory: []u8, |
| 302 | alignment: mem.Alignment, | |
| 303 | alignment: Alignment, | |
| 303 | 304 | new_len: usize, |
| 304 | 305 | return_address: usize, |
| 305 | 306 | ) bool { |
| ... | ... | @@ -314,7 +315,7 @@ fn rawCResize( |
| 314 | 315 | fn rawCRemap( |
| 315 | 316 | context: *anyopaque, |
| 316 | 317 | memory: []u8, |
| 317 | alignment: mem.Alignment, | |
| 318 | alignment: Alignment, | |
| 318 | 319 | new_len: usize, |
| 319 | 320 | return_address: usize, |
| 320 | 321 | ) ?[*]u8 { |
| ... | ... | @@ -327,7 +328,7 @@ fn rawCRemap( |
| 327 | 328 | fn rawCFree( |
| 328 | 329 | context: *anyopaque, |
| 329 | 330 | memory: []u8, |
| 330 | alignment: mem.Alignment, | |
| 331 | alignment: Alignment, | |
| 331 | 332 | return_address: usize, |
| 332 | 333 | ) void { |
| 333 | 334 | _ = context; |
| ... | ... | @@ -425,7 +426,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type { |
| 425 | 426 | fn alloc( |
| 426 | 427 | ctx: *anyopaque, |
| 427 | 428 | len: usize, |
| 428 | alignment: mem.Alignment, | |
| 429 | alignment: Alignment, | |
| 429 | 430 | ra: usize, |
| 430 | 431 | ) ?[*]u8 { |
| 431 | 432 | const self: *Self = @ptrCast(@alignCast(ctx)); |
| ... | ... | @@ -436,7 +437,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type { |
| 436 | 437 | fn resize( |
| 437 | 438 | ctx: *anyopaque, |
| 438 | 439 | buf: []u8, |
| 439 | alignment: mem.Alignment, | |
| 440 | alignment: Alignment, | |
| 440 | 441 | new_len: usize, |
| 441 | 442 | ra: usize, |
| 442 | 443 | ) bool { |
| ... | ... | @@ -451,7 +452,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type { |
| 451 | 452 | fn remap( |
| 452 | 453 | context: *anyopaque, |
| 453 | 454 | memory: []u8, |
| 454 | alignment: mem.Alignment, | |
| 455 | alignment: Alignment, | |
| 455 | 456 | new_len: usize, |
| 456 | 457 | return_address: usize, |
| 457 | 458 | ) ?[*]u8 { |
| ... | ... | @@ -466,7 +467,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type { |
| 466 | 467 | fn free( |
| 467 | 468 | ctx: *anyopaque, |
| 468 | 469 | buf: []u8, |
| 469 | alignment: mem.Alignment, | |
| 470 | alignment: Alignment, | |
| 470 | 471 | ra: usize, |
| 471 | 472 | ) void { |
| 472 | 473 | const self: *Self = @ptrCast(@alignCast(ctx)); |
| ... | ... | @@ -512,7 +513,7 @@ test PageAllocator { |
| 512 | 513 | } |
| 513 | 514 | |
| 514 | 515 | if (builtin.os.tag == .windows) { |
| 515 | const slice = try allocator.alignedAlloc(u8, page_size_min, 128); | |
| 516 | const slice = try allocator.alignedAlloc(u8, .fromByteUnits(page_size_min), 128); | |
| 516 | 517 | slice[0] = 0x12; |
| 517 | 518 | slice[127] = 0x34; |
| 518 | 519 | allocator.free(slice); |
| ... | ... | @@ -609,7 +610,7 @@ pub fn testAllocatorAligned(base_allocator: mem.Allocator) !void { |
| 609 | 610 | const allocator = validationAllocator.allocator(); |
| 610 | 611 | |
| 611 | 612 | // Test a few alignment values, smaller and bigger than the type's one |
| 612 | inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| { | |
| 613 | inline for ([_]Alignment{ .@"1", .@"2", .@"4", .@"8", .@"16", .@"32", .@"64" }) |alignment| { | |
| 613 | 614 | // initial |
| 614 | 615 | var slice = try allocator.alignedAlloc(u8, alignment, 10); |
| 615 | 616 | try testing.expect(slice.len == 10); |
| ... | ... | @@ -640,7 +641,7 @@ pub fn testAllocatorLargeAlignment(base_allocator: mem.Allocator) !void { |
| 640 | 641 | var align_mask: usize = undefined; |
| 641 | 642 | align_mask = @shlWithOverflow(~@as(usize, 0), @as(Allocator.Log2Align, @ctz(large_align)))[0]; |
| 642 | 643 | |
| 643 | var slice = try allocator.alignedAlloc(u8, large_align, 500); | |
| 644 | var slice = try allocator.alignedAlloc(u8, .fromByteUnits(large_align), 500); | |
| 644 | 645 | try testing.expect(@intFromPtr(slice.ptr) & align_mask == @intFromPtr(slice.ptr)); |
| 645 | 646 | |
| 646 | 647 | if (allocator.resize(slice, 100)) { |
| ... | ... | @@ -669,7 +670,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void { |
| 669 | 670 | const debug_allocator = fib.allocator(); |
| 670 | 671 | |
| 671 | 672 | const alloc_size = pageSize() * 2 + 50; |
| 672 | var slice = try allocator.alignedAlloc(u8, 16, alloc_size); | |
| 673 | var slice = try allocator.alignedAlloc(u8, .@"16", alloc_size); | |
| 673 | 674 | defer allocator.free(slice); |
| 674 | 675 | |
| 675 | 676 | var stuff_to_free = std.ArrayList([]align(16) u8).init(debug_allocator); |
| ... | ... | @@ -679,7 +680,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void { |
| 679 | 680 | // fail, because of this high over-alignment we want to have. |
| 680 | 681 | while (@intFromPtr(slice.ptr) == mem.alignForward(usize, @intFromPtr(slice.ptr), pageSize() * 32)) { |
| 681 | 682 | try stuff_to_free.append(slice); |
| 682 | slice = try allocator.alignedAlloc(u8, 16, alloc_size); | |
| 683 | slice = try allocator.alignedAlloc(u8, .@"16", alloc_size); | |
| 683 | 684 | } |
| 684 | 685 | while (stuff_to_free.pop()) |item| { |
| 685 | 686 | allocator.free(item); |
lib/std/heap/WasmAllocator.zig+1-1| ... | ... | @@ -218,7 +218,7 @@ test "very large allocation" { |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | test "realloc" { |
| 221 | var slice = try test_ally.alignedAlloc(u8, @alignOf(u32), 1); | |
| 221 | var slice = try test_ally.alignedAlloc(u8, .of(u32), 1); | |
| 222 | 222 | defer test_ally.free(slice); |
| 223 | 223 | slice[0] = 0x12; |
| 224 | 224 |
lib/std/heap/arena_allocator.zig+8-7| ... | ... | @@ -2,6 +2,7 @@ const std = @import("../std.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const Allocator = std.mem.Allocator; |
| 5 | const Alignment = std.mem.Alignment; | |
| 5 | 6 | |
| 6 | 7 | /// This allocator takes an existing allocator, wraps it, and provides an interface where |
| 7 | 8 | /// you can allocate and then free it all together. Calls to free an individual item only |
| ... | ... | @@ -41,7 +42,7 @@ pub const ArenaAllocator = struct { |
| 41 | 42 | data: usize, |
| 42 | 43 | node: std.SinglyLinkedList.Node = .{}, |
| 43 | 44 | }; |
| 44 | const BufNode_alignment: mem.Alignment = .fromByteUnits(@alignOf(BufNode)); | |
| 45 | const BufNode_alignment: Alignment = .fromByteUnits(@alignOf(BufNode)); | |
| 45 | 46 | |
| 46 | 47 | pub fn init(child_allocator: Allocator) ArenaAllocator { |
| 47 | 48 | return (State{}).promote(child_allocator); |
| ... | ... | @@ -181,7 +182,7 @@ pub const ArenaAllocator = struct { |
| 181 | 182 | return buf_node; |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | fn alloc(ctx: *anyopaque, n: usize, alignment: mem.Alignment, ra: usize) ?[*]u8 { | |
| 185 | fn alloc(ctx: *anyopaque, n: usize, alignment: Alignment, ra: usize) ?[*]u8 { | |
| 185 | 186 | const self: *ArenaAllocator = @ptrCast(@alignCast(ctx)); |
| 186 | 187 | _ = ra; |
| 187 | 188 | |
| ... | ... | @@ -214,7 +215,7 @@ pub const ArenaAllocator = struct { |
| 214 | 215 | } |
| 215 | 216 | } |
| 216 | 217 | |
| 217 | fn resize(ctx: *anyopaque, buf: []u8, alignment: mem.Alignment, new_len: usize, ret_addr: usize) bool { | |
| 218 | fn resize(ctx: *anyopaque, buf: []u8, alignment: Alignment, new_len: usize, ret_addr: usize) bool { | |
| 218 | 219 | const self: *ArenaAllocator = @ptrCast(@alignCast(ctx)); |
| 219 | 220 | _ = alignment; |
| 220 | 221 | _ = ret_addr; |
| ... | ... | @@ -242,14 +243,14 @@ pub const ArenaAllocator = struct { |
| 242 | 243 | fn remap( |
| 243 | 244 | context: *anyopaque, |
| 244 | 245 | memory: []u8, |
| 245 | alignment: mem.Alignment, | |
| 246 | alignment: Alignment, | |
| 246 | 247 | new_len: usize, |
| 247 | 248 | return_address: usize, |
| 248 | 249 | ) ?[*]u8 { |
| 249 | 250 | return if (resize(context, memory, alignment, new_len, return_address)) memory.ptr else null; |
| 250 | 251 | } |
| 251 | 252 | |
| 252 | fn free(ctx: *anyopaque, buf: []u8, alignment: mem.Alignment, ret_addr: usize) void { | |
| 253 | fn free(ctx: *anyopaque, buf: []u8, alignment: Alignment, ret_addr: usize) void { | |
| 253 | 254 | _ = alignment; |
| 254 | 255 | _ = ret_addr; |
| 255 | 256 | |
| ... | ... | @@ -279,9 +280,9 @@ test "reset with preheating" { |
| 279 | 280 | const total_size: usize = random.intRangeAtMost(usize, 256, 16384); |
| 280 | 281 | while (alloced_bytes < total_size) { |
| 281 | 282 | const size = random.intRangeAtMost(usize, 16, 256); |
| 282 | const alignment = 32; | |
| 283 | const alignment: Alignment = .@"32"; | |
| 283 | 284 | const slice = try arena_allocator.allocator().alignedAlloc(u8, alignment, size); |
| 284 | try std.testing.expect(std.mem.isAligned(@intFromPtr(slice.ptr), alignment)); | |
| 285 | try std.testing.expect(alignment.check(@intFromPtr(slice.ptr))); | |
| 285 | 286 | try std.testing.expectEqual(size, slice.len); |
| 286 | 287 | alloced_bytes += slice.len; |
| 287 | 288 | } |
lib/std/heap/debug_allocator.zig+6-6| ... | ... | @@ -1120,7 +1120,7 @@ test "realloc" { |
| 1120 | 1120 | defer std.testing.expect(gpa.deinit() == .ok) catch @panic("leak"); |
| 1121 | 1121 | const allocator = gpa.allocator(); |
| 1122 | 1122 | |
| 1123 | var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1); | |
| 1123 | var slice = try allocator.alignedAlloc(u8, .of(u32), 1); | |
| 1124 | 1124 | defer allocator.free(slice); |
| 1125 | 1125 | slice[0] = 0x12; |
| 1126 | 1126 | |
| ... | ... | @@ -1234,7 +1234,7 @@ test "shrink large object to large object with larger alignment" { |
| 1234 | 1234 | const debug_allocator = fba.allocator(); |
| 1235 | 1235 | |
| 1236 | 1236 | const alloc_size = default_page_size * 2 + 50; |
| 1237 | var slice = try allocator.alignedAlloc(u8, 16, alloc_size); | |
| 1237 | var slice = try allocator.alignedAlloc(u8, .@"16", alloc_size); | |
| 1238 | 1238 | defer allocator.free(slice); |
| 1239 | 1239 | |
| 1240 | 1240 | const big_alignment: usize = default_page_size * 2; |
| ... | ... | @@ -1244,7 +1244,7 @@ test "shrink large object to large object with larger alignment" { |
| 1244 | 1244 | var stuff_to_free = std.ArrayList([]align(16) u8).init(debug_allocator); |
| 1245 | 1245 | while (mem.isAligned(@intFromPtr(slice.ptr), big_alignment)) { |
| 1246 | 1246 | try stuff_to_free.append(slice); |
| 1247 | slice = try allocator.alignedAlloc(u8, 16, alloc_size); | |
| 1247 | slice = try allocator.alignedAlloc(u8, .@"16", alloc_size); | |
| 1248 | 1248 | } |
| 1249 | 1249 | while (stuff_to_free.pop()) |item| { |
| 1250 | 1250 | allocator.free(item); |
| ... | ... | @@ -1308,7 +1308,7 @@ test "realloc large object to larger alignment" { |
| 1308 | 1308 | var fba = std.heap.FixedBufferAllocator.init(&debug_buffer); |
| 1309 | 1309 | const debug_allocator = fba.allocator(); |
| 1310 | 1310 | |
| 1311 | var slice = try allocator.alignedAlloc(u8, 16, default_page_size * 2 + 50); | |
| 1311 | var slice = try allocator.alignedAlloc(u8, .@"16", default_page_size * 2 + 50); | |
| 1312 | 1312 | defer allocator.free(slice); |
| 1313 | 1313 | |
| 1314 | 1314 | const big_alignment: usize = default_page_size * 2; |
| ... | ... | @@ -1316,7 +1316,7 @@ test "realloc large object to larger alignment" { |
| 1316 | 1316 | var stuff_to_free = std.ArrayList([]align(16) u8).init(debug_allocator); |
| 1317 | 1317 | while (mem.isAligned(@intFromPtr(slice.ptr), big_alignment)) { |
| 1318 | 1318 | try stuff_to_free.append(slice); |
| 1319 | slice = try allocator.alignedAlloc(u8, 16, default_page_size * 2 + 50); | |
| 1319 | slice = try allocator.alignedAlloc(u8, .@"16", default_page_size * 2 + 50); | |
| 1320 | 1320 | } |
| 1321 | 1321 | while (stuff_to_free.pop()) |item| { |
| 1322 | 1322 | allocator.free(item); |
| ... | ... | @@ -1402,7 +1402,7 @@ test "large allocations count requested size not backing size" { |
| 1402 | 1402 | var gpa: DebugAllocator(.{ .enable_memory_limit = true }) = .{}; |
| 1403 | 1403 | const allocator = gpa.allocator(); |
| 1404 | 1404 | |
| 1405 | var buf = try allocator.alignedAlloc(u8, 1, default_page_size + 1); | |
| 1405 | var buf = try allocator.alignedAlloc(u8, .@"1", default_page_size + 1); | |
| 1406 | 1406 | try std.testing.expectEqual(default_page_size + 1, gpa.total_requested_bytes); |
| 1407 | 1407 | buf = try allocator.realloc(buf, 1); |
| 1408 | 1408 | try std.testing.expectEqual(1, gpa.total_requested_bytes); |
lib/std/heap/memory_pool.zig+12-11| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const std = @import("../std.zig"); |
| 2 | const Alignment = std.mem.Alignment; | |
| 2 | 3 | |
| 3 | 4 | const debug_mode = @import("builtin").mode == .Debug; |
| 4 | 5 | |
| ... | ... | @@ -8,14 +9,14 @@ pub const MemoryPoolError = error{OutOfMemory}; |
| 8 | 9 | /// Use this when you need to allocate a lot of objects of the same type, |
| 9 | 10 | /// because It outperforms general purpose allocators. |
| 10 | 11 | pub fn MemoryPool(comptime Item: type) type { |
| 11 | return MemoryPoolAligned(Item, @alignOf(Item)); | |
| 12 | return MemoryPoolAligned(Item, .of(Item)); | |
| 12 | 13 | } |
| 13 | 14 | |
| 14 | 15 | /// A memory pool that can allocate objects of a single type very quickly. |
| 15 | 16 | /// Use this when you need to allocate a lot of objects of the same type, |
| 16 | 17 | /// because It outperforms general purpose allocators. |
| 17 | pub fn MemoryPoolAligned(comptime Item: type, comptime alignment: u29) type { | |
| 18 | if (@alignOf(Item) == alignment) { | |
| 18 | pub fn MemoryPoolAligned(comptime Item: type, comptime alignment: Alignment) type { | |
| 19 | if (@alignOf(Item) == comptime alignment.toByteUnits()) { | |
| 19 | 20 | return MemoryPoolExtra(Item, .{}); |
| 20 | 21 | } else { |
| 21 | 22 | return MemoryPoolExtra(Item, .{ .alignment = alignment }); |
| ... | ... | @@ -24,7 +25,7 @@ pub fn MemoryPoolAligned(comptime Item: type, comptime alignment: u29) type { |
| 24 | 25 | |
| 25 | 26 | pub const Options = struct { |
| 26 | 27 | /// The alignment of the memory pool items. Use `null` for natural alignment. |
| 27 | alignment: ?u29 = null, | |
| 28 | alignment: ?Alignment = null, | |
| 28 | 29 | |
| 29 | 30 | /// If `true`, the memory pool can allocate additional items after a initial setup. |
| 30 | 31 | /// If `false`, the memory pool will not allocate further after a call to `initPreheated`. |
| ... | ... | @@ -43,17 +44,17 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type |
| 43 | 44 | pub const item_size = @max(@sizeOf(Node), @sizeOf(Item)); |
| 44 | 45 | |
| 45 | 46 | // This needs to be kept in sync with Node. |
| 46 | const node_alignment = @alignOf(*anyopaque); | |
| 47 | const node_alignment: Alignment = .of(*anyopaque); | |
| 47 | 48 | |
| 48 | 49 | /// Alignment of the memory pool items. This is not necessarily the same |
| 49 | 50 | /// as `@alignOf(Item)` as the pool also uses the items for internal means. |
| 50 | pub const item_alignment = @max(node_alignment, pool_options.alignment orelse @alignOf(Item)); | |
| 51 | pub const item_alignment: Alignment = node_alignment.max(pool_options.alignment orelse .of(Item)); | |
| 51 | 52 | |
| 52 | 53 | const Node = struct { |
| 53 | next: ?*align(item_alignment) @This(), | |
| 54 | next: ?*align(item_alignment.toByteUnits()) @This(), | |
| 54 | 55 | }; |
| 55 | const NodePtr = *align(item_alignment) Node; | |
| 56 | const ItemPtr = *align(item_alignment) Item; | |
| 56 | const NodePtr = *align(item_alignment.toByteUnits()) Node; | |
| 57 | const ItemPtr = *align(item_alignment.toByteUnits()) Item; | |
| 57 | 58 | |
| 58 | 59 | arena: std.heap.ArenaAllocator, |
| 59 | 60 | free_list: ?NodePtr = null, |
| ... | ... | @@ -143,7 +144,7 @@ pub fn MemoryPoolExtra(comptime Item: type, comptime pool_options: Options) type |
| 143 | 144 | pool.free_list = node; |
| 144 | 145 | } |
| 145 | 146 | |
| 146 | fn allocNew(pool: *Pool) MemoryPoolError!*align(item_alignment) [item_size]u8 { | |
| 147 | fn allocNew(pool: *Pool) MemoryPoolError!*align(item_alignment.toByteUnits()) [item_size]u8 { | |
| 147 | 148 | const mem = try pool.arena.allocator().alignedAlloc(u8, item_alignment, item_size); |
| 148 | 149 | return mem[0..item_size]; // coerce slice to array pointer |
| 149 | 150 | } |
| ... | ... | @@ -213,7 +214,7 @@ test "greater than pointer manual alignment" { |
| 213 | 214 | data: u64, |
| 214 | 215 | }; |
| 215 | 216 | |
| 216 | var pool = MemoryPoolAligned(Foo, 16).init(std.testing.allocator); | |
| 217 | var pool = MemoryPoolAligned(Foo, .@"16").init(std.testing.allocator); | |
| 217 | 218 | defer pool.deinit(); |
| 218 | 219 | |
| 219 | 220 | const foo: *align(16) Foo = try pool.create(); |
lib/std/io.zig+2-2| ... | ... | @@ -5,7 +5,6 @@ const c = std.c; |
| 5 | 5 | const is_windows = builtin.os.tag == .windows; |
| 6 | 6 | const windows = std.os.windows; |
| 7 | 7 | const posix = std.posix; |
| 8 | ||
| 9 | 8 | const math = std.math; |
| 10 | 9 | const assert = std.debug.assert; |
| 11 | 10 | const fs = std.fs; |
| ... | ... | @@ -13,6 +12,7 @@ const mem = std.mem; |
| 13 | 12 | const meta = std.meta; |
| 14 | 13 | const File = std.fs.File; |
| 15 | 14 | const Allocator = std.mem.Allocator; |
| 15 | const Alignment = std.mem.Alignment; | |
| 16 | 16 | |
| 17 | 17 | fn getStdOutHandle() posix.fd_t { |
| 18 | 18 | if (is_windows) { |
| ... | ... | @@ -104,7 +104,7 @@ pub fn GenericReader( |
| 104 | 104 | |
| 105 | 105 | pub inline fn readAllArrayListAligned( |
| 106 | 106 | self: Self, |
| 107 | comptime alignment: ?u29, | |
| 107 | comptime alignment: ?Alignment, | |
| 108 | 108 | array_list: *std.ArrayListAligned(u8, alignment), |
| 109 | 109 | max_append_size: usize, |
| 110 | 110 | ) (error{StreamTooLong} || Allocator.Error || Error)!void { |
lib/std/io/Reader.zig+2-1| ... | ... | @@ -54,7 +54,7 @@ pub fn readAllArrayList( |
| 54 | 54 | |
| 55 | 55 | pub fn readAllArrayListAligned( |
| 56 | 56 | self: Self, |
| 57 | comptime alignment: ?u29, | |
| 57 | comptime alignment: ?Alignment, | |
| 58 | 58 | array_list: *std.ArrayListAligned(u8, alignment), |
| 59 | 59 | max_append_size: usize, |
| 60 | 60 | ) anyerror!void { |
| ... | ... | @@ -379,6 +379,7 @@ const assert = std.debug.assert; |
| 379 | 379 | const mem = std.mem; |
| 380 | 380 | const testing = std.testing; |
| 381 | 381 | const native_endian = @import("builtin").target.cpu.arch.endian(); |
| 382 | const Alignment = std.mem.Alignment; | |
| 382 | 383 | |
| 383 | 384 | test { |
| 384 | 385 | _ = @import("Reader/test.zig"); |
lib/std/math.zig+6-8| ... | ... | @@ -4,6 +4,7 @@ const float = @import("math/float.zig"); |
| 4 | 4 | const assert = std.debug.assert; |
| 5 | 5 | const mem = std.mem; |
| 6 | 6 | const testing = std.testing; |
| 7 | const Alignment = std.mem.Alignment; | |
| 7 | 8 | |
| 8 | 9 | /// Euler's number (e) |
| 9 | 10 | pub const e = 2.71828182845904523536028747135266249775724709369995; |
| ... | ... | @@ -1084,19 +1085,16 @@ test cast { |
| 1084 | 1085 | |
| 1085 | 1086 | pub const AlignCastError = error{UnalignedMemory}; |
| 1086 | 1087 | |
| 1087 | fn AlignCastResult(comptime alignment: u29, comptime Ptr: type) type { | |
| 1088 | fn AlignCastResult(comptime alignment: Alignment, comptime Ptr: type) type { | |
| 1088 | 1089 | var ptr_info = @typeInfo(Ptr); |
| 1089 | ptr_info.pointer.alignment = alignment; | |
| 1090 | ptr_info.pointer.alignment = alignment.toByteUnits(); | |
| 1090 | 1091 | return @Type(ptr_info); |
| 1091 | 1092 | } |
| 1092 | 1093 | |
| 1093 | 1094 | /// Align cast a pointer but return an error if it's the wrong alignment |
| 1094 | pub fn alignCast(comptime alignment: u29, ptr: anytype) AlignCastError!AlignCastResult(alignment, @TypeOf(ptr)) { | |
| 1095 | const addr = @intFromPtr(ptr); | |
| 1096 | if (addr % alignment != 0) { | |
| 1097 | return error.UnalignedMemory; | |
| 1098 | } | |
| 1099 | return @alignCast(ptr); | |
| 1095 | pub fn alignCast(comptime alignment: Alignment, ptr: anytype) AlignCastError!AlignCastResult(alignment, @TypeOf(ptr)) { | |
| 1096 | if (alignment.check(@intFromPtr(ptr))) return @alignCast(ptr); | |
| 1097 | return error.UnalignedMemory; | |
| 1100 | 1098 | } |
| 1101 | 1099 | |
| 1102 | 1100 | /// Asserts `int > 0`. |
lib/std/mem.zig+4-15| ... | ... | @@ -38,6 +38,10 @@ pub const Alignment = enum(math.Log2Int(usize)) { |
| 38 | 38 | return @enumFromInt(@ctz(n)); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | pub inline fn of(comptime T: type) Alignment { | |
| 42 | return comptime fromByteUnits(@alignOf(T)); | |
| 43 | } | |
| 44 | ||
| 41 | 45 | pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order { |
| 42 | 46 | return std.math.order(@intFromEnum(lhs), @intFromEnum(rhs)); |
| 43 | 47 | } |
| ... | ... | @@ -166,21 +170,6 @@ pub fn validationWrap(allocator: anytype) ValidationAllocator(@TypeOf(allocator) |
| 166 | 170 | return ValidationAllocator(@TypeOf(allocator)).init(allocator); |
| 167 | 171 | } |
| 168 | 172 | |
| 169 | /// An allocator helper function. Adjusts an allocation length satisfy `len_align`. | |
| 170 | /// `full_len` should be the full capacity of the allocation which may be greater | |
| 171 | /// than the `len` that was requested. This function should only be used by allocators | |
| 172 | /// that are unaffected by `len_align`. | |
| 173 | pub fn alignAllocLen(full_len: usize, alloc_len: usize, len_align: u29) usize { | |
| 174 | assert(alloc_len > 0); | |
| 175 | assert(alloc_len >= len_align); | |
| 176 | assert(full_len >= alloc_len); | |
| 177 | if (len_align == 0) | |
| 178 | return alloc_len; | |
| 179 | const adjusted = alignBackwardAnyAlign(usize, full_len, len_align); | |
| 180 | assert(adjusted >= alloc_len); | |
| 181 | return adjusted; | |
| 182 | } | |
| 183 | ||
| 184 | 173 | test "Allocator basics" { |
| 185 | 174 | try testing.expectError(error.OutOfMemory, testing.failing_allocator.alloc(u8, 1)); |
| 186 | 175 | try testing.expectError(error.OutOfMemory, testing.failing_allocator.allocSentinel(u8, 1, 0)); |
lib/std/mem/Allocator.zig+30-19| ... | ... | @@ -152,9 +152,9 @@ pub inline fn rawFree(a: Allocator, memory: []u8, alignment: Alignment, ret_addr |
| 152 | 152 | pub fn create(a: Allocator, comptime T: type) Error!*T { |
| 153 | 153 | if (@sizeOf(T) == 0) { |
| 154 | 154 | const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), @alignOf(T)); |
| 155 | return @as(*T, @ptrFromInt(ptr)); | |
| 155 | return @ptrFromInt(ptr); | |
| 156 | 156 | } |
| 157 | const ptr: *T = @ptrCast(try a.allocBytesWithAlignment(@alignOf(T), @sizeOf(T), @returnAddress())); | |
| 157 | const ptr: *T = @ptrCast(try a.allocBytesWithAlignment(.of(T), @sizeOf(T), @returnAddress())); | |
| 158 | 158 | return ptr; |
| 159 | 159 | } |
| 160 | 160 | |
| ... | ... | @@ -186,7 +186,7 @@ pub fn allocWithOptions( |
| 186 | 186 | comptime Elem: type, |
| 187 | 187 | n: usize, |
| 188 | 188 | /// null means naturally aligned |
| 189 | comptime optional_alignment: ?u29, | |
| 189 | comptime optional_alignment: ?Alignment, | |
| 190 | 190 | comptime optional_sentinel: ?Elem, |
| 191 | 191 | ) Error!AllocWithOptionsPayload(Elem, optional_alignment, optional_sentinel) { |
| 192 | 192 | return self.allocWithOptionsRetAddr(Elem, n, optional_alignment, optional_sentinel, @returnAddress()); |
| ... | ... | @@ -197,7 +197,7 @@ pub fn allocWithOptionsRetAddr( |
| 197 | 197 | comptime Elem: type, |
| 198 | 198 | n: usize, |
| 199 | 199 | /// null means naturally aligned |
| 200 | comptime optional_alignment: ?u29, | |
| 200 | comptime optional_alignment: ?Alignment, | |
| 201 | 201 | comptime optional_sentinel: ?Elem, |
| 202 | 202 | return_address: usize, |
| 203 | 203 | ) Error!AllocWithOptionsPayload(Elem, optional_alignment, optional_sentinel) { |
| ... | ... | @@ -210,11 +210,11 @@ pub fn allocWithOptionsRetAddr( |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | fn AllocWithOptionsPayload(comptime Elem: type, comptime alignment: ?u29, comptime sentinel: ?Elem) type { | |
| 213 | fn AllocWithOptionsPayload(comptime Elem: type, comptime alignment: ?Alignment, comptime sentinel: ?Elem) type { | |
| 214 | 214 | if (sentinel) |s| { |
| 215 | return [:s]align(alignment orelse @alignOf(Elem)) Elem; | |
| 215 | return [:s]align(if (alignment) |a| a.toByteUnits() else @alignOf(Elem)) Elem; | |
| 216 | 216 | } else { |
| 217 | return []align(alignment orelse @alignOf(Elem)) Elem; | |
| 217 | return []align(if (alignment) |a| a.toByteUnits() else @alignOf(Elem)) Elem; | |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
| ... | ... | @@ -239,9 +239,9 @@ pub fn alignedAlloc( |
| 239 | 239 | self: Allocator, |
| 240 | 240 | comptime T: type, |
| 241 | 241 | /// null means naturally aligned |
| 242 | comptime alignment: ?u29, | |
| 242 | comptime alignment: ?Alignment, | |
| 243 | 243 | n: usize, |
| 244 | ) Error![]align(alignment orelse @alignOf(T)) T { | |
| 244 | ) Error![]align(if (alignment) |a| a.toByteUnits() else @alignOf(T)) T { | |
| 245 | 245 | return self.allocAdvancedWithRetAddr(T, alignment, n, @returnAddress()); |
| 246 | 246 | } |
| 247 | 247 | |
| ... | ... | @@ -249,27 +249,38 @@ pub inline fn allocAdvancedWithRetAddr( |
| 249 | 249 | self: Allocator, |
| 250 | 250 | comptime T: type, |
| 251 | 251 | /// null means naturally aligned |
| 252 | comptime alignment: ?u29, | |
| 252 | comptime alignment: ?Alignment, | |
| 253 | 253 | n: usize, |
| 254 | 254 | return_address: usize, |
| 255 | ) Error![]align(alignment orelse @alignOf(T)) T { | |
| 256 | const a = alignment orelse @alignOf(T); | |
| 257 | const ptr: [*]align(a) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address)); | |
| 255 | ) Error![]align(if (alignment) |a| a.toByteUnits() else @alignOf(T)) T { | |
| 256 | const a = comptime (alignment orelse Alignment.fromByteUnits(@alignOf(T))); | |
| 257 | const ptr: [*]align(a.toByteUnits()) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address)); | |
| 258 | 258 | return ptr[0..n]; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | fn allocWithSizeAndAlignment(self: Allocator, comptime size: usize, comptime alignment: u29, n: usize, return_address: usize) Error![*]align(alignment) u8 { | |
| 261 | fn allocWithSizeAndAlignment( | |
| 262 | self: Allocator, | |
| 263 | comptime size: usize, | |
| 264 | comptime alignment: Alignment, | |
| 265 | n: usize, | |
| 266 | return_address: usize, | |
| 267 | ) Error![*]align(alignment.toByteUnits()) u8 { | |
| 262 | 268 | const byte_count = math.mul(usize, size, n) catch return Error.OutOfMemory; |
| 263 | 269 | return self.allocBytesWithAlignment(alignment, byte_count, return_address); |
| 264 | 270 | } |
| 265 | 271 | |
| 266 | fn allocBytesWithAlignment(self: Allocator, comptime alignment: u29, byte_count: usize, return_address: usize) Error![*]align(alignment) u8 { | |
| 272 | fn allocBytesWithAlignment( | |
| 273 | self: Allocator, | |
| 274 | comptime alignment: Alignment, | |
| 275 | byte_count: usize, | |
| 276 | return_address: usize, | |
| 277 | ) Error![*]align(alignment.toByteUnits()) u8 { | |
| 267 | 278 | if (byte_count == 0) { |
| 268 | const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), alignment); | |
| 269 | return @as([*]align(alignment) u8, @ptrFromInt(ptr)); | |
| 279 | const ptr = comptime alignment.backward(math.maxInt(usize)); | |
| 280 | return @as([*]align(alignment.toByteUnits()) u8, @ptrFromInt(ptr)); | |
| 270 | 281 | } |
| 271 | 282 | |
| 272 | const byte_ptr = self.rawAlloc(byte_count, .fromByteUnits(alignment), return_address) orelse return Error.OutOfMemory; | |
| 283 | const byte_ptr = self.rawAlloc(byte_count, alignment, return_address) orelse return Error.OutOfMemory; | |
| 273 | 284 | @memset(byte_ptr[0..byte_count], undefined); |
| 274 | 285 | return @alignCast(byte_ptr); |
| 275 | 286 | } |
| ... | ... | @@ -378,7 +389,7 @@ pub fn reallocAdvanced( |
| 378 | 389 | const Slice = @typeInfo(@TypeOf(old_mem)).pointer; |
| 379 | 390 | const T = Slice.child; |
| 380 | 391 | if (old_mem.len == 0) { |
| 381 | return self.allocAdvancedWithRetAddr(T, Slice.alignment, new_n, return_address); | |
| 392 | return self.allocAdvancedWithRetAddr(T, .fromByteUnits(Slice.alignment), new_n, return_address); | |
| 382 | 393 | } |
| 383 | 394 | if (new_n == 0) { |
| 384 | 395 | self.free(old_mem); |
lib/std/meta/trailer_flags.zig+1-1| ... | ... | @@ -144,7 +144,7 @@ test TrailerFlags { |
| 144 | 144 | .b = true, |
| 145 | 145 | .c = true, |
| 146 | 146 | }); |
| 147 | const slice = try testing.allocator.alignedAlloc(u8, 8, flags.sizeInBytes()); | |
| 147 | const slice = try testing.allocator.alignedAlloc(u8, .@"8", flags.sizeInBytes()); | |
| 148 | 148 | defer testing.allocator.free(slice); |
| 149 | 149 | |
| 150 | 150 | flags.set(slice.ptr, .b, false); |
lib/std/multi_array_list.zig+2-10| ... | ... | @@ -350,11 +350,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 350 | 350 | assert(new_len <= self.capacity); |
| 351 | 351 | assert(new_len <= self.len); |
| 352 | 352 | |
| 353 | const other_bytes = gpa.alignedAlloc( | |
| 354 | u8, | |
| 355 | @alignOf(Elem), | |
| 356 | capacityInBytes(new_len), | |
| 357 | ) catch { | |
| 353 | const other_bytes = gpa.alignedAlloc(u8, .of(Elem), capacityInBytes(new_len)) catch { | |
| 358 | 354 | const self_slice = self.slice(); |
| 359 | 355 | inline for (fields, 0..) |field_info, i| { |
| 360 | 356 | if (@sizeOf(field_info.type) != 0) { |
| ... | ... | @@ -440,11 +436,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 440 | 436 | /// `new_capacity` must be greater or equal to `len`. |
| 441 | 437 | pub fn setCapacity(self: *Self, gpa: Allocator, new_capacity: usize) !void { |
| 442 | 438 | assert(new_capacity >= self.len); |
| 443 | const new_bytes = try gpa.alignedAlloc( | |
| 444 | u8, | |
| 445 | @alignOf(Elem), | |
| 446 | capacityInBytes(new_capacity), | |
| 447 | ); | |
| 439 | const new_bytes = try gpa.alignedAlloc(u8, .of(Elem), capacityInBytes(new_capacity)); | |
| 448 | 440 | if (self.len == 0) { |
| 449 | 441 | gpa.free(self.allocatedBytes()); |
| 450 | 442 | self.bytes = new_bytes.ptr; |
lib/std/process.zig+1-1| ... | ... | @@ -1256,7 +1256,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 { |
| 1256 | 1256 | const slice_sizes = slice_list.items; |
| 1257 | 1257 | const slice_list_bytes = try math.mul(usize, @sizeOf([]u8), slice_sizes.len); |
| 1258 | 1258 | const total_bytes = try math.add(usize, slice_list_bytes, contents_slice.len); |
| 1259 | const buf = try allocator.alignedAlloc(u8, @alignOf([]u8), total_bytes); | |
| 1259 | const buf = try allocator.alignedAlloc(u8, .of([]u8), total_bytes); | |
| 1260 | 1260 | errdefer allocator.free(buf); |
| 1261 | 1261 | |
| 1262 | 1262 | const result_slice_list = mem.bytesAsSlice([:0]u8, buf[0..slice_list_bytes]); |
lib/std/zig.zig+1-1| ... | ... | @@ -543,7 +543,7 @@ pub fn readSourceFileToEndAlloc(gpa: Allocator, input: std.fs.File, size_hint: ? |
| 543 | 543 | gpa, |
| 544 | 544 | max_src_size, |
| 545 | 545 | size_hint, |
| 546 | @alignOf(u8), | |
| 546 | .of(u8), | |
| 547 | 547 | 0, |
| 548 | 548 | ) catch |err| switch (err) { |
| 549 | 549 | error.ConnectionResetByPeer => unreachable, |
lib/std/zon/parse.zig+1-1| ... | ... | @@ -679,7 +679,7 @@ const Parser = struct { |
| 679 | 679 | const slice = try self.gpa.allocWithOptions( |
| 680 | 680 | pointer.child, |
| 681 | 681 | nodes.len, |
| 682 | pointer.alignment, | |
| 682 | .fromByteUnits(pointer.alignment), | |
| 683 | 683 | pointer.sentinel(), |
| 684 | 684 | ); |
| 685 | 685 | errdefer self.gpa.free(slice); |
src/InternPool.zig+6-6| ... | ... | @@ -255,7 +255,7 @@ pub fn trackZir( |
| 255 | 255 | const new_map_capacity = map_header.capacity * 2; |
| 256 | 256 | const new_map_buf = try arena.allocator().alignedAlloc( |
| 257 | 257 | u8, |
| 258 | Map.alignment, | |
| 258 | .fromByteUnits(Map.alignment), | |
| 259 | 259 | Map.entries_offset + new_map_capacity * @sizeOf(Map.Entry), |
| 260 | 260 | ); |
| 261 | 261 | const new_map: Map = .{ .entries = @ptrCast(new_map_buf[Map.entries_offset..].ptr) }; |
| ... | ... | @@ -350,7 +350,7 @@ pub fn rehashTrackedInsts( |
| 350 | 350 | defer arena_state.* = arena.state; |
| 351 | 351 | const new_map_buf = try arena.allocator().alignedAlloc( |
| 352 | 352 | u8, |
| 353 | Map.alignment, | |
| 353 | .fromByteUnits(Map.alignment), | |
| 354 | 354 | Map.entries_offset + want_capacity * @sizeOf(Map.Entry), |
| 355 | 355 | ); |
| 356 | 356 | const new_map: Map = .{ .entries = @ptrCast(new_map_buf[Map.entries_offset..].ptr) }; |
| ... | ... | @@ -1296,7 +1296,7 @@ const Local = struct { |
| 1296 | 1296 | defer mutable.arena.* = arena.state; |
| 1297 | 1297 | const buf = try arena.allocator().alignedAlloc( |
| 1298 | 1298 | u8, |
| 1299 | alignment, | |
| 1299 | .fromByteUnits(alignment), | |
| 1300 | 1300 | bytes_offset + View.capacityInBytes(capacity), |
| 1301 | 1301 | ); |
| 1302 | 1302 | var new_list: ListSelf = .{ .bytes = @ptrCast(buf[bytes_offset..].ptr) }; |
| ... | ... | @@ -7547,7 +7547,7 @@ fn getOrPutKeyEnsuringAdditionalCapacity( |
| 7547 | 7547 | } |
| 7548 | 7548 | const new_map_buf = try arena.allocator().alignedAlloc( |
| 7549 | 7549 | u8, |
| 7550 | Map.alignment, | |
| 7550 | .fromByteUnits(Map.alignment), | |
| 7551 | 7551 | Map.entries_offset + new_map_capacity * @sizeOf(Map.Entry), |
| 7552 | 7552 | ); |
| 7553 | 7553 | const new_map: Map = .{ .entries = @ptrCast(new_map_buf[Map.entries_offset..].ptr) }; |
| ... | ... | @@ -11666,7 +11666,7 @@ pub fn getOrPutTrailingString( |
| 11666 | 11666 | const new_map_capacity = map_header.capacity * 2; |
| 11667 | 11667 | const new_map_buf = try arena.allocator().alignedAlloc( |
| 11668 | 11668 | u8, |
| 11669 | Map.alignment, | |
| 11669 | .fromByteUnits(Map.alignment), | |
| 11670 | 11670 | Map.entries_offset + new_map_capacity * @sizeOf(Map.Entry), |
| 11671 | 11671 | ); |
| 11672 | 11672 | const new_map: Map = .{ .entries = @ptrCast(new_map_buf[Map.entries_offset..].ptr) }; |
| ... | ... | @@ -12586,7 +12586,7 @@ const GlobalErrorSet = struct { |
| 12586 | 12586 | const new_map_capacity = map_header.capacity * 2; |
| 12587 | 12587 | const new_map_buf = try arena.allocator().alignedAlloc( |
| 12588 | 12588 | u8, |
| 12589 | Map.alignment, | |
| 12589 | .fromByteUnits(Map.alignment), | |
| 12590 | 12590 | Map.entries_offset + new_map_capacity * @sizeOf(Map.Entry), |
| 12591 | 12591 | ); |
| 12592 | 12592 | const new_map: Map = .{ .entries = @ptrCast(new_map_buf[Map.entries_offset..].ptr) }; |
src/Package/Fetch.zig+1-1| ... | ... | @@ -640,7 +640,7 @@ fn loadManifest(f: *Fetch, pkg_root: Cache.Path) RunError!void { |
| 640 | 640 | try fs.path.join(arena, &.{ pkg_root.sub_path, Manifest.basename }), |
| 641 | 641 | Manifest.max_bytes, |
| 642 | 642 | null, |
| 643 | 1, | |
| 643 | .@"1", | |
| 644 | 644 | 0, |
| 645 | 645 | ) catch |err| switch (err) { |
| 646 | 646 | error.FileNotFound => return, |
src/main.zig+1-1| ... | ... | @@ -7510,7 +7510,7 @@ fn loadManifest( |
| 7510 | 7510 | Package.Manifest.basename, |
| 7511 | 7511 | Package.Manifest.max_bytes, |
| 7512 | 7512 | null, |
| 7513 | 1, | |
| 7513 | .@"1", | |
| 7514 | 7514 | 0, |
| 7515 | 7515 | ) catch |err| switch (err) { |
| 7516 | 7516 | error.FileNotFound => { |
test/src/Cases.zig+1-1| ... | ... | @@ -358,7 +358,7 @@ fn addFromDirInner( |
| 358 | 358 | current_file.* = filename; |
| 359 | 359 | |
| 360 | 360 | const max_file_size = 10 * 1024 * 1024; |
| 361 | const src = try iterable_dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, 1, 0); | |
| 361 | const src = try iterable_dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, .@"1", 0); | |
| 362 | 362 | |
| 363 | 363 | // Parse the manifest |
| 364 | 364 | var manifest = try TestManifest.parse(ctx.arena, src); |