| author | |
| committer | |
| log | ef14c732455dc089b56aab7392584c4fa8bc2c2d |
| tree | 8d531f6490b8e1915b0f53770d8a8b721d5958ed |
| parent | 0096c0806c0f939140ef61216d967b00e571018c |
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 | 1821 | stdout_bytes = try poller.toOwnedSlice(.stdout); |
| 1822 | 1822 | stderr_bytes = try poller.toOwnedSlice(.stderr); |
| 1823 | 1823 | } else { |
| 1824 | var small_buffer: [1]u8 = undefined; | |
| 1825 | var stdout_reader = stdout.readerStreaming(&small_buffer); | |
| 1824 | var stdout_reader = stdout.readerStreaming(&.{}); | |
| 1826 | 1825 | stdout_bytes = stdout_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) { |
| 1827 | 1826 | error.OutOfMemory => return error.OutOfMemory, |
| 1828 | 1827 | error.ReadFailed => return stdout_reader.err.?, |
| ... | ... | @@ -1830,8 +1829,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult { |
| 1830 | 1829 | }; |
| 1831 | 1830 | } |
| 1832 | 1831 | } 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(&.{}); | |
| 1835 | 1833 | stderr_bytes = stderr_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) { |
| 1836 | 1834 | error.OutOfMemory => return error.OutOfMemory, |
| 1837 | 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 | 283 | /// such case, the next byte that would be read will be the first one to exceed |
| 284 | 284 | /// `limit`, and all preceeding bytes have been discarded. |
| 285 | 285 | /// |
| 286 | /// Asserts `buffer` has nonzero capacity. | |
| 287 | /// | |
| 288 | 286 | /// See also: |
| 289 | 287 | /// * `appendRemaining` |
| 290 | 288 | pub 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 | 1194 | }; |
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 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 | 1201 | return .{ |
| 1199 | 1202 | .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, | |
| 1202 | 1207 | }; |
| 1203 | 1208 | } |
| 1204 | 1209 | |
| ... | ... | @@ -1578,14 +1583,21 @@ pub const Writer = struct { |
| 1578 | 1583 | const max_buffers_len = 16; |
| 1579 | 1584 | |
| 1580 | 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 | } |
| 1583 | 1592 | |
| 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 | 1597 | return .{ |
| 1586 | 1598 | .file = file, |
| 1587 | 1599 | .interface = initInterface(buffer), |
| 1588 | .mode = init_mode, | |
| 1600 | .mode = .streaming, | |
| 1589 | 1601 | }; |
| 1590 | 1602 | } |
| 1591 | 1603 | |
| ... | ... | @@ -2092,15 +2104,10 @@ pub fn reader(file: File, buffer: []u8) Reader { |
| 2092 | 2104 | } |
| 2093 | 2105 | |
| 2094 | 2106 | /// 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. | |
| 2097 | 2109 | pub 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); | |
| 2104 | 2111 | } |
| 2105 | 2112 | |
| 2106 | 2113 | /// Defaults to positional reading; falls back to streaming. |
| ... | ... | @@ -2112,10 +2119,10 @@ pub fn writer(file: File, buffer: []u8) Writer { |
| 2112 | 2119 | } |
| 2113 | 2120 | |
| 2114 | 2121 | /// 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. | |
| 2117 | 2124 | pub fn writerStreaming(file: File, buffer: []u8) Writer { |
| 2118 | return .initMode(file, buffer, .streaming); | |
| 2125 | return .initStreaming(file, buffer); | |
| 2119 | 2126 | } |
| 2120 | 2127 | |
| 2121 | 2128 | const range_off: windows.LARGE_INTEGER = 0; |
lib/std/net.zig+1-1| ... | ... | @@ -2233,7 +2233,7 @@ pub const Stream = struct { |
| 2233 | 2233 | }, |
| 2234 | 2234 | .buffer = buffer, |
| 2235 | 2235 | }, |
| 2236 | .file_writer = .initMode(.{ .handle = stream.handle }, &.{}, .streaming), | |
| 2236 | .file_writer = .initStreaming(.{ .handle = stream.handle }, &.{}), | |
| 2237 | 2237 | }; |
| 2238 | 2238 | } |
| 2239 | 2239 |
lib/std/process/Child.zig+2-2| ... | ... | @@ -1003,14 +1003,14 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { |
| 1003 | 1003 | |
| 1004 | 1004 | fn writeIntFd(fd: i32, value: ErrInt) !void { |
| 1005 | 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 | 1007 | fw.interface.writeInt(u64, value, .little) catch unreachable; |
| 1008 | 1008 | fw.interface.flush() catch return error.SystemResources; |
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | fn readIntFd(fd: i32) !ErrInt { |
| 1012 | 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 | 1014 | return @intCast(fr.interface.takeInt(u64, .little) catch return error.SystemResources); |
| 1015 | 1015 | } |
| 1016 | 1016 |
src/Compilation.zig+2-1| ... | ... | @@ -6278,7 +6278,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr |
| 6278 | 6278 | |
| 6279 | 6279 | try child.spawn(); |
| 6280 | 6280 | |
| 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))); | |
| 6282 | 6283 | |
| 6283 | 6284 | const term = child.wait() catch |err| { |
| 6284 | 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 | 1632 | |
| 1633 | 1633 | fn dumpHashInfo(all_files: []const *const HashedFile) !void { |
| 1634 | 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 | 1636 | const w = &stdout_writer.interface; |
| 1637 | 1637 | for (all_files) |hashed_file| { |
| 1638 | 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 | 27 | b.default_step = test_step; |
| 28 | 28 | |
| 29 | 29 | 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." }); | |
| 34 | 31 | test_step.dependOn(&test_run.step); |
| 35 | 32 | } |
| 36 | 33 |