diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-03-10 15:27:45 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-03-10 15:32:32 -0400 |
| commit | ba0e3be5cfa2f60f2f9d2a4eb319408f972796c2 (patch) | |
| tree | da35c17d0067a463b521163f624f3d109b8050f4 /lib/std/child_process.zig | |
| parent | 1ad831a0ef22f354d4e1dd5073456a0683249846 (diff) | |
| download | zig-ba0e3be5cfa2f60f2f9d2a4eb319408f972796c2.tar.gz zig-ba0e3be5cfa2f60f2f9d2a4eb319408f972796c2.zip | |
(breaking) rework stream abstractions
The main goal here is to make the function pointers comptime, so that we
don't have to do the crazy stuff with async function frames.
Since InStream, OutStream, and SeekableStream are already generic
across error sets, it's not really worse to make them generic across the
vtable as well.
See #764 for the open issue acknowledging that using generics for these
abstractions is a design flaw.
See #130 for the efforts to make these abstractions non-generic.
This commit also changes the OutStream API so that `write` returns
number of bytes written, and `writeAll` is the one that loops until the
whole buffer is written.
Diffstat (limited to 'lib/std/child_process.zig')
| -rw-r--r-- | lib/std/child_process.zig | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 4f5fc2b496..95619384b1 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -221,9 +221,9 @@ pub const ChildProcess = struct { var stderr_file_in_stream = child.stderr.?.inStream(); // TODO need to poll to read these streams to prevent a deadlock (or rely on evented I/O). - const stdout = try stdout_file_in_stream.stream.readAllAlloc(args.allocator, args.max_output_bytes); + const stdout = try stdout_file_in_stream.readAllAlloc(args.allocator, args.max_output_bytes); errdefer args.allocator.free(stdout); - const stderr = try stderr_file_in_stream.stream.readAllAlloc(args.allocator, args.max_output_bytes); + const stderr = try stderr_file_in_stream.readAllAlloc(args.allocator, args.max_output_bytes); errdefer args.allocator.free(stderr); return ExecResult{ @@ -857,8 +857,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void { .io_mode = .blocking, .async_block_allowed = File.async_block_allowed_yes, }; - const stream = &file.outStream().stream; - stream.writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources; + file.outStream().writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources; } fn readIntFd(fd: i32) !ErrInt { @@ -867,8 +866,7 @@ fn readIntFd(fd: i32) !ErrInt { .io_mode = .blocking, .async_block_allowed = File.async_block_allowed_yes, }; - const stream = &file.inStream().stream; - return @intCast(ErrInt, stream.readIntNative(u64) catch return error.SystemResources); + return @intCast(ErrInt, file.inStream().readIntNative(u64) catch return error.SystemResources); } /// Caller must free result. |
