authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-14 20:32:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-16 14:46:20-07:00
logef14c732455dc089b56aab7392584c4fa8bc2c2d
tree8d531f6490b8e1915b0f53770d8a8b721d5958ed
parent0096c0806c0f939140ef61216d967b00e571018c

Compilation: remove last instance of deprecatedReader

This also makes initStreaming preemptively disable file size checking.

8 files changed, 33 insertions(+), 32 deletions(-)

lib/std/Build/Step/Run.zig+2-4
...@@ -1821,8 +1821,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {...@@ -1821,8 +1821,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {
1821 stdout_bytes = try poller.toOwnedSlice(.stdout);1821 stdout_bytes = try poller.toOwnedSlice(.stdout);
1822 stderr_bytes = try poller.toOwnedSlice(.stderr);1822 stderr_bytes = try poller.toOwnedSlice(.stderr);
1823 } else {1823 } else {
1824 var small_buffer: [1]u8 = undefined;1824 var stdout_reader = stdout.readerStreaming(&.{});
1825 var stdout_reader = stdout.readerStreaming(&small_buffer);
1826 stdout_bytes = stdout_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) {1825 stdout_bytes = stdout_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) {
1827 error.OutOfMemory => return error.OutOfMemory,1826 error.OutOfMemory => return error.OutOfMemory,
1828 error.ReadFailed => return stdout_reader.err.?,1827 error.ReadFailed => return stdout_reader.err.?,
...@@ -1830,8 +1829,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {...@@ -1830,8 +1829,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {
1830 };1829 };
1831 }1830 }
1832 } else if (child.stderr) |stderr| {1831 } else if (child.stderr) |stderr| {
1833 var small_buffer: [1]u8 = undefined;1832 var stderr_reader = stderr.readerStreaming(&.{});
1834 var stderr_reader = stderr.readerStreaming(&small_buffer);
1835 stderr_bytes = stderr_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) {1833 stderr_bytes = stderr_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) {
1836 error.OutOfMemory => return error.OutOfMemory,1834 error.OutOfMemory => return error.OutOfMemory,
1837 error.ReadFailed => return stderr_reader.err.?,1835 error.ReadFailed => return stderr_reader.err.?,
lib/std/Io/Reader.zig-2
...@@ -283,8 +283,6 @@ pub const LimitedAllocError = Allocator.Error || ShortError || error{StreamTooLo...@@ -283,8 +283,6 @@ pub const LimitedAllocError = Allocator.Error || ShortError || error{StreamTooLo
283/// such case, the next byte that would be read will be the first one to exceed283/// such case, the next byte that would be read will be the first one to exceed
284/// `limit`, and all preceeding bytes have been discarded.284/// `limit`, and all preceeding bytes have been discarded.
285///285///
286/// Asserts `buffer` has nonzero capacity.
287///
288/// See also:286/// See also:
289/// * `appendRemaining`287/// * `appendRemaining`
290pub fn allocRemaining(r: *Reader, gpa: Allocator, limit: Limit) LimitedAllocError![]u8 {288pub fn allocRemaining(r: *Reader, gpa: Allocator, limit: Limit) LimitedAllocError![]u8 {
lib/std/fs/File.zig+24-17
...@@ -1194,11 +1194,16 @@ pub const Reader = struct {...@@ -1194,11 +1194,16 @@ pub const Reader = struct {
1194 };1194 };
1195 }1195 }
11961196
1197 pub fn initMode(file: File, buffer: []u8, init_mode: Reader.Mode) Reader {1197 /// Positional is more threadsafe, since the global seek position is not
1198 /// affected, but when such syscalls are not available, preemptively
1199 /// initializing in streaming mode skips a failed syscall.
1200 pub fn initStreaming(file: File, buffer: []u8) Reader {
1198 return .{1201 return .{
1199 .file = file,1202 .file = file,
1200 .interface = initInterface(buffer),1203 .interface = Reader.initInterface(buffer),
1201 .mode = init_mode,1204 .mode = .streaming,
1205 .seek_err = error.Unseekable,
1206 .size_err = error.Streaming,
1202 };1207 };
1203 }1208 }
12041209
...@@ -1578,14 +1583,21 @@ pub const Writer = struct {...@@ -1578,14 +1583,21 @@ pub const Writer = struct {
1578 const max_buffers_len = 16;1583 const max_buffers_len = 16;
15791584
1580 pub fn init(file: File, buffer: []u8) Writer {1585 pub fn init(file: File, buffer: []u8) Writer {
1581 return initMode(file, buffer, .positional);1586 return .{
1587 .file = file,
1588 .interface = initInterface(buffer),
1589 .mode = .positional,
1590 };
1582 }1591 }
15831592
1584 pub fn initMode(file: File, buffer: []u8, init_mode: Writer.Mode) Writer {1593 /// Positional is more threadsafe, since the global seek position is not
1594 /// affected, but when such syscalls are not available, preemptively
1595 /// initializing in streaming mode will skip a failed syscall.
1596 pub fn initStreaming(file: File, buffer: []u8) Writer {
1585 return .{1597 return .{
1586 .file = file,1598 .file = file,
1587 .interface = initInterface(buffer),1599 .interface = initInterface(buffer),
1588 .mode = init_mode,1600 .mode = .streaming,
1589 };1601 };
1590 }1602 }
15911603
...@@ -2092,15 +2104,10 @@ pub fn reader(file: File, buffer: []u8) Reader {...@@ -2092,15 +2104,10 @@ pub fn reader(file: File, buffer: []u8) Reader {
2092}2104}
20932105
2094/// Positional is more threadsafe, since the global seek position is not2106/// Positional is more threadsafe, since the global seek position is not
2095/// affected, but when such syscalls are not available, preemptively choosing2107/// affected, but when such syscalls are not available, preemptively
2096/// `Reader.Mode.streaming` will skip a failed syscall.2108/// initializing in streaming mode skips a failed syscall.
2097pub fn readerStreaming(file: File, buffer: []u8) Reader {2109pub fn readerStreaming(file: File, buffer: []u8) Reader {
2098 return .{2110 return .initStreaming(file, buffer);
2099 .file = file,
2100 .interface = Reader.initInterface(buffer),
2101 .mode = .streaming,
2102 .seek_err = error.Unseekable,
2103 };
2104}2111}
21052112
2106/// Defaults to positional reading; falls back to streaming.2113/// Defaults to positional reading; falls back to streaming.
...@@ -2112,10 +2119,10 @@ pub fn writer(file: File, buffer: []u8) Writer {...@@ -2112,10 +2119,10 @@ pub fn writer(file: File, buffer: []u8) Writer {
2112}2119}
21132120
2114/// Positional is more threadsafe, since the global seek position is not2121/// Positional is more threadsafe, since the global seek position is not
2115/// affected, but when such syscalls are not available, preemptively choosing2122/// affected, but when such syscalls are not available, preemptively
2116/// `Writer.Mode.streaming` will skip a failed syscall.2123/// initializing in streaming mode will skip a failed syscall.
2117pub fn writerStreaming(file: File, buffer: []u8) Writer {2124pub fn writerStreaming(file: File, buffer: []u8) Writer {
2118 return .initMode(file, buffer, .streaming);2125 return .initStreaming(file, buffer);
2119}2126}
21202127
2121const range_off: windows.LARGE_INTEGER = 0;2128const range_off: windows.LARGE_INTEGER = 0;
lib/std/net.zig+1-1
...@@ -2233,7 +2233,7 @@ pub const Stream = struct {...@@ -2233,7 +2233,7 @@ pub const Stream = struct {
2233 },2233 },
2234 .buffer = buffer,2234 .buffer = buffer,
2235 },2235 },
2236 .file_writer = .initMode(.{ .handle = stream.handle }, &.{}, .streaming),2236 .file_writer = .initStreaming(.{ .handle = stream.handle }, &.{}),
2237 };2237 };
2238 }2238 }
22392239
lib/std/process/Child.zig+2-2
...@@ -1003,14 +1003,14 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {...@@ -1003,14 +1003,14 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
10031003
1004fn writeIntFd(fd: i32, value: ErrInt) !void {1004fn writeIntFd(fd: i32, value: ErrInt) !void {
1005 var buffer: [8]u8 = undefined;1005 var buffer: [8]u8 = undefined;
1006 var fw: std.fs.File.Writer = .initMode(.{ .handle = fd }, &buffer, .streaming);1006 var fw: std.fs.File.Writer = .initStreaming(.{ .handle = fd }, &buffer);
1007 fw.interface.writeInt(u64, value, .little) catch unreachable;1007 fw.interface.writeInt(u64, value, .little) catch unreachable;
1008 fw.interface.flush() catch return error.SystemResources;1008 fw.interface.flush() catch return error.SystemResources;
1009}1009}
10101010
1011fn readIntFd(fd: i32) !ErrInt {1011fn readIntFd(fd: i32) !ErrInt {
1012 var buffer: [8]u8 = undefined;1012 var buffer: [8]u8 = undefined;
1013 var fr: std.fs.File.Reader = .initMode(.{ .handle = fd }, &buffer, .streaming);1013 var fr: std.fs.File.Reader = .initStreaming(.{ .handle = fd }, &buffer);
1014 return @intCast(fr.interface.takeInt(u64, .little) catch return error.SystemResources);1014 return @intCast(fr.interface.takeInt(u64, .little) catch return error.SystemResources);
1015}1015}
10161016
src/Compilation.zig+2-1
...@@ -6278,7 +6278,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr...@@ -6278,7 +6278,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
62786278
6279 try child.spawn();6279 try child.spawn();
62806280
6281 const stderr = try child.stderr.?.deprecatedReader().readAllAlloc(arena, std.math.maxInt(usize));6281 var stderr_reader = child.stderr.?.readerStreaming(&.{});
6282 const stderr = try stderr_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32)));
62826283
6283 const term = child.wait() catch |err| {6284 const term = child.wait() catch |err| {
6284 return comp.failCObj(c_object, "failed to spawn zig clang {s}: {s}", .{ argv.items[0], @errorName(err) });6285 return comp.failCObj(c_object, "failed to spawn zig clang {s}: {s}", .{ argv.items[0], @errorName(err) });
src/Package/Fetch.zig+1-1
...@@ -1632,7 +1632,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute...@@ -1632,7 +1632,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
16321632
1633fn dumpHashInfo(all_files: []const *const HashedFile) !void {1633fn dumpHashInfo(all_files: []const *const HashedFile) !void {
1634 var stdout_buffer: [1024]u8 = undefined;1634 var stdout_buffer: [1024]u8 = undefined;
1635 var stdout_writer: fs.File.Writer = .initMode(.stdout(), &stdout_buffer, .streaming);1635 var stdout_writer: fs.File.Writer = .initStreaming(.stdout(), &stdout_buffer);
1636 const w = &stdout_writer.interface;1636 const w = &stdout_writer.interface;
1637 for (all_files) |hashed_file| {1637 for (all_files) |hashed_file| {
1638 try w.print("{t}: {x}: {s}\n", .{ hashed_file.kind, &hashed_file.hash, hashed_file.normalized_path });1638 try w.print("{t}: {x}: {s}\n", .{ hashed_file.kind, &hashed_file.hash, hashed_file.normalized_path });
test/standalone/test_obj_link_run/build.zig+1-4
...@@ -27,10 +27,7 @@ pub fn build(b: *std.Build) void {...@@ -27,10 +27,7 @@ pub fn build(b: *std.Build) void {
27 b.default_step = test_step;27 b.default_step = test_step;
2828
29 const test_run = b.addRunArtifact(test_exe);29 const test_run = b.addRunArtifact(test_exe);
30 if (!is_windows) {30 test_run.addCheck(.{ .expect_stderr_match = "All 3 tests passed." });
31 // https://github.com/ziglang/zig/issues/24867
32 test_run.addCheck(.{ .expect_stderr_match = "All 3 tests passed." });
33 }
34 test_step.dependOn(&test_run.step);31 test_step.dependOn(&test_run.step);
35}32}
3633