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 {
18211821 stdout_bytes = try poller.toOwnedSlice(.stdout);
18221822 stderr_bytes = try poller.toOwnedSlice(.stderr);
18231823 } else {
1824 var small_buffer: [1]u8 = undefined;
1825 var stdout_reader = stdout.readerStreaming(&small_buffer);
1824 var stdout_reader = stdout.readerStreaming(&.{});
18261825 stdout_bytes = stdout_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) {
18271826 error.OutOfMemory => return error.OutOfMemory,
18281827 error.ReadFailed => return stdout_reader.err.?,
......@@ -1830,8 +1829,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {
18301829 };
18311830 }
18321831 } else if (child.stderr) |stderr| {
1833 var small_buffer: [1]u8 = undefined;
1834 var stderr_reader = stderr.readerStreaming(&small_buffer);
1832 var stderr_reader = stderr.readerStreaming(&.{});
18351833 stderr_bytes = stderr_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) {
18361834 error.OutOfMemory => return error.OutOfMemory,
18371835 error.ReadFailed => return stderr_reader.err.?,
lib/std/Io/Reader.zig-2
......@@ -283,8 +283,6 @@ pub const LimitedAllocError = Allocator.Error || ShortError || error{StreamTooLo
283283/// such case, the next byte that would be read will be the first one to exceed
284284/// `limit`, and all preceeding bytes have been discarded.
285285///
286/// Asserts `buffer` has nonzero capacity.
287///
288286/// See also:
289287/// * `appendRemaining`
290288pub 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 {
11941194 };
11951195 }
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 {
11981201 return .{
11991202 .file = file,
1200 .interface = initInterface(buffer),
1201 .mode = init_mode,
1203 .interface = Reader.initInterface(buffer),
1204 .mode = .streaming,
1205 .seek_err = error.Unseekable,
1206 .size_err = error.Streaming,
12021207 };
12031208 }
12041209
......@@ -1578,14 +1583,21 @@ pub const Writer = struct {
15781583 const max_buffers_len = 16;
15791584
15801585 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 };
15821591 }
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 {
15851597 return .{
15861598 .file = file,
15871599 .interface = initInterface(buffer),
1588 .mode = init_mode,
1600 .mode = .streaming,
15891601 };
15901602 }
15911603
......@@ -2092,15 +2104,10 @@ pub fn reader(file: File, buffer: []u8) Reader {
20922104}
20932105
20942106/// Positional is more threadsafe, since the global seek position is not
2095/// affected, but when such syscalls are not available, preemptively choosing
2096/// `Reader.Mode.streaming` will skip a failed syscall.
2107/// affected, but when such syscalls are not available, preemptively
2108/// initializing in streaming mode skips a failed syscall.
20972109pub fn readerStreaming(file: File, buffer: []u8) Reader {
2098 return .{
2099 .file = file,
2100 .interface = Reader.initInterface(buffer),
2101 .mode = .streaming,
2102 .seek_err = error.Unseekable,
2103 };
2110 return .initStreaming(file, buffer);
21042111}
21052112
21062113/// Defaults to positional reading; falls back to streaming.
......@@ -2112,10 +2119,10 @@ pub fn writer(file: File, buffer: []u8) Writer {
21122119}
21132120
21142121/// Positional is more threadsafe, since the global seek position is not
2115/// affected, but when such syscalls are not available, preemptively choosing
2116/// `Writer.Mode.streaming` will skip a failed syscall.
2122/// affected, but when such syscalls are not available, preemptively
2123/// initializing in streaming mode will skip a failed syscall.
21172124pub fn writerStreaming(file: File, buffer: []u8) Writer {
2118 return .initMode(file, buffer, .streaming);
2125 return .initStreaming(file, buffer);
21192126}
21202127
21212128const range_off: windows.LARGE_INTEGER = 0;
lib/std/net.zig+1-1
......@@ -2233,7 +2233,7 @@ pub const Stream = struct {
22332233 },
22342234 .buffer = buffer,
22352235 },
2236 .file_writer = .initMode(.{ .handle = stream.handle }, &.{}, .streaming),
2236 .file_writer = .initStreaming(.{ .handle = stream.handle }, &.{}),
22372237 };
22382238 }
22392239
lib/std/process/Child.zig+2-2
......@@ -1003,14 +1003,14 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
10031003
10041004fn writeIntFd(fd: i32, value: ErrInt) !void {
10051005 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);
10071007 fw.interface.writeInt(u64, value, .little) catch unreachable;
10081008 fw.interface.flush() catch return error.SystemResources;
10091009}
10101010
10111011fn readIntFd(fd: i32) !ErrInt {
10121012 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);
10141014 return @intCast(fr.interface.takeInt(u64, .little) catch return error.SystemResources);
10151015}
10161016
src/Compilation.zig+2-1
......@@ -6278,7 +6278,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
62786278
62796279 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
62836284 const term = child.wait() catch |err| {
62846285 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
16321632
16331633fn dumpHashInfo(all_files: []const *const HashedFile) !void {
16341634 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);
16361636 const w = &stdout_writer.interface;
16371637 for (all_files) |hashed_file| {
16381638 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 {
2727 b.default_step = test_step;
2828
2929 const test_run = b.addRunArtifact(test_exe);
30 if (!is_windows) {
31 // https://github.com/ziglang/zig/issues/24867
32 test_run.addCheck(.{ .expect_stderr_match = "All 3 tests passed." });
33 }
30 test_run.addCheck(.{ .expect_stderr_match = "All 3 tests passed." });
3431 test_step.dependOn(&test_run.step);
3532}
3633