authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-18 11:31:23-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:10-08:00
log446c145ca86b014d6743f5666e9ee1d671b56045
tree28b3754371c40a106896916e7e01a5401d9148aa
parenta2416c685a83788780fec1c379008a2d795f7bd2

std.Io.Threaded: fix compilation errors on posix


2 files changed, 12 insertions(+), 7 deletions(-)

lib/std/Io/Dir.zig+10-5
...@@ -101,10 +101,8 @@ pub const Reader = struct {...@@ -101,10 +101,8 @@ pub const Reader = struct {
101 /// Fill position of `buffer`.101 /// Fill position of `buffer`.
102 end: usize,102 end: usize,
103103
104 pub const min_buffer_len = switch (native_os) {104 /// A length for `buffer` that allows all implementations to function.
105 .windows => std.mem.alignForward(usize, max_name_bytes, @alignOf(usize)),105 pub const min_buffer_len = std.mem.alignForward(usize, max_name_bytes, @alignOf(usize));
106 else => 32, // TODO: what is this based on?
107 };
108106
109 pub const State = enum {107 pub const State = enum {
110 /// Indicates the next call to `read` should rewind and start over the108 /// Indicates the next call to `read` should rewind and start over the
...@@ -120,6 +118,7 @@ pub const Reader = struct {...@@ -120,6 +118,7 @@ pub const Reader = struct {
120 SystemResources,118 SystemResources,
121 } || Io.UnexpectedError || Io.Cancelable;119 } || Io.UnexpectedError || Io.Cancelable;
122120
121 /// Asserts that `buffer` has length at least `min_buffer_len`.
123 pub fn init(dir: Dir, buffer: []align(@alignOf(usize)) u8) Reader {122 pub fn init(dir: Dir, buffer: []align(@alignOf(usize)) u8) Reader {
124 assert(buffer.len >= min_buffer_len);123 assert(buffer.len >= min_buffer_len);
125 return .{124 return .{
...@@ -164,7 +163,13 @@ pub const Reader = struct {...@@ -164,7 +163,13 @@ pub const Reader = struct {
164/// see `Walker`.163/// see `Walker`.
165pub const Iterator = struct {164pub const Iterator = struct {
166 reader: Reader,165 reader: Reader,
167 reader_buffer: [2048]u8 align(@alignOf(usize)),166 reader_buffer: [reader_buffer_len]u8 align(@alignOf(usize)),
167
168 pub const reader_buffer_len = 2048;
169
170 comptime {
171 assert(reader_buffer_len >= Reader.min_buffer_len);
172 }
168173
169 pub const Error = Reader.Error;174 pub const Error = Reader.Error;
170175
lib/std/Io/Threaded.zig+2-2
...@@ -1621,7 +1621,7 @@ fn dirMakePath(...@@ -1621,7 +1621,7 @@ fn dirMakePath(
1621 // stat the file and return an error if it's not a directory1621 // stat the file and return an error if it's not a directory
1622 // this is important because otherwise a dangling symlink1622 // this is important because otherwise a dangling symlink
1623 // could cause an infinite loop1623 // could cause an infinite loop
1624 const fstat = dirStatFile(t, dir, component.path, .{});1624 const fstat = try dirStatFile(t, dir, component.path, .{});
1625 if (fstat.kind != .directory) return error.NotDir;1625 if (fstat.kind != .directory) return error.NotDir;
1626 },1626 },
1627 error.FileNotFound => |e| {1627 error.FileNotFound => |e| {
...@@ -3796,7 +3796,7 @@ fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D...@@ -3796,7 +3796,7 @@ fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D
3796 // the remaining unprocessed entries, then backtrack and return what we have so far.3796 // the remaining unprocessed entries, then backtrack and return what we have so far.
3797 if (name_index + std.unicode.calcWtf8Len(name_wtf16le) > unreserved_start + dr.index) {3797 if (name_index + std.unicode.calcWtf8Len(name_wtf16le) > unreserved_start + dr.index) {
3798 // We should always be able to fit at least one entry into the buffer no matter what3798 // We should always be able to fit at least one entry into the buffer no matter what
3799 std.debug.assert(buffer_index != 0);3799 assert(buffer_index != 0);
3800 dr.index = backtrack_index;3800 dr.index = backtrack_index;
3801 break;3801 break;
3802 }3802 }