authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-10 20:22:30-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-10 20:22:30-04:00
log2bff0dda795cd84e4da59652736b7cfa7e1c964c
tree4b3bc5f10fefd1c3e4fedccc872ed99d9d87a6e7
parent9abee660dce3b43b9ac3b8260fbf269532d6c7f5
signaturelock-open Commit is signed but in an unrecognized format.

fix regressions found by test suite


11 files changed, 103 insertions(+), 128 deletions(-)

doc/docgen.zig+44-51
...@@ -40,12 +40,9 @@ pub fn main() !void {...@@ -40,12 +40,9 @@ pub fn main() !void {
40 var out_file = try fs.cwd().createFile(out_file_name, .{});40 var out_file = try fs.cwd().createFile(out_file_name, .{});
41 defer out_file.close();41 defer out_file.close();
4242
43 var file_in_stream = in_file.inStream();43 const input_file_bytes = try in_file.inStream().readAllAlloc(allocator, max_doc_file_size);
4444
45 const input_file_bytes = try file_in_stream.stream.readAllAlloc(allocator, max_doc_file_size);45 var buffered_out_stream = io.bufferedOutStream(out_file.outStream());
46
47 var file_out_stream = out_file.outStream();
48 var buffered_out_stream = io.BufferedOutStream(fs.File.WriteError).init(&file_out_stream.stream);
4946
50 var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);47 var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);
51 var toc = try genToc(allocator, &tokenizer);48 var toc = try genToc(allocator, &tokenizer);
...@@ -53,7 +50,7 @@ pub fn main() !void {...@@ -53,7 +50,7 @@ pub fn main() !void {
53 try fs.cwd().makePath(tmp_dir_name);50 try fs.cwd().makePath(tmp_dir_name);
54 defer fs.deleteTree(tmp_dir_name) catch {};51 defer fs.deleteTree(tmp_dir_name) catch {};
5552
56 try genHtml(allocator, &tokenizer, &toc, &buffered_out_stream.stream, zig_exe);53 try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.outStream(), zig_exe);
57 try buffered_out_stream.flush();54 try buffered_out_stream.flush();
58}55}
5956
...@@ -327,8 +324,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -327,8 +324,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
327 var toc_buf = try std.Buffer.initSize(allocator, 0);324 var toc_buf = try std.Buffer.initSize(allocator, 0);
328 defer toc_buf.deinit();325 defer toc_buf.deinit();
329326
330 var toc_buf_adapter = io.BufferOutStream.init(&toc_buf);327 var toc = toc_buf.outStream();
331 var toc = &toc_buf_adapter.stream;
332328
333 var nodes = std.ArrayList(Node).init(allocator);329 var nodes = std.ArrayList(Node).init(allocator);
334 defer nodes.deinit();330 defer nodes.deinit();
...@@ -342,7 +338,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -342,7 +338,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
342 if (header_stack_size != 0) {338 if (header_stack_size != 0) {
343 return parseError(tokenizer, token, "unbalanced headers", .{});339 return parseError(tokenizer, token, "unbalanced headers", .{});
344 }340 }
345 try toc.write(" </ul>\n");341 try toc.writeAll(" </ul>\n");
346 break;342 break;
347 },343 },
348 Token.Id.Content => {344 Token.Id.Content => {
...@@ -407,7 +403,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -407,7 +403,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
407 if (last_columns) |n| {403 if (last_columns) |n| {
408 try toc.print("<ul style=\"columns: {}\">\n", .{n});404 try toc.print("<ul style=\"columns: {}\">\n", .{n});
409 } else {405 } else {
410 try toc.write("<ul>\n");406 try toc.writeAll("<ul>\n");
411 }407 }
412 } else {408 } else {
413 last_action = Action.Open;409 last_action = Action.Open;
...@@ -424,9 +420,9 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -424,9 +420,9 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
424420
425 if (last_action == Action.Close) {421 if (last_action == Action.Close) {
426 try toc.writeByteNTimes(' ', 8 + header_stack_size * 4);422 try toc.writeByteNTimes(' ', 8 + header_stack_size * 4);
427 try toc.write("</ul></li>\n");423 try toc.writeAll("</ul></li>\n");
428 } else {424 } else {
429 try toc.write("</li>\n");425 try toc.writeAll("</li>\n");
430 last_action = Action.Close;426 last_action = Action.Close;
431 }427 }
432 } else if (mem.eql(u8, tag_name, "see_also")) {428 } else if (mem.eql(u8, tag_name, "see_also")) {
...@@ -614,8 +610,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {...@@ -614,8 +610,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
614 var buf = try std.Buffer.initSize(allocator, 0);610 var buf = try std.Buffer.initSize(allocator, 0);
615 defer buf.deinit();611 defer buf.deinit();
616612
617 var buf_adapter = io.BufferOutStream.init(&buf);613 const out = buf.outStream();
618 var out = &buf_adapter.stream;
619 for (input) |c| {614 for (input) |c| {
620 switch (c) {615 switch (c) {
621 'a'...'z', 'A'...'Z', '_', '-', '0'...'9' => {616 'a'...'z', 'A'...'Z', '_', '-', '0'...'9' => {
...@@ -634,8 +629,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {...@@ -634,8 +629,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
634 var buf = try std.Buffer.initSize(allocator, 0);629 var buf = try std.Buffer.initSize(allocator, 0);
635 defer buf.deinit();630 defer buf.deinit();
636631
637 var buf_adapter = io.BufferOutStream.init(&buf);632 const out = buf.outStream();
638 var out = &buf_adapter.stream;
639 try writeEscaped(out, input);633 try writeEscaped(out, input);
640 return buf.toOwnedSlice();634 return buf.toOwnedSlice();
641}635}
...@@ -643,10 +637,10 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {...@@ -643,10 +637,10 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
643fn writeEscaped(out: var, input: []const u8) !void {637fn writeEscaped(out: var, input: []const u8) !void {
644 for (input) |c| {638 for (input) |c| {
645 try switch (c) {639 try switch (c) {
646 '&' => out.write("&amp;"),640 '&' => out.writeAll("&amp;"),
647 '<' => out.write("&lt;"),641 '<' => out.writeAll("&lt;"),
648 '>' => out.write("&gt;"),642 '>' => out.writeAll("&gt;"),
649 '"' => out.write("&quot;"),643 '"' => out.writeAll("&quot;"),
650 else => out.writeByte(c),644 else => out.writeByte(c),
651 };645 };
652 }646 }
...@@ -681,8 +675,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {...@@ -681,8 +675,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
681 var buf = try std.Buffer.initSize(allocator, 0);675 var buf = try std.Buffer.initSize(allocator, 0);
682 defer buf.deinit();676 defer buf.deinit();
683677
684 var buf_adapter = io.BufferOutStream.init(&buf);678 var out = buf.outStream();
685 var out = &buf_adapter.stream;
686 var number_start_index: usize = undefined;679 var number_start_index: usize = undefined;
687 var first_number: usize = undefined;680 var first_number: usize = undefined;
688 var second_number: usize = undefined;681 var second_number: usize = undefined;
...@@ -743,7 +736,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {...@@ -743,7 +736,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
743 'm' => {736 'm' => {
744 state = TermState.Start;737 state = TermState.Start;
745 while (open_span_count != 0) : (open_span_count -= 1) {738 while (open_span_count != 0) : (open_span_count -= 1) {
746 try out.write("</span>");739 try out.writeAll("</span>");
747 }740 }
748 if (first_number != 0 or second_number != 0) {741 if (first_number != 0 or second_number != 0) {
749 try out.print("<span class=\"t{}_{}\">", .{ first_number, second_number });742 try out.print("<span class=\"t{}_{}\">", .{ first_number, second_number });
...@@ -774,7 +767,7 @@ fn isType(name: []const u8) bool {...@@ -774,7 +767,7 @@ fn isType(name: []const u8) bool {
774767
775fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Token, raw_src: []const u8) !void {768fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Token, raw_src: []const u8) !void {
776 const src = mem.trim(u8, raw_src, " \n");769 const src = mem.trim(u8, raw_src, " \n");
777 try out.write("<code class=\"zig\">");770 try out.writeAll("<code class=\"zig\">");
778 var tokenizer = std.zig.Tokenizer.init(src);771 var tokenizer = std.zig.Tokenizer.init(src);
779 var index: usize = 0;772 var index: usize = 0;
780 var next_tok_is_fn = false;773 var next_tok_is_fn = false;
...@@ -835,15 +828,15 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -835,15 +828,15 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
835 .Keyword_allowzero,828 .Keyword_allowzero,
836 .Keyword_while,829 .Keyword_while,
837 => {830 => {
838 try out.write("<span class=\"tok-kw\">");831 try out.writeAll("<span class=\"tok-kw\">");
839 try writeEscaped(out, src[token.start..token.end]);832 try writeEscaped(out, src[token.start..token.end]);
840 try out.write("</span>");833 try out.writeAll("</span>");
841 },834 },
842835
843 .Keyword_fn => {836 .Keyword_fn => {
844 try out.write("<span class=\"tok-kw\">");837 try out.writeAll("<span class=\"tok-kw\">");
845 try writeEscaped(out, src[token.start..token.end]);838 try writeEscaped(out, src[token.start..token.end]);
846 try out.write("</span>");839 try out.writeAll("</span>");
847 next_tok_is_fn = true;840 next_tok_is_fn = true;
848 },841 },
849842
...@@ -852,24 +845,24 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -852,24 +845,24 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
852 .Keyword_true,845 .Keyword_true,
853 .Keyword_false,846 .Keyword_false,
854 => {847 => {
855 try out.write("<span class=\"tok-null\">");848 try out.writeAll("<span class=\"tok-null\">");
856 try writeEscaped(out, src[token.start..token.end]);849 try writeEscaped(out, src[token.start..token.end]);
857 try out.write("</span>");850 try out.writeAll("</span>");
858 },851 },
859852
860 .StringLiteral,853 .StringLiteral,
861 .MultilineStringLiteralLine,854 .MultilineStringLiteralLine,
862 .CharLiteral,855 .CharLiteral,
863 => {856 => {
864 try out.write("<span class=\"tok-str\">");857 try out.writeAll("<span class=\"tok-str\">");
865 try writeEscaped(out, src[token.start..token.end]);858 try writeEscaped(out, src[token.start..token.end]);
866 try out.write("</span>");859 try out.writeAll("</span>");
867 },860 },
868861
869 .Builtin => {862 .Builtin => {
870 try out.write("<span class=\"tok-builtin\">");863 try out.writeAll("<span class=\"tok-builtin\">");
871 try writeEscaped(out, src[token.start..token.end]);864 try writeEscaped(out, src[token.start..token.end]);
872 try out.write("</span>");865 try out.writeAll("</span>");
873 },866 },
874867
875 .LineComment,868 .LineComment,
...@@ -877,16 +870,16 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -877,16 +870,16 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
877 .ContainerDocComment,870 .ContainerDocComment,
878 .ShebangLine,871 .ShebangLine,
879 => {872 => {
880 try out.write("<span class=\"tok-comment\">");873 try out.writeAll("<span class=\"tok-comment\">");
881 try writeEscaped(out, src[token.start..token.end]);874 try writeEscaped(out, src[token.start..token.end]);
882 try out.write("</span>");875 try out.writeAll("</span>");
883 },876 },
884877
885 .Identifier => {878 .Identifier => {
886 if (prev_tok_was_fn) {879 if (prev_tok_was_fn) {
887 try out.write("<span class=\"tok-fn\">");880 try out.writeAll("<span class=\"tok-fn\">");
888 try writeEscaped(out, src[token.start..token.end]);881 try writeEscaped(out, src[token.start..token.end]);
889 try out.write("</span>");882 try out.writeAll("</span>");
890 } else {883 } else {
891 const is_int = blk: {884 const is_int = blk: {
892 if (src[token.start] != 'i' and src[token.start] != 'u')885 if (src[token.start] != 'i' and src[token.start] != 'u')
...@@ -901,9 +894,9 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -901,9 +894,9 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
901 break :blk true;894 break :blk true;
902 };895 };
903 if (is_int or isType(src[token.start..token.end])) {896 if (is_int or isType(src[token.start..token.end])) {
904 try out.write("<span class=\"tok-type\">");897 try out.writeAll("<span class=\"tok-type\">");
905 try writeEscaped(out, src[token.start..token.end]);898 try writeEscaped(out, src[token.start..token.end]);
906 try out.write("</span>");899 try out.writeAll("</span>");
907 } else {900 } else {
908 try writeEscaped(out, src[token.start..token.end]);901 try writeEscaped(out, src[token.start..token.end]);
909 }902 }
...@@ -913,9 +906,9 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -913,9 +906,9 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
913 .IntegerLiteral,906 .IntegerLiteral,
914 .FloatLiteral,907 .FloatLiteral,
915 => {908 => {
916 try out.write("<span class=\"tok-number\">");909 try out.writeAll("<span class=\"tok-number\">");
917 try writeEscaped(out, src[token.start..token.end]);910 try writeEscaped(out, src[token.start..token.end]);
918 try out.write("</span>");911 try out.writeAll("</span>");
919 },912 },
920913
921 .Bang,914 .Bang,
...@@ -983,7 +976,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -983,7 +976,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
983 }976 }
984 index = token.end;977 index = token.end;
985 }978 }
986 try out.write("</code>");979 try out.writeAll("</code>");
987}980}
988981
989fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token) !void {982fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token) !void {
...@@ -1002,7 +995,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1002,7 +995,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1002 for (toc.nodes) |node| {995 for (toc.nodes) |node| {
1003 switch (node) {996 switch (node) {
1004 .Content => |data| {997 .Content => |data| {
1005 try out.write(data);998 try out.writeAll(data);
1006 },999 },
1007 .Link => |info| {1000 .Link => |info| {
1008 if (!toc.urls.contains(info.url)) {1001 if (!toc.urls.contains(info.url)) {
...@@ -1011,12 +1004,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1011,12 +1004,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1011 try out.print("<a href=\"#{}\">{}</a>", .{ info.url, info.name });1004 try out.print("<a href=\"#{}\">{}</a>", .{ info.url, info.name });
1012 },1005 },
1013 .Nav => {1006 .Nav => {
1014 try out.write(toc.toc);1007 try out.writeAll(toc.toc);
1015 },1008 },
1016 .Builtin => |tok| {1009 .Builtin => |tok| {
1017 try out.write("<pre>");1010 try out.writeAll("<pre>");
1018 try tokenizeAndPrintRaw(tokenizer, out, tok, builtin_code);1011 try tokenizeAndPrintRaw(tokenizer, out, tok, builtin_code);
1019 try out.write("</pre>");1012 try out.writeAll("</pre>");
1020 },1013 },
1021 .HeaderOpen => |info| {1014 .HeaderOpen => |info| {
1022 try out.print(1015 try out.print(
...@@ -1025,7 +1018,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1025,7 +1018,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1025 );1018 );
1026 },1019 },
1027 .SeeAlso => |items| {1020 .SeeAlso => |items| {
1028 try out.write("<p>See also:</p><ul>\n");1021 try out.writeAll("<p>See also:</p><ul>\n");
1029 for (items) |item| {1022 for (items) |item| {
1030 const url = try urlize(allocator, item.name);1023 const url = try urlize(allocator, item.name);
1031 if (!toc.urls.contains(url)) {1024 if (!toc.urls.contains(url)) {
...@@ -1033,7 +1026,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1033,7 +1026,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1033 }1026 }
1034 try out.print("<li><a href=\"#{}\">{}</a></li>\n", .{ url, item.name });1027 try out.print("<li><a href=\"#{}\">{}</a></li>\n", .{ url, item.name });
1035 }1028 }
1036 try out.write("</ul>\n");1029 try out.writeAll("</ul>\n");
1037 },1030 },
1038 .Syntax => |content_tok| {1031 .Syntax => |content_tok| {
1039 try tokenizeAndPrint(tokenizer, out, content_tok);1032 try tokenizeAndPrint(tokenizer, out, content_tok);
...@@ -1047,9 +1040,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1047,9 +1040,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1047 if (!code.is_inline) {1040 if (!code.is_inline) {
1048 try out.print("<p class=\"file\">{}.zig</p>", .{code.name});1041 try out.print("<p class=\"file\">{}.zig</p>", .{code.name});
1049 }1042 }
1050 try out.write("<pre>");1043 try out.writeAll("<pre>");
1051 try tokenizeAndPrint(tokenizer, out, code.source_token);1044 try tokenizeAndPrint(tokenizer, out, code.source_token);
1052 try out.write("</pre>");1045 try out.writeAll("</pre>");
1053 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", .{code.name});1046 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", .{code.name});
1054 const tmp_source_file_name = try fs.path.join(1047 const tmp_source_file_name = try fs.path.join(
1055 allocator,1048 allocator,
doc/langref.html.in+1-1
...@@ -230,7 +230,7 @@...@@ -230,7 +230,7 @@
230const std = @import("std");230const std = @import("std");
231231
232pub fn main() !void {232pub fn main() !void {
233 const stdout = &std.io.getStdOut().outStream().stream;233 const stdout = std.io.getStdOut().outStream();
234 try stdout.print("Hello, {}!\n", .{"world"});234 try stdout.print("Hello, {}!\n", .{"world"});
235}235}
236 {#code_end#}236 {#code_end#}
lib/std/build.zig+1-2
...@@ -926,8 +926,7 @@ pub const Builder = struct {...@@ -926,8 +926,7 @@ pub const Builder = struct {
926926
927 try child.spawn();927 try child.spawn();
928928
929 var stdout_file_in_stream = child.stdout.?.inStream();929 const stdout = try child.stdout.?.inStream().readAllAlloc(self.allocator, max_output_size);
930 const stdout = try stdout_file_in_stream.stream.readAllAlloc(self.allocator, max_output_size);
931 errdefer self.allocator.free(stdout);930 errdefer self.allocator.free(stdout);
932931
933 const term = try child.wait();932 const term = try child.wait();
lib/std/build/run.zig+2-4
...@@ -175,8 +175,7 @@ pub const RunStep = struct {...@@ -175,8 +175,7 @@ pub const RunStep = struct {
175175
176 switch (self.stdout_action) {176 switch (self.stdout_action) {
177 .expect_exact, .expect_matches => {177 .expect_exact, .expect_matches => {
178 var stdout_file_in_stream = child.stdout.?.inStream();178 stdout = child.stdout.?.inStream().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable;
179 stdout = stdout_file_in_stream.stream.readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable;
180 },179 },
181 .inherit, .ignore => {},180 .inherit, .ignore => {},
182 }181 }
...@@ -186,8 +185,7 @@ pub const RunStep = struct {...@@ -186,8 +185,7 @@ pub const RunStep = struct {
186185
187 switch (self.stderr_action) {186 switch (self.stderr_action) {
188 .expect_exact, .expect_matches => {187 .expect_exact, .expect_matches => {
189 var stderr_file_in_stream = child.stderr.?.inStream();188 stderr = child.stderr.?.inStream().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable;
190 stderr = stderr_file_in_stream.stream.readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable;
191 },189 },
192 .inherit, .ignore => {},190 .inherit, .ignore => {},
193 }191 }
lib/std/coff.zig+6-9
...@@ -56,8 +56,7 @@ pub const Coff = struct {...@@ -56,8 +56,7 @@ pub const Coff = struct {
56 pub fn loadHeader(self: *Coff) !void {56 pub fn loadHeader(self: *Coff) !void {
57 const pe_pointer_offset = 0x3C;57 const pe_pointer_offset = 0x3C;
5858
59 var file_stream = self.in_file.inStream();59 const in = self.in_file.inStream();
60 const in = &file_stream.stream;
6160
62 var magic: [2]u8 = undefined;61 var magic: [2]u8 = undefined;
63 try in.readNoEof(magic[0..]);62 try in.readNoEof(magic[0..]);
...@@ -89,11 +88,11 @@ pub const Coff = struct {...@@ -89,11 +88,11 @@ pub const Coff = struct {
89 else => return error.InvalidMachine,88 else => return error.InvalidMachine,
90 }89 }
9190
92 try self.loadOptionalHeader(&file_stream);91 try self.loadOptionalHeader();
93 }92 }
9493
95 fn loadOptionalHeader(self: *Coff, file_stream: *File.InStream) !void {94 fn loadOptionalHeader(self: *Coff) !void {
96 const in = &file_stream.stream;95 const in = self.in_file.inStream();
97 self.pe_header.magic = try in.readIntLittle(u16);96 self.pe_header.magic = try in.readIntLittle(u16);
98 // For now we're only interested in finding the reference to the .pdb,97 // For now we're only interested in finding the reference to the .pdb,
99 // so we'll skip most of this header, which size is different in 3298 // so we'll skip most of this header, which size is different in 32
...@@ -136,8 +135,7 @@ pub const Coff = struct {...@@ -136,8 +135,7 @@ pub const Coff = struct {
136 const debug_dir = &self.pe_header.data_directory[DEBUG_DIRECTORY];135 const debug_dir = &self.pe_header.data_directory[DEBUG_DIRECTORY];
137 const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data;136 const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data;
138137
139 var file_stream = self.in_file.inStream();138 const in = self.in_file.inStream();
140 const in = &file_stream.stream;
141 try self.in_file.seekTo(file_offset);139 try self.in_file.seekTo(file_offset);
142140
143 // Find the correct DebugDirectoryEntry, and where its data is stored.141 // Find the correct DebugDirectoryEntry, and where its data is stored.
...@@ -188,8 +186,7 @@ pub const Coff = struct {...@@ -188,8 +186,7 @@ pub const Coff = struct {
188186
189 try self.sections.ensureCapacity(self.coff_header.number_of_sections);187 try self.sections.ensureCapacity(self.coff_header.number_of_sections);
190188
191 var file_stream = self.in_file.inStream();189 const in = self.in_file.inStream();
192 const in = &file_stream.stream;
193190
194 var name: [8]u8 = undefined;191 var name: [8]u8 = undefined;
195192
lib/std/debug.zig+19-19
...@@ -475,15 +475,15 @@ fn populateModule(di: *ModuleDebugInfo, mod: *Module) !void {...@@ -475,15 +475,15 @@ fn populateModule(di: *ModuleDebugInfo, mod: *Module) !void {
475475
476 const modi = di.pdb.getStreamById(mod.mod_info.ModuleSymStream) orelse return error.MissingDebugInfo;476 const modi = di.pdb.getStreamById(mod.mod_info.ModuleSymStream) orelse return error.MissingDebugInfo;
477477
478 const signature = try modi.stream.readIntLittle(u32);478 const signature = try modi.inStream().readIntLittle(u32);
479 if (signature != 4)479 if (signature != 4)
480 return error.InvalidDebugInfo;480 return error.InvalidDebugInfo;
481481
482 mod.symbols = try allocator.alloc(u8, mod.mod_info.SymByteSize - 4);482 mod.symbols = try allocator.alloc(u8, mod.mod_info.SymByteSize - 4);
483 try modi.stream.readNoEof(mod.symbols);483 try modi.inStream().readNoEof(mod.symbols);
484484
485 mod.subsect_info = try allocator.alloc(u8, mod.mod_info.C13ByteSize);485 mod.subsect_info = try allocator.alloc(u8, mod.mod_info.C13ByteSize);
486 try modi.stream.readNoEof(mod.subsect_info);486 try modi.inStream().readNoEof(mod.subsect_info);
487487
488 var sect_offset: usize = 0;488 var sect_offset: usize = 0;
489 var skip_len: usize = undefined;489 var skip_len: usize = undefined;
...@@ -656,11 +656,11 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !...@@ -656,11 +656,11 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
656 try di.pdb.openFile(di.coff, path);656 try di.pdb.openFile(di.coff, path);
657657
658 var pdb_stream = di.pdb.getStream(pdb.StreamType.Pdb) orelse return error.InvalidDebugInfo;658 var pdb_stream = di.pdb.getStream(pdb.StreamType.Pdb) orelse return error.InvalidDebugInfo;
659 const version = try pdb_stream.stream.readIntLittle(u32);659 const version = try pdb_stream.inStream().readIntLittle(u32);
660 const signature = try pdb_stream.stream.readIntLittle(u32);660 const signature = try pdb_stream.inStream().readIntLittle(u32);
661 const age = try pdb_stream.stream.readIntLittle(u32);661 const age = try pdb_stream.inStream().readIntLittle(u32);
662 var guid: [16]u8 = undefined;662 var guid: [16]u8 = undefined;
663 try pdb_stream.stream.readNoEof(&guid);663 try pdb_stream.inStream().readNoEof(&guid);
664 if (version != 20000404) // VC70, only value observed by LLVM team664 if (version != 20000404) // VC70, only value observed by LLVM team
665 return error.UnknownPDBVersion;665 return error.UnknownPDBVersion;
666 if (!mem.eql(u8, &di.coff.guid, &guid) or di.coff.age != age)666 if (!mem.eql(u8, &di.coff.guid, &guid) or di.coff.age != age)
...@@ -668,9 +668,9 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !...@@ -668,9 +668,9 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
668 // We validated the executable and pdb match.668 // We validated the executable and pdb match.
669669
670 const string_table_index = str_tab_index: {670 const string_table_index = str_tab_index: {
671 const name_bytes_len = try pdb_stream.stream.readIntLittle(u32);671 const name_bytes_len = try pdb_stream.inStream().readIntLittle(u32);
672 const name_bytes = try allocator.alloc(u8, name_bytes_len);672 const name_bytes = try allocator.alloc(u8, name_bytes_len);
673 try pdb_stream.stream.readNoEof(name_bytes);673 try pdb_stream.inStream().readNoEof(name_bytes);
674674
675 const HashTableHeader = packed struct {675 const HashTableHeader = packed struct {
676 Size: u32,676 Size: u32,
...@@ -680,17 +680,17 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !...@@ -680,17 +680,17 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
680 return cap * 2 / 3 + 1;680 return cap * 2 / 3 + 1;
681 }681 }
682 };682 };
683 const hash_tbl_hdr = try pdb_stream.stream.readStruct(HashTableHeader);683 const hash_tbl_hdr = try pdb_stream.inStream().readStruct(HashTableHeader);
684 if (hash_tbl_hdr.Capacity == 0)684 if (hash_tbl_hdr.Capacity == 0)
685 return error.InvalidDebugInfo;685 return error.InvalidDebugInfo;
686686
687 if (hash_tbl_hdr.Size > HashTableHeader.maxLoad(hash_tbl_hdr.Capacity))687 if (hash_tbl_hdr.Size > HashTableHeader.maxLoad(hash_tbl_hdr.Capacity))
688 return error.InvalidDebugInfo;688 return error.InvalidDebugInfo;
689689
690 const present = try readSparseBitVector(&pdb_stream.stream, allocator);690 const present = try readSparseBitVector(&pdb_stream.inStream(), allocator);
691 if (present.len != hash_tbl_hdr.Size)691 if (present.len != hash_tbl_hdr.Size)
692 return error.InvalidDebugInfo;692 return error.InvalidDebugInfo;
693 const deleted = try readSparseBitVector(&pdb_stream.stream, allocator);693 const deleted = try readSparseBitVector(&pdb_stream.inStream(), allocator);
694694
695 const Bucket = struct {695 const Bucket = struct {
696 first: u32,696 first: u32,
...@@ -698,8 +698,8 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !...@@ -698,8 +698,8 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
698 };698 };
699 const bucket_list = try allocator.alloc(Bucket, present.len);699 const bucket_list = try allocator.alloc(Bucket, present.len);
700 for (present) |_| {700 for (present) |_| {
701 const name_offset = try pdb_stream.stream.readIntLittle(u32);701 const name_offset = try pdb_stream.inStream().readIntLittle(u32);
702 const name_index = try pdb_stream.stream.readIntLittle(u32);702 const name_index = try pdb_stream.inStream().readIntLittle(u32);
703 const name = mem.toSlice(u8, @ptrCast([*:0]u8, name_bytes.ptr + name_offset));703 const name = mem.toSlice(u8, @ptrCast([*:0]u8, name_bytes.ptr + name_offset));
704 if (mem.eql(u8, name, "/names")) {704 if (mem.eql(u8, name, "/names")) {
705 break :str_tab_index name_index;705 break :str_tab_index name_index;
...@@ -714,7 +714,7 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !...@@ -714,7 +714,7 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
714 const dbi = di.pdb.dbi;714 const dbi = di.pdb.dbi;
715715
716 // Dbi Header716 // Dbi Header
717 const dbi_stream_header = try dbi.stream.readStruct(pdb.DbiStreamHeader);717 const dbi_stream_header = try dbi.inStream().readStruct(pdb.DbiStreamHeader);
718 if (dbi_stream_header.VersionHeader != 19990903) // V70, only value observed by LLVM team718 if (dbi_stream_header.VersionHeader != 19990903) // V70, only value observed by LLVM team
719 return error.UnknownPDBVersion;719 return error.UnknownPDBVersion;
720 if (dbi_stream_header.Age != age)720 if (dbi_stream_header.Age != age)
...@@ -728,7 +728,7 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !...@@ -728,7 +728,7 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
728 // Module Info Substream728 // Module Info Substream
729 var mod_info_offset: usize = 0;729 var mod_info_offset: usize = 0;
730 while (mod_info_offset != mod_info_size) {730 while (mod_info_offset != mod_info_size) {
731 const mod_info = try dbi.stream.readStruct(pdb.ModInfo);731 const mod_info = try dbi.inStream().readStruct(pdb.ModInfo);
732 var this_record_len: usize = @sizeOf(pdb.ModInfo);732 var this_record_len: usize = @sizeOf(pdb.ModInfo);
733733
734 const module_name = try dbi.readNullTermString(allocator);734 const module_name = try dbi.readNullTermString(allocator);
...@@ -766,14 +766,14 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !...@@ -766,14 +766,14 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
766 var sect_contribs = ArrayList(pdb.SectionContribEntry).init(allocator);766 var sect_contribs = ArrayList(pdb.SectionContribEntry).init(allocator);
767 var sect_cont_offset: usize = 0;767 var sect_cont_offset: usize = 0;
768 if (section_contrib_size != 0) {768 if (section_contrib_size != 0) {
769 const ver = @intToEnum(pdb.SectionContrSubstreamVersion, try dbi.stream.readIntLittle(u32));769 const ver = @intToEnum(pdb.SectionContrSubstreamVersion, try dbi.inStream().readIntLittle(u32));
770 if (ver != pdb.SectionContrSubstreamVersion.Ver60)770 if (ver != pdb.SectionContrSubstreamVersion.Ver60)
771 return error.InvalidDebugInfo;771 return error.InvalidDebugInfo;
772 sect_cont_offset += @sizeOf(u32);772 sect_cont_offset += @sizeOf(u32);
773 }773 }
774 while (sect_cont_offset != section_contrib_size) {774 while (sect_cont_offset != section_contrib_size) {
775 const entry = try sect_contribs.addOne();775 const entry = try sect_contribs.addOne();
776 entry.* = try dbi.stream.readStruct(pdb.SectionContribEntry);776 entry.* = try dbi.inStream().readStruct(pdb.SectionContribEntry);
777 sect_cont_offset += @sizeOf(pdb.SectionContribEntry);777 sect_cont_offset += @sizeOf(pdb.SectionContribEntry);
778778
779 if (sect_cont_offset > section_contrib_size)779 if (sect_cont_offset > section_contrib_size)
...@@ -827,7 +827,7 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M...@@ -827,7 +827,7 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M
827 const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);827 const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);
828 const str_shdr = @ptrCast(828 const str_shdr = @ptrCast(
829 *const elf.Shdr,829 *const elf.Shdr,
830 @alignCast(@alignOf(elf.Shdr), &mapped_mem[str_section_off]),830 @alignCast(@alignOf(elf.Shdr), &mapped_mem[try math.cast(usize, str_section_off)]),
831 );831 );
832 const header_strings = mapped_mem[str_shdr.sh_offset .. str_shdr.sh_offset + str_shdr.sh_size];832 const header_strings = mapped_mem[str_shdr.sh_offset .. str_shdr.sh_offset + str_shdr.sh_size];
833 const shdrs = @ptrCast(833 const shdrs = @ptrCast(
lib/std/pdb.zig+6-8
...@@ -495,8 +495,7 @@ const Msf = struct {...@@ -495,8 +495,7 @@ const Msf = struct {
495 streams: []MsfStream,495 streams: []MsfStream,
496496
497 fn openFile(self: *Msf, allocator: *mem.Allocator, file: File) !void {497 fn openFile(self: *Msf, allocator: *mem.Allocator, file: File) !void {
498 var file_stream = file.inStream();498 const in = file.inStream();
499 const in = &file_stream.stream;
500499
501 const superblock = try in.readStruct(SuperBlock);500 const superblock = try in.readStruct(SuperBlock);
502501
...@@ -529,7 +528,7 @@ const Msf = struct {...@@ -529,7 +528,7 @@ const Msf = struct {
529 );528 );
530529
531 const begin = self.directory.pos;530 const begin = self.directory.pos;
532 const stream_count = try self.directory.stream.readIntLittle(u32);531 const stream_count = try self.directory.inStream().readIntLittle(u32);
533 const stream_sizes = try allocator.alloc(u32, stream_count);532 const stream_sizes = try allocator.alloc(u32, stream_count);
534 defer allocator.free(stream_sizes);533 defer allocator.free(stream_sizes);
535534
...@@ -538,7 +537,7 @@ const Msf = struct {...@@ -538,7 +537,7 @@ const Msf = struct {
538 // and must be taken into account when resolving stream indices.537 // and must be taken into account when resolving stream indices.
539 const Nil = 0xFFFFFFFF;538 const Nil = 0xFFFFFFFF;
540 for (stream_sizes) |*s, i| {539 for (stream_sizes) |*s, i| {
541 const size = try self.directory.stream.readIntLittle(u32);540 const size = try self.directory.inStream().readIntLittle(u32);
542 s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize);541 s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize);
543 }542 }
544543
...@@ -553,7 +552,7 @@ const Msf = struct {...@@ -553,7 +552,7 @@ const Msf = struct {
553 var blocks = try allocator.alloc(u32, size);552 var blocks = try allocator.alloc(u32, size);
554 var j: u32 = 0;553 var j: u32 = 0;
555 while (j < size) : (j += 1) {554 while (j < size) : (j += 1) {
556 const block_id = try self.directory.stream.readIntLittle(u32);555 const block_id = try self.directory.inStream().readIntLittle(u32);
557 const n = (block_id % superblock.BlockSize);556 const n = (block_id % superblock.BlockSize);
558 // 0 is for SuperBlock, 1 and 2 for FPMs.557 // 0 is for SuperBlock, 1 and 2 for FPMs.
559 if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > try file.getEndPos())558 if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > try file.getEndPos())
...@@ -648,7 +647,7 @@ const MsfStream = struct {...@@ -648,7 +647,7 @@ const MsfStream = struct {
648 fn readNullTermString(self: *MsfStream, allocator: *mem.Allocator) ![]u8 {647 fn readNullTermString(self: *MsfStream, allocator: *mem.Allocator) ![]u8 {
649 var list = ArrayList(u8).init(allocator);648 var list = ArrayList(u8).init(allocator);
650 while (true) {649 while (true) {
651 const byte = try self.stream.readByte();650 const byte = try self.inStream().readByte();
652 if (byte == 0) {651 if (byte == 0) {
653 return list.toSlice();652 return list.toSlice();
654 }653 }
...@@ -662,8 +661,7 @@ const MsfStream = struct {...@@ -662,8 +661,7 @@ const MsfStream = struct {
662 var offset = self.pos % self.block_size;661 var offset = self.pos % self.block_size;
663662
664 try self.in_file.seekTo(block * self.block_size + offset);663 try self.in_file.seekTo(block * self.block_size + offset);
665 var file_stream = self.in_file.inStream();664 const in = self.in_file.inStream();
666 const in = &file_stream.stream;
667665
668 var size: usize = 0;666 var size: usize = 0;
669 var rem_buffer = buffer;667 var rem_buffer = buffer;
lib/std/special/build_runner.zig+4-4
...@@ -42,8 +42,8 @@ pub fn main() !void {...@@ -42,8 +42,8 @@ pub fn main() !void {
4242
43 var targets = ArrayList([]const u8).init(allocator);43 var targets = ArrayList([]const u8).init(allocator);
4444
45 const stderr_stream = &io.getStdErr().outStream().stream;45 const stderr_stream = io.getStdErr().outStream();
46 const stdout_stream = &io.getStdOut().outStream().stream;46 const stdout_stream = io.getStdOut().outStream();
4747
48 while (nextArg(args, &arg_idx)) |arg| {48 while (nextArg(args, &arg_idx)) |arg| {
49 if (mem.startsWith(u8, arg, "-D")) {49 if (mem.startsWith(u8, arg, "-D")) {
...@@ -159,7 +159,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {...@@ -159,7 +159,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
159 try out_stream.print(" {s:22} {}\n", .{ name, top_level_step.description });159 try out_stream.print(" {s:22} {}\n", .{ name, top_level_step.description });
160 }160 }
161161
162 try out_stream.write(162 try out_stream.writeAll(
163 \\163 \\
164 \\General Options:164 \\General Options:
165 \\ --help Print this help and exit165 \\ --help Print this help and exit
...@@ -184,7 +184,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {...@@ -184,7 +184,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
184 }184 }
185 }185 }
186186
187 try out_stream.write(187 try out_stream.writeAll(
188 \\188 \\
189 \\Advanced Options:189 \\Advanced Options:
190 \\ --build-file [file] Override path to build.zig190 \\ --build-file [file] Override path to build.zig
test/compare_output.zig+15-19
...@@ -22,7 +22,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -22,7 +22,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
22 \\22 \\
23 \\pub fn main() void {23 \\pub fn main() void {
24 \\ privateFunction();24 \\ privateFunction();
25 \\ const stdout = &getStdOut().outStream().stream;25 \\ const stdout = getStdOut().outStream();
26 \\ stdout.print("OK 2\n", .{}) catch unreachable;26 \\ stdout.print("OK 2\n", .{}) catch unreachable;
27 \\}27 \\}
28 \\28 \\
...@@ -37,7 +37,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -37,7 +37,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
37 \\// purposefully conflicting function with main.zig37 \\// purposefully conflicting function with main.zig
38 \\// but it's private so it should be OK38 \\// but it's private so it should be OK
39 \\fn privateFunction() void {39 \\fn privateFunction() void {
40 \\ const stdout = &getStdOut().outStream().stream;40 \\ const stdout = getStdOut().outStream();
41 \\ stdout.print("OK 1\n", .{}) catch unreachable;41 \\ stdout.print("OK 1\n", .{}) catch unreachable;
42 \\}42 \\}
43 \\43 \\
...@@ -63,7 +63,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -63,7 +63,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
63 tc.addSourceFile("foo.zig",63 tc.addSourceFile("foo.zig",
64 \\usingnamespace @import("std").io;64 \\usingnamespace @import("std").io;
65 \\pub fn foo_function() void {65 \\pub fn foo_function() void {
66 \\ const stdout = &getStdOut().outStream().stream;66 \\ const stdout = getStdOut().outStream();
67 \\ stdout.print("OK\n", .{}) catch unreachable;67 \\ stdout.print("OK\n", .{}) catch unreachable;
68 \\}68 \\}
69 );69 );
...@@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
74 \\74 \\
75 \\pub fn bar_function() void {75 \\pub fn bar_function() void {
76 \\ if (foo_function()) {76 \\ if (foo_function()) {
77 \\ const stdout = &getStdOut().outStream().stream;77 \\ const stdout = getStdOut().outStream();
78 \\ stdout.print("OK\n", .{}) catch unreachable;78 \\ stdout.print("OK\n", .{}) catch unreachable;
79 \\ }79 \\ }
80 \\}80 \\}
...@@ -106,7 +106,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -106,7 +106,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
106 \\pub const a_text = "OK\n";106 \\pub const a_text = "OK\n";
107 \\107 \\
108 \\pub fn ok() void {108 \\pub fn ok() void {
109 \\ const stdout = &io.getStdOut().outStream().stream;109 \\ const stdout = io.getStdOut().outStream();
110 \\ stdout.print(b_text, .{}) catch unreachable;110 \\ stdout.print(b_text, .{}) catch unreachable;
111 \\}111 \\}
112 );112 );
...@@ -124,7 +124,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -124,7 +124,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
124 \\const io = @import("std").io;124 \\const io = @import("std").io;
125 \\125 \\
126 \\pub fn main() void {126 \\pub fn main() void {
127 \\ const stdout = &io.getStdOut().outStream().stream;127 \\ const stdout = io.getStdOut().outStream();
128 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", .{@as(u32, 12), @as(u16, 0x12), @as(u8, 'a')}) catch unreachable;128 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", .{@as(u32, 12), @as(u16, 0x12), @as(u8, 'a')}) catch unreachable;
129 \\}129 \\}
130 , "Hello, world!\n 12 12 a\n");130 , "Hello, world!\n 12 12 a\n");
...@@ -267,7 +267,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -267,7 +267,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
267 \\ var x_local : i32 = print_ok(x);267 \\ var x_local : i32 = print_ok(x);
268 \\}268 \\}
269 \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) {269 \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) {
270 \\ const stdout = &io.getStdOut().outStream().stream;270 \\ const stdout = io.getStdOut().outStream();
271 \\ stdout.print("OK\n", .{}) catch unreachable;271 \\ stdout.print("OK\n", .{}) catch unreachable;
272 \\ return 0;272 \\ return 0;
273 \\}273 \\}
...@@ -349,7 +349,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -349,7 +349,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
349 \\pub fn main() void {349 \\pub fn main() void {
350 \\ const bar = Bar {.field2 = 13,};350 \\ const bar = Bar {.field2 = 13,};
351 \\ const foo = Foo {.field1 = bar,};351 \\ const foo = Foo {.field1 = bar,};
352 \\ const stdout = &io.getStdOut().outStream().stream;352 \\ const stdout = io.getStdOut().outStream();
353 \\ if (!foo.method()) {353 \\ if (!foo.method()) {
354 \\ stdout.print("BAD\n", .{}) catch unreachable;354 \\ stdout.print("BAD\n", .{}) catch unreachable;
355 \\ }355 \\ }
...@@ -363,7 +363,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -363,7 +363,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
363 cases.add("defer with only fallthrough",363 cases.add("defer with only fallthrough",
364 \\const io = @import("std").io;364 \\const io = @import("std").io;
365 \\pub fn main() void {365 \\pub fn main() void {
366 \\ const stdout = &io.getStdOut().outStream().stream;366 \\ const stdout = io.getStdOut().outStream();
367 \\ stdout.print("before\n", .{}) catch unreachable;367 \\ stdout.print("before\n", .{}) catch unreachable;
368 \\ defer stdout.print("defer1\n", .{}) catch unreachable;368 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
369 \\ defer stdout.print("defer2\n", .{}) catch unreachable;369 \\ defer stdout.print("defer2\n", .{}) catch unreachable;
...@@ -376,7 +376,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -376,7 +376,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
376 \\const io = @import("std").io;376 \\const io = @import("std").io;
377 \\const os = @import("std").os;377 \\const os = @import("std").os;
378 \\pub fn main() void {378 \\pub fn main() void {
379 \\ const stdout = &io.getStdOut().outStream().stream;379 \\ const stdout = io.getStdOut().outStream();
380 \\ stdout.print("before\n", .{}) catch unreachable;380 \\ stdout.print("before\n", .{}) catch unreachable;
381 \\ defer stdout.print("defer1\n", .{}) catch unreachable;381 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
382 \\ defer stdout.print("defer2\n", .{}) catch unreachable;382 \\ defer stdout.print("defer2\n", .{}) catch unreachable;
...@@ -393,7 +393,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -393,7 +393,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
393 \\ do_test() catch return;393 \\ do_test() catch return;
394 \\}394 \\}
395 \\fn do_test() !void {395 \\fn do_test() !void {
396 \\ const stdout = &io.getStdOut().outStream().stream;396 \\ const stdout = io.getStdOut().outStream();
397 \\ stdout.print("before\n", .{}) catch unreachable;397 \\ stdout.print("before\n", .{}) catch unreachable;
398 \\ defer stdout.print("defer1\n", .{}) catch unreachable;398 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
399 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;399 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;
...@@ -412,7 +412,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -412,7 +412,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
412 \\ do_test() catch return;412 \\ do_test() catch return;
413 \\}413 \\}
414 \\fn do_test() !void {414 \\fn do_test() !void {
415 \\ const stdout = &io.getStdOut().outStream().stream;415 \\ const stdout = io.getStdOut().outStream();
416 \\ stdout.print("before\n", .{}) catch unreachable;416 \\ stdout.print("before\n", .{}) catch unreachable;
417 \\ defer stdout.print("defer1\n", .{}) catch unreachable;417 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
418 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;418 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;
...@@ -429,7 +429,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -429,7 +429,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
429 \\const io = @import("std").io;429 \\const io = @import("std").io;
430 \\430 \\
431 \\pub fn main() void {431 \\pub fn main() void {
432 \\ const stdout = &io.getStdOut().outStream().stream;432 \\ const stdout = io.getStdOut().outStream();
433 \\ stdout.print(foo_txt, .{}) catch unreachable;433 \\ stdout.print(foo_txt, .{}) catch unreachable;
434 \\}434 \\}
435 , "1234\nabcd\n");435 , "1234\nabcd\n");
...@@ -448,9 +448,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -448,9 +448,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
448 \\448 \\
449 \\pub fn main() !void {449 \\pub fn main() !void {
450 \\ var args_it = std.process.args();450 \\ var args_it = std.process.args();
451 \\ var stdout_file = io.getStdOut();451 \\ const stdout = io.getStdOut().outStream();
452 \\ var stdout_adapter = stdout_file.outStream();
453 \\ const stdout = &stdout_adapter.stream;
454 \\ var index: usize = 0;452 \\ var index: usize = 0;
455 \\ _ = args_it.skip();453 \\ _ = args_it.skip();
456 \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) {454 \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) {
...@@ -489,9 +487,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -489,9 +487,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
489 \\487 \\
490 \\pub fn main() !void {488 \\pub fn main() !void {
491 \\ var args_it = std.process.args();489 \\ var args_it = std.process.args();
492 \\ var stdout_file = io.getStdOut();490 \\ const stdout = io.getStdOut().outStream();
493 \\ var stdout_adapter = stdout_file.outStream();
494 \\ const stdout = &stdout_adapter.stream;
495 \\ var index: usize = 0;491 \\ var index: usize = 0;
496 \\ _ = args_it.skip();492 \\ _ = args_it.skip();
497 \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) {493 \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) {
test/standalone/guess_number/main.zig+1-1
...@@ -4,7 +4,7 @@ const io = std.io;...@@ -4,7 +4,7 @@ const io = std.io;
4const fmt = std.fmt;4const fmt = std.fmt;
55
6pub fn main() !void {6pub fn main() !void {
7 const stdout = &io.getStdOut().outStream().stream;7 const stdout = io.getStdOut().outStream();
8 const stdin = io.getStdIn();8 const stdin = io.getStdIn();
99
10 try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});10 try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});
test/tests.zig+4-10
...@@ -566,12 +566,9 @@ pub const StackTracesContext = struct {...@@ -566,12 +566,9 @@ pub const StackTracesContext = struct {
566 }566 }
567 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });567 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
568568
569 var stdout_file_in_stream = child.stdout.?.inStream();569 const stdout = child.stdout.?.inStream().readAllAlloc(b.allocator, max_stdout_size) catch unreachable;
570 var stderr_file_in_stream = child.stderr.?.inStream();
571
572 const stdout = stdout_file_in_stream.stream.readAllAlloc(b.allocator, max_stdout_size) catch unreachable;
573 defer b.allocator.free(stdout);570 defer b.allocator.free(stdout);
574 const stderr = stderr_file_in_stream.stream.readAllAlloc(b.allocator, max_stdout_size) catch unreachable;571 const stderr = child.stderr.?.inStream().readAllAlloc(b.allocator, max_stdout_size) catch unreachable;
575 defer b.allocator.free(stderr);572 defer b.allocator.free(stderr);
576573
577 const term = child.wait() catch |err| {574 const term = child.wait() catch |err| {
...@@ -798,11 +795,8 @@ pub const CompileErrorContext = struct {...@@ -798,11 +795,8 @@ pub const CompileErrorContext = struct {
798 var stdout_buf = Buffer.initNull(b.allocator);795 var stdout_buf = Buffer.initNull(b.allocator);
799 var stderr_buf = Buffer.initNull(b.allocator);796 var stderr_buf = Buffer.initNull(b.allocator);
800797
801 var stdout_file_in_stream = child.stdout.?.inStream();798 child.stdout.?.inStream().readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
802 var stderr_file_in_stream = child.stderr.?.inStream();799 child.stderr.?.inStream().readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
803
804 stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
805 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
806800
807 const term = child.wait() catch |err| {801 const term = child.wait() catch |err| {
808 debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });802 debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });