Compilation: remove last instance of deprecatedReader
This also makes initStreaming preemptively disable file size checking.
This commit is contained in:
@@ -1821,8 +1821,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {
|
||||
stdout_bytes = try poller.toOwnedSlice(.stdout);
|
||||
stderr_bytes = try poller.toOwnedSlice(.stderr);
|
||||
} else {
|
||||
var small_buffer: [1]u8 = undefined;
|
||||
var stdout_reader = stdout.readerStreaming(&small_buffer);
|
||||
var stdout_reader = stdout.readerStreaming(&.{});
|
||||
stdout_bytes = stdout_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.ReadFailed => return stdout_reader.err.?,
|
||||
@@ -1830,8 +1829,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {
|
||||
};
|
||||
}
|
||||
} else if (child.stderr) |stderr| {
|
||||
var small_buffer: [1]u8 = undefined;
|
||||
var stderr_reader = stderr.readerStreaming(&small_buffer);
|
||||
var stderr_reader = stderr.readerStreaming(&.{});
|
||||
stderr_bytes = stderr_reader.interface.allocRemaining(arena, run.stdio_limit) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.ReadFailed => return stderr_reader.err.?,
|
||||
|
||||
@@ -283,8 +283,6 @@ pub const LimitedAllocError = Allocator.Error || ShortError || error{StreamTooLo
|
||||
/// such case, the next byte that would be read will be the first one to exceed
|
||||
/// `limit`, and all preceeding bytes have been discarded.
|
||||
///
|
||||
/// Asserts `buffer` has nonzero capacity.
|
||||
///
|
||||
/// See also:
|
||||
/// * `appendRemaining`
|
||||
pub fn allocRemaining(r: *Reader, gpa: Allocator, limit: Limit) LimitedAllocError![]u8 {
|
||||
|
||||
@@ -1194,11 +1194,16 @@ pub const Reader = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn initMode(file: File, buffer: []u8, init_mode: Reader.Mode) Reader {
|
||||
/// Positional is more threadsafe, since the global seek position is not
|
||||
/// affected, but when such syscalls are not available, preemptively
|
||||
/// initializing in streaming mode skips a failed syscall.
|
||||
pub fn initStreaming(file: File, buffer: []u8) Reader {
|
||||
return .{
|
||||
.file = file,
|
||||
.interface = initInterface(buffer),
|
||||
.mode = init_mode,
|
||||
.interface = Reader.initInterface(buffer),
|
||||
.mode = .streaming,
|
||||
.seek_err = error.Unseekable,
|
||||
.size_err = error.Streaming,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1578,14 +1583,21 @@ pub const Writer = struct {
|
||||
const max_buffers_len = 16;
|
||||
|
||||
pub fn init(file: File, buffer: []u8) Writer {
|
||||
return initMode(file, buffer, .positional);
|
||||
}
|
||||
|
||||
pub fn initMode(file: File, buffer: []u8, init_mode: Writer.Mode) Writer {
|
||||
return .{
|
||||
.file = file,
|
||||
.interface = initInterface(buffer),
|
||||
.mode = init_mode,
|
||||
.mode = .positional,
|
||||
};
|
||||
}
|
||||
|
||||
/// Positional is more threadsafe, since the global seek position is not
|
||||
/// affected, but when such syscalls are not available, preemptively
|
||||
/// initializing in streaming mode will skip a failed syscall.
|
||||
pub fn initStreaming(file: File, buffer: []u8) Writer {
|
||||
return .{
|
||||
.file = file,
|
||||
.interface = initInterface(buffer),
|
||||
.mode = .streaming,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2092,15 +2104,10 @@ pub fn reader(file: File, buffer: []u8) Reader {
|
||||
}
|
||||
|
||||
/// Positional is more threadsafe, since the global seek position is not
|
||||
/// affected, but when such syscalls are not available, preemptively choosing
|
||||
/// `Reader.Mode.streaming` will skip a failed syscall.
|
||||
/// affected, but when such syscalls are not available, preemptively
|
||||
/// initializing in streaming mode skips a failed syscall.
|
||||
pub fn readerStreaming(file: File, buffer: []u8) Reader {
|
||||
return .{
|
||||
.file = file,
|
||||
.interface = Reader.initInterface(buffer),
|
||||
.mode = .streaming,
|
||||
.seek_err = error.Unseekable,
|
||||
};
|
||||
return .initStreaming(file, buffer);
|
||||
}
|
||||
|
||||
/// Defaults to positional reading; falls back to streaming.
|
||||
@@ -2112,10 +2119,10 @@ pub fn writer(file: File, buffer: []u8) Writer {
|
||||
}
|
||||
|
||||
/// Positional is more threadsafe, since the global seek position is not
|
||||
/// affected, but when such syscalls are not available, preemptively choosing
|
||||
/// `Writer.Mode.streaming` will skip a failed syscall.
|
||||
/// affected, but when such syscalls are not available, preemptively
|
||||
/// initializing in streaming mode will skip a failed syscall.
|
||||
pub fn writerStreaming(file: File, buffer: []u8) Writer {
|
||||
return .initMode(file, buffer, .streaming);
|
||||
return .initStreaming(file, buffer);
|
||||
}
|
||||
|
||||
const range_off: windows.LARGE_INTEGER = 0;
|
||||
|
||||
@@ -2233,7 +2233,7 @@ pub const Stream = struct {
|
||||
},
|
||||
.buffer = buffer,
|
||||
},
|
||||
.file_writer = .initMode(.{ .handle = stream.handle }, &.{}, .streaming),
|
||||
.file_writer = .initStreaming(.{ .handle = stream.handle }, &.{}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1003,14 +1003,14 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
|
||||
|
||||
fn writeIntFd(fd: i32, value: ErrInt) !void {
|
||||
var buffer: [8]u8 = undefined;
|
||||
var fw: std.fs.File.Writer = .initMode(.{ .handle = fd }, &buffer, .streaming);
|
||||
var fw: std.fs.File.Writer = .initStreaming(.{ .handle = fd }, &buffer);
|
||||
fw.interface.writeInt(u64, value, .little) catch unreachable;
|
||||
fw.interface.flush() catch return error.SystemResources;
|
||||
}
|
||||
|
||||
fn readIntFd(fd: i32) !ErrInt {
|
||||
var buffer: [8]u8 = undefined;
|
||||
var fr: std.fs.File.Reader = .initMode(.{ .handle = fd }, &buffer, .streaming);
|
||||
var fr: std.fs.File.Reader = .initStreaming(.{ .handle = fd }, &buffer);
|
||||
return @intCast(fr.interface.takeInt(u64, .little) catch return error.SystemResources);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user