| author | |
| committer | |
| log | f7884961c230367cefd3dfbf730ac5277297dc63 |
| tree | e9f49ef21141371c1643a28ac7aa7347afc43cba |
| parent | 4f510dba10872cf7b71d1a48b4dc5879444f89d7 |
10 files changed, 128 insertions(+), 99 deletions(-)
lib/std/Io/Reader.zig+32-1| ... | ... | @@ -784,7 +784,7 @@ pub fn peekDelimiterInclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 { |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /// Returns a slice of the next bytes of buffered data from the stream until |
| 787 | /// `delimiter` is found, advancing the seek position. | |
| 787 | /// `delimiter` is found, advancing the seek position up to the delimiter. | |
| 788 | 788 | /// |
| 789 | 789 | /// Returned slice excludes the delimiter. End-of-stream is treated equivalent |
| 790 | 790 | /// to a delimiter, unless it would result in a length 0 return value, in which |
| ... | ... | @@ -814,6 +814,37 @@ pub fn takeDelimiterExclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 { |
| 814 | 814 | return result[0 .. result.len - 1]; |
| 815 | 815 | } |
| 816 | 816 | |
| 817 | /// Returns a slice of the next bytes of buffered data from the stream until | |
| 818 | /// `delimiter` is found, advancing the seek position past the delimiter. | |
| 819 | /// | |
| 820 | /// Returned slice excludes the delimiter. End-of-stream is treated equivalent | |
| 821 | /// to a delimiter, unless it would result in a length 0 return value, in which | |
| 822 | /// case `null` is returned instead. | |
| 823 | /// | |
| 824 | /// If the delimiter is not found within a number of bytes matching the | |
| 825 | /// capacity of this `Reader`, `error.StreamTooLong` is returned. In | |
| 826 | /// such case, the stream state is unmodified as if this function was never | |
| 827 | /// called. | |
| 828 | /// | |
| 829 | /// Invalidates previously returned values from `peek`. | |
| 830 | /// | |
| 831 | /// See also: | |
| 832 | /// * `takeDelimiterInclusive` | |
| 833 | /// * `takeDelimiterExclusive` | |
| 834 | pub fn takeDelimiter(r: *Reader, delimiter: u8) error{ ReadFailed, StreamTooLong }!?[]u8 { | |
| 835 | const result = r.peekDelimiterInclusive(delimiter) catch |err| switch (err) { | |
| 836 | error.EndOfStream => { | |
| 837 | const remaining = r.buffer[r.seek..r.end]; | |
| 838 | if (remaining.len == 0) return null; | |
| 839 | r.toss(remaining.len); | |
| 840 | return remaining; | |
| 841 | }, | |
| 842 | else => |e| return e, | |
| 843 | }; | |
| 844 | r.toss(result.len + 1); | |
| 845 | return result[0 .. result.len - 1]; | |
| 846 | } | |
| 847 | ||
| 817 | 848 | /// Returns a slice of the next bytes of buffered data from the stream until |
| 818 | 849 | /// `delimiter` is found, without advancing the seek position. |
| 819 | 850 | /// |
src/link/MachO/dyld_info/Rebase.zig+6-7| ... | ... | @@ -228,13 +228,13 @@ fn setTypePointer(writer: anytype) !void { |
| 228 | 228 | fn setSegmentOffset(segment_id: u8, offset: u64, writer: anytype) !void { |
| 229 | 229 | log.debug(">>> set segment: {d} and offset: {x}", .{ segment_id, offset }); |
| 230 | 230 | try writer.writeByte(macho.REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | @as(u4, @truncate(segment_id))); |
| 231 | try std.leb.writeUleb128(writer, offset); | |
| 231 | try writer.writeUleb128(offset); | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | fn rebaseAddAddr(addr: u64, writer: anytype) !void { |
| 235 | 235 | log.debug(">>> rebase with add: {x}", .{addr}); |
| 236 | 236 | try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB); |
| 237 | try std.leb.writeUleb128(writer, addr); | |
| 237 | try writer.writeUleb128(addr); | |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | fn rebaseTimes(count: usize, writer: anytype) !void { |
| ... | ... | @@ -243,15 +243,15 @@ fn rebaseTimes(count: usize, writer: anytype) !void { |
| 243 | 243 | try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_IMM_TIMES | @as(u4, @truncate(count))); |
| 244 | 244 | } else { |
| 245 | 245 | try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_ULEB_TIMES); |
| 246 | try std.leb.writeUleb128(writer, count); | |
| 246 | try writer.writeUleb128(count); | |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | fn rebaseTimesSkip(count: usize, skip: u64, writer: anytype) !void { |
| 251 | 251 | log.debug(">>> rebase with count: {d} and skip: {x}", .{ count, skip }); |
| 252 | 252 | try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB); |
| 253 | try std.leb.writeUleb128(writer, count); | |
| 254 | try std.leb.writeUleb128(writer, skip); | |
| 253 | try writer.writeUleb128(count); | |
| 254 | try writer.writeUleb128(skip); | |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | fn addAddr(addr: u64, writer: anytype) !void { |
| ... | ... | @@ -264,7 +264,7 @@ fn addAddr(addr: u64, writer: anytype) !void { |
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | try writer.writeByte(macho.REBASE_OPCODE_ADD_ADDR_ULEB); |
| 267 | try std.leb.writeUleb128(writer, addr); | |
| 267 | try writer.writeUleb128(addr); | |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | fn done(writer: anytype) !void { |
| ... | ... | @@ -651,7 +651,6 @@ test "rebase - composite" { |
| 651 | 651 | |
| 652 | 652 | const std = @import("std"); |
| 653 | 653 | const assert = std.debug.assert; |
| 654 | const leb = std.leb; | |
| 655 | 654 | const log = std.log.scoped(.link_dyld_info); |
| 656 | 655 | const macho = std.macho; |
| 657 | 656 | const mem = std.mem; |
src/link/MachO/dyld_info/Trie.zig+4-5| ... | ... | @@ -262,13 +262,13 @@ fn writeNode(self: *Trie, node_index: Node.Index, writer: *std.Io.Writer) !void |
| 262 | 262 | // TODO Implement for special flags. |
| 263 | 263 | assert(export_flags & macho.EXPORT_SYMBOL_FLAGS_REEXPORT == 0 and |
| 264 | 264 | export_flags & macho.EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER == 0); |
| 265 | try leb.writeUleb128(&info_stream, export_flags); | |
| 266 | try leb.writeUleb128(&info_stream, vmaddr_offset); | |
| 265 | try info_stream.writeUleb128(export_flags); | |
| 266 | try info_stream.writeUleb128(vmaddr_offset); | |
| 267 | 267 | |
| 268 | 268 | // Encode the size of the terminal node info. |
| 269 | 269 | var size_buf: [@sizeOf(u64)]u8 = undefined; |
| 270 | 270 | var size_stream: std.Io.Writer = .fixed(&size_buf); |
| 271 | try leb.writeUleb128(&size_stream, info_stream.end); | |
| 271 | try size_stream.writeUleb128(info_stream.end); | |
| 272 | 272 | |
| 273 | 273 | // Now, write them to the output stream. |
| 274 | 274 | try writer.writeAll(size_buf[0..size_stream.end]); |
| ... | ... | @@ -285,7 +285,7 @@ fn writeNode(self: *Trie, node_index: Node.Index, writer: *std.Io.Writer) !void |
| 285 | 285 | // Write edge label and offset to next node in trie. |
| 286 | 286 | try writer.writeAll(edge.label); |
| 287 | 287 | try writer.writeByte(0); |
| 288 | try leb.writeUleb128(writer, slice.items(.trie_offset)[edge.node]); | |
| 288 | try writer.writeUleb128(slice.items(.trie_offset)[edge.node]); | |
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
| ... | ... | @@ -419,7 +419,6 @@ test "ordering bug" { |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | const assert = std.debug.assert; |
| 422 | const leb = std.leb; | |
| 423 | 422 | const log = std.log.scoped(.macho); |
| 424 | 423 | const macho = std.macho; |
| 425 | 424 | const mem = std.mem; |
src/link/MachO/dyld_info/bind.zig+6-7| ... | ... | @@ -605,7 +605,7 @@ pub const LazyBind = struct { |
| 605 | 605 | fn setSegmentOffset(segment_id: u8, offset: u64, writer: *std.Io.Writer) !void { |
| 606 | 606 | log.debug(">>> set segment: {d} and offset: {x}", .{ segment_id, offset }); |
| 607 | 607 | try writer.writeByte(macho.BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB | @as(u4, @truncate(segment_id))); |
| 608 | try std.leb.writeUleb128(writer, offset); | |
| 608 | try writer.writeUleb128(offset); | |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | fn setSymbol(name: []const u8, flags: u8, writer: *std.Io.Writer) !void { |
| ... | ... | @@ -639,7 +639,7 @@ fn setDylibOrdinal(ordinal: i16, writer: *std.Io.Writer) !void { |
| 639 | 639 | try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | @as(u4, @truncate(cast))); |
| 640 | 640 | } else { |
| 641 | 641 | try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB); |
| 642 | try std.leb.writeUleb128(writer, cast); | |
| 642 | try writer.writeUleb128(cast); | |
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | } |
| ... | ... | @@ -667,20 +667,20 @@ fn doBindAddAddr(addr: u64, writer: *std.Io.Writer) !void { |
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | try writer.writeByte(macho.BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB); |
| 670 | try std.leb.writeUleb128(writer, addr); | |
| 670 | try writer.writeUleb128(addr); | |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | fn doBindTimesSkip(count: usize, skip: u64, writer: *std.Io.Writer) !void { |
| 674 | 674 | log.debug(">>> bind with count: {d} and skip: {x}", .{ count, skip }); |
| 675 | 675 | try writer.writeByte(macho.BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB); |
| 676 | try std.leb.writeUleb128(writer, count); | |
| 677 | try std.leb.writeUleb128(writer, skip); | |
| 676 | try writer.writeUleb128(count); | |
| 677 | try writer.writeUleb128(skip); | |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | fn addAddr(addr: u64, writer: *std.Io.Writer) !void { |
| 681 | 681 | log.debug(">>> add: {x}", .{addr}); |
| 682 | 682 | try writer.writeByte(macho.BIND_OPCODE_ADD_ADDR_ULEB); |
| 683 | try std.leb.writeUleb128(writer, addr); | |
| 683 | try writer.writeUleb128(addr); | |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | fn done(writer: *std.Io.Writer) !void { |
| ... | ... | @@ -689,7 +689,6 @@ fn done(writer: *std.Io.Writer) !void { |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | const assert = std.debug.assert; |
| 692 | const leb = std.leb; | |
| 693 | 692 | const log = std.log.scoped(.link_dyld_info); |
| 694 | 693 | const macho = std.macho; |
| 695 | 694 | const mem = std.mem; |
test/standalone/run_output_paths/create_file.zig+2-1| ... | ... | @@ -10,7 +10,8 @@ pub fn main() !void { |
| 10 | 10 | dir_name, .{}); |
| 11 | 11 | const file_name = args.next().?; |
| 12 | 12 | const file = try dir.createFile(file_name, .{}); |
| 13 | try file.deprecatedWriter().print( | |
| 13 | var file_writer = file.writer(&.{}); | |
| 14 | try file_writer.interface.print( | |
| 14 | 15 | \\{s} |
| 15 | 16 | \\{s} |
| 16 | 17 | \\Hello, world! |
tools/doctest.zig+45-45| ... | ... | @@ -7,6 +7,7 @@ const process = std.process; |
| 7 | 7 | const Allocator = std.mem.Allocator; |
| 8 | 8 | const testing = std.testing; |
| 9 | 9 | const getExternalExecutor = std.zig.system.getExternalExecutor; |
| 10 | const Writer = std.Io.Writer; | |
| 10 | 11 | |
| 11 | 12 | const max_doc_file_size = 10 * 1024 * 1024; |
| 12 | 13 | |
| ... | ... | @@ -108,7 +109,7 @@ pub fn main() !void { |
| 108 | 109 | |
| 109 | 110 | fn printOutput( |
| 110 | 111 | arena: Allocator, |
| 111 | out: anytype, | |
| 112 | out: *Writer, | |
| 112 | 113 | code: Code, |
| 113 | 114 | /// Relative to this process' cwd. |
| 114 | 115 | tmp_dir_path: []const u8, |
| ... | ... | @@ -610,7 +611,7 @@ fn dumpArgs(args: []const []const u8) void { |
| 610 | 611 | std.debug.print("\n", .{}); |
| 611 | 612 | } |
| 612 | 613 | |
| 613 | fn printSourceBlock(arena: Allocator, out: anytype, source_bytes: []const u8, name: []const u8) !void { | |
| 614 | fn printSourceBlock(arena: Allocator, out: *Writer, source_bytes: []const u8, name: []const u8) !void { | |
| 614 | 615 | try out.print("<figure><figcaption class=\"{s}-cap\"><cite class=\"file\">{s}</cite></figcaption><pre>", .{ |
| 615 | 616 | "zig", name, |
| 616 | 617 | }); |
| ... | ... | @@ -618,7 +619,7 @@ fn printSourceBlock(arena: Allocator, out: anytype, source_bytes: []const u8, na |
| 618 | 619 | try out.writeAll("</pre></figure>"); |
| 619 | 620 | } |
| 620 | 621 | |
| 621 | fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void { | |
| 622 | fn tokenizeAndPrint(arena: Allocator, out: *Writer, raw_src: []const u8) !void { | |
| 622 | 623 | const src_non_terminated = mem.trim(u8, raw_src, " \r\n"); |
| 623 | 624 | const src = try arena.dupeZ(u8, src_non_terminated); |
| 624 | 625 | |
| ... | ... | @@ -846,7 +847,7 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void { |
| 846 | 847 | try out.writeAll("</code>"); |
| 847 | 848 | } |
| 848 | 849 | |
| 849 | fn writeEscapedLines(out: anytype, text: []const u8) !void { | |
| 850 | fn writeEscapedLines(out: *Writer, text: []const u8) !void { | |
| 850 | 851 | return writeEscaped(out, text); |
| 851 | 852 | } |
| 852 | 853 | |
| ... | ... | @@ -983,7 +984,7 @@ fn escapeHtml(allocator: Allocator, input: []const u8) ![]u8 { |
| 983 | 984 | return try buf.toOwnedSlice(); |
| 984 | 985 | } |
| 985 | 986 | |
| 986 | fn writeEscaped(out: anytype, input: []const u8) !void { | |
| 987 | fn writeEscaped(out: *Writer, input: []const u8) !void { | |
| 987 | 988 | for (input) |c| { |
| 988 | 989 | try switch (c) { |
| 989 | 990 | '&' => out.writeAll("&amp;"), |
| ... | ... | @@ -1014,7 +1015,6 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 1014 | 1015 | var buf = std.array_list.Managed(u8).init(allocator); |
| 1015 | 1016 | defer buf.deinit(); |
| 1016 | 1017 | |
| 1017 | var out = buf.writer(); | |
| 1018 | 1018 | var sgr_param_start_index: usize = undefined; |
| 1019 | 1019 | var sgr_num: u8 = undefined; |
| 1020 | 1020 | var sgr_color: u8 = undefined; |
| ... | ... | @@ -1037,10 +1037,10 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 1037 | 1037 | .start => switch (c) { |
| 1038 | 1038 | '\x1b' => state = .escape, |
| 1039 | 1039 | '\n' => { |
| 1040 | try out.writeByte(c); | |
| 1040 | try buf.append(c); | |
| 1041 | 1041 | last_new_line = buf.items.len; |
| 1042 | 1042 | }, |
| 1043 | else => try out.writeByte(c), | |
| 1043 | else => try buf.append(c), | |
| 1044 | 1044 | }, |
| 1045 | 1045 | .escape => switch (c) { |
| 1046 | 1046 | '[' => state = .lbracket, |
| ... | ... | @@ -1101,16 +1101,16 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 1101 | 1101 | 'm' => { |
| 1102 | 1102 | state = .start; |
| 1103 | 1103 | while (open_span_count != 0) : (open_span_count -= 1) { |
| 1104 | try out.writeAll("</span>"); | |
| 1104 | try buf.appendSlice("</span>"); | |
| 1105 | 1105 | } |
| 1106 | 1106 | if (sgr_num == 0) { |
| 1107 | 1107 | if (sgr_color != 0) return error.UnsupportedColor; |
| 1108 | 1108 | continue; |
| 1109 | 1109 | } |
| 1110 | 1110 | if (sgr_color != 0) { |
| 1111 | try out.print("<span class=\"sgr-{d}_{d}m\">", .{ sgr_color, sgr_num }); | |
| 1111 | try buf.print("<span class=\"sgr-{d}_{d}m\">", .{ sgr_color, sgr_num }); | |
| 1112 | 1112 | } else { |
| 1113 | try out.print("<span class=\"sgr-{d}m\">", .{sgr_num}); | |
| 1113 | try buf.print("<span class=\"sgr-{d}m\">", .{sgr_num}); | |
| 1114 | 1114 | } |
| 1115 | 1115 | open_span_count += 1; |
| 1116 | 1116 | }, |
| ... | ... | @@ -1156,7 +1156,7 @@ fn run( |
| 1156 | 1156 | return result; |
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { | |
| 1159 | fn printShell(out: *Writer, shell_content: []const u8, escape: bool) !void { | |
| 1160 | 1160 | const trimmed_shell_content = mem.trim(u8, shell_content, " \r\n"); |
| 1161 | 1161 | try out.writeAll("<figure><figcaption class=\"shell-cap\">Shell</figcaption><pre><samp>"); |
| 1162 | 1162 | var cmd_cont: bool = false; |
| ... | ... | @@ -1401,11 +1401,11 @@ test "printShell" { |
| 1401 | 1401 | \\</samp></pre></figure> |
| 1402 | 1402 | ; |
| 1403 | 1403 | |
| 1404 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1404 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1405 | 1405 | defer buffer.deinit(); |
| 1406 | 1406 | |
| 1407 | try printShell(buffer.writer(), shell_out, false); | |
| 1408 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1407 | try printShell(&buffer.writer, shell_out, false); | |
| 1408 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1409 | 1409 | } |
| 1410 | 1410 | { |
| 1411 | 1411 | const shell_out = |
| ... | ... | @@ -1418,11 +1418,11 @@ test "printShell" { |
| 1418 | 1418 | \\</samp></pre></figure> |
| 1419 | 1419 | ; |
| 1420 | 1420 | |
| 1421 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1421 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1422 | 1422 | defer buffer.deinit(); |
| 1423 | 1423 | |
| 1424 | try printShell(buffer.writer(), shell_out, false); | |
| 1425 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1424 | try printShell(&buffer.writer, shell_out, false); | |
| 1425 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1426 | 1426 | } |
| 1427 | 1427 | { |
| 1428 | 1428 | const shell_out = "$ zig build test.zig\r\nbuild output\r\n"; |
| ... | ... | @@ -1432,11 +1432,11 @@ test "printShell" { |
| 1432 | 1432 | \\</samp></pre></figure> |
| 1433 | 1433 | ; |
| 1434 | 1434 | |
| 1435 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1435 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1436 | 1436 | defer buffer.deinit(); |
| 1437 | 1437 | |
| 1438 | try printShell(buffer.writer(), shell_out, false); | |
| 1439 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1438 | try printShell(&buffer.writer, shell_out, false); | |
| 1439 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1440 | 1440 | } |
| 1441 | 1441 | { |
| 1442 | 1442 | const shell_out = |
| ... | ... | @@ -1451,11 +1451,11 @@ test "printShell" { |
| 1451 | 1451 | \\</samp></pre></figure> |
| 1452 | 1452 | ; |
| 1453 | 1453 | |
| 1454 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1454 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1455 | 1455 | defer buffer.deinit(); |
| 1456 | 1456 | |
| 1457 | try printShell(buffer.writer(), shell_out, false); | |
| 1458 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1457 | try printShell(&buffer.writer, shell_out, false); | |
| 1458 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1459 | 1459 | } |
| 1460 | 1460 | { |
| 1461 | 1461 | const shell_out = |
| ... | ... | @@ -1472,11 +1472,11 @@ test "printShell" { |
| 1472 | 1472 | \\</samp></pre></figure> |
| 1473 | 1473 | ; |
| 1474 | 1474 | |
| 1475 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1475 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1476 | 1476 | defer buffer.deinit(); |
| 1477 | 1477 | |
| 1478 | try printShell(buffer.writer(), shell_out, false); | |
| 1479 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1478 | try printShell(&buffer.writer, shell_out, false); | |
| 1479 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1480 | 1480 | } |
| 1481 | 1481 | { |
| 1482 | 1482 | const shell_out = |
| ... | ... | @@ -1491,11 +1491,11 @@ test "printShell" { |
| 1491 | 1491 | \\</samp></pre></figure> |
| 1492 | 1492 | ; |
| 1493 | 1493 | |
| 1494 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1494 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1495 | 1495 | defer buffer.deinit(); |
| 1496 | 1496 | |
| 1497 | try printShell(buffer.writer(), shell_out, false); | |
| 1498 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1497 | try printShell(&buffer.writer, shell_out, false); | |
| 1498 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1499 | 1499 | } |
| 1500 | 1500 | { |
| 1501 | 1501 | const shell_out = |
| ... | ... | @@ -1514,11 +1514,11 @@ test "printShell" { |
| 1514 | 1514 | \\</samp></pre></figure> |
| 1515 | 1515 | ; |
| 1516 | 1516 | |
| 1517 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1517 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1518 | 1518 | defer buffer.deinit(); |
| 1519 | 1519 | |
| 1520 | try printShell(buffer.writer(), shell_out, false); | |
| 1521 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1520 | try printShell(&buffer.writer, shell_out, false); | |
| 1521 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1522 | 1522 | } |
| 1523 | 1523 | { |
| 1524 | 1524 | // intentional space after "--build-option1 \" |
| ... | ... | @@ -1536,11 +1536,11 @@ test "printShell" { |
| 1536 | 1536 | \\</samp></pre></figure> |
| 1537 | 1537 | ; |
| 1538 | 1538 | |
| 1539 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1539 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1540 | 1540 | defer buffer.deinit(); |
| 1541 | 1541 | |
| 1542 | try printShell(buffer.writer(), shell_out, false); | |
| 1543 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1542 | try printShell(&buffer.writer, shell_out, false); | |
| 1543 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1544 | 1544 | } |
| 1545 | 1545 | { |
| 1546 | 1546 | const shell_out = |
| ... | ... | @@ -1553,11 +1553,11 @@ test "printShell" { |
| 1553 | 1553 | \\</samp></pre></figure> |
| 1554 | 1554 | ; |
| 1555 | 1555 | |
| 1556 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1556 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1557 | 1557 | defer buffer.deinit(); |
| 1558 | 1558 | |
| 1559 | try printShell(buffer.writer(), shell_out, false); | |
| 1560 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1559 | try printShell(&buffer.writer, shell_out, false); | |
| 1560 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1561 | 1561 | } |
| 1562 | 1562 | { |
| 1563 | 1563 | const shell_out = |
| ... | ... | @@ -1572,11 +1572,11 @@ test "printShell" { |
| 1572 | 1572 | \\</samp></pre></figure> |
| 1573 | 1573 | ; |
| 1574 | 1574 | |
| 1575 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1575 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1576 | 1576 | defer buffer.deinit(); |
| 1577 | 1577 | |
| 1578 | try printShell(buffer.writer(), shell_out, false); | |
| 1579 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1578 | try printShell(&buffer.writer, shell_out, false); | |
| 1579 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1580 | 1580 | } |
| 1581 | 1581 | { |
| 1582 | 1582 | const shell_out = |
| ... | ... | @@ -1587,10 +1587,10 @@ test "printShell" { |
| 1587 | 1587 | \\</samp></pre></figure> |
| 1588 | 1588 | ; |
| 1589 | 1589 | |
| 1590 | var buffer = std.array_list.Managed(u8).init(test_allocator); | |
| 1590 | var buffer: std.Io.Writer.Allocating = .init(test_allocator); | |
| 1591 | 1591 | defer buffer.deinit(); |
| 1592 | 1592 | |
| 1593 | try printShell(buffer.writer(), shell_out, false); | |
| 1594 | try testing.expectEqualSlices(u8, expected, buffer.items); | |
| 1593 | try printShell(&buffer.writer, shell_out, false); | |
| 1594 | try testing.expectEqualSlices(u8, expected, buffer.written()); | |
| 1595 | 1595 | } |
| 1596 | 1596 | } |
tools/gen_outline_atomics.zig+1-1| ... | ... | @@ -49,7 +49,7 @@ pub fn main() !void { |
| 49 | 49 | @tagName(op), n.toBytes(), @tagName(order), |
| 50 | 50 | }); |
| 51 | 51 | try writeFunction(arena, w, name, op, n, order); |
| 52 | try footer.writer().print(" @export(&{s}, .{{ .name = \"{s}\", .linkage = common.linkage, .visibility = common.visibility }});\n", .{ | |
| 52 | try footer.print(" @export(&{s}, .{{ .name = \"{s}\", .linkage = common.linkage, .visibility = common.visibility }});\n", .{ | |
| 53 | 53 | name, name, |
| 54 | 54 | }); |
| 55 | 55 | } |
tools/gen_spirv_spec.zig+8-11| ... | ... | @@ -82,13 +82,11 @@ pub fn main() !void { |
| 82 | 82 | |
| 83 | 83 | try readExtRegistry(&exts, std.fs.cwd(), args[2]); |
| 84 | 84 | |
| 85 | const output_buf = try allocator.alloc(u8, 1024 * 1024); | |
| 86 | var fbs = std.io.fixedBufferStream(output_buf); | |
| 87 | var adapter = fbs.writer().adaptToNewApi(&.{}); | |
| 88 | const w = &adapter.new_interface; | |
| 89 | try render(w, core_spec, exts.items); | |
| 90 | var output: [:0]u8 = @ptrCast(fbs.getWritten()); | |
| 91 | output[output.len] = 0; | |
| 85 | var allocating: std.Io.Writer.Allocating = .init(allocator); | |
| 86 | defer allocating.deinit(); | |
| 87 | try render(&allocating.writer, core_spec, exts.items); | |
| 88 | try allocating.writer.writeByte(0); | |
| 89 | const output = allocating.written()[0 .. allocating.written().len - 1 :0]; | |
| 92 | 90 | |
| 93 | 91 | var tree = try std.zig.Ast.parse(allocator, output, .zig); |
| 94 | 92 | var color: std.zig.Color = .on; |
| ... | ... | @@ -429,10 +427,9 @@ fn renderClass(writer: *std.io.Writer, instructions: []const Instruction) !void |
| 429 | 427 | const Formatter = struct { |
| 430 | 428 | data: []const u8, |
| 431 | 429 | |
| 432 | fn format(f: Formatter, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 430 | fn format(f: Formatter, writer: *std.Io.Writer) std.io.Writer.Error!void { | |
| 433 | 431 | var id_buf: [128]u8 = undefined; |
| 434 | var fbs = std.io.fixedBufferStream(&id_buf); | |
| 435 | const fw = fbs.writer(); | |
| 432 | var fw: std.Io.Writer = .fixed(&id_buf); | |
| 436 | 433 | for (f.data, 0..) |c, i| { |
| 437 | 434 | switch (c) { |
| 438 | 435 | '-', '_', '.', '~', ' ' => fw.writeByte('_') catch return error.WriteFailed, |
| ... | ... | @@ -452,7 +449,7 @@ const Formatter = struct { |
| 452 | 449 | } |
| 453 | 450 | |
| 454 | 451 | // make sure that this won't clobber with zig keywords |
| 455 | try writer.print("{f}", .{std.zig.fmtId(fbs.getWritten())}); | |
| 452 | try writer.print("{f}", .{std.zig.fmtId(fw.buffered())}); | |
| 456 | 453 | } |
| 457 | 454 | }; |
| 458 | 455 |
tools/migrate_langref.zig+22-18| ... | ... | @@ -382,46 +382,50 @@ fn walk(arena: Allocator, tokenizer: *Tokenizer, out_dir: std.fs.Dir, w: anytype |
| 382 | 382 | fatal("unable to create file '{s}': {s}", .{ name, @errorName(err) }); |
| 383 | 383 | }; |
| 384 | 384 | defer file.close(); |
| 385 | var file_buffer: [1024]u8 = undefined; | |
| 386 | var file_writer = file.writer(&file_buffer); | |
| 387 | const code = &file_writer.interface; | |
| 385 | 388 | |
| 386 | 389 | const source = tokenizer.buffer[source_token.start..source_token.end]; |
| 387 | try file.writeAll(std.mem.trim(u8, source[1..], " \t\r\n")); | |
| 388 | try file.writeAll("\n\n"); | |
| 390 | try code.writeAll(std.mem.trim(u8, source[1..], " \t\r\n")); | |
| 391 | try code.writeAll("\n\n"); | |
| 389 | 392 | |
| 390 | 393 | if (just_check_syntax) { |
| 391 | try file.deprecatedWriter().print("// syntax\n", .{}); | |
| 394 | try code.print("// syntax\n", .{}); | |
| 392 | 395 | } else switch (code_kind_id) { |
| 393 | .@"test" => try file.deprecatedWriter().print("// test\n", .{}), | |
| 394 | .lib => try file.deprecatedWriter().print("// lib\n", .{}), | |
| 395 | .test_error => |s| try file.deprecatedWriter().print("// test_error={s}\n", .{s}), | |
| 396 | .test_safety => |s| try file.deprecatedWriter().print("// test_safety={s}\n", .{s}), | |
| 397 | .exe => |s| try file.deprecatedWriter().print("// exe={s}\n", .{@tagName(s)}), | |
| 396 | .@"test" => try code.print("// test\n", .{}), | |
| 397 | .lib => try code.print("// lib\n", .{}), | |
| 398 | .test_error => |s| try code.print("// test_error={s}\n", .{s}), | |
| 399 | .test_safety => |s| try code.print("// test_safety={s}\n", .{s}), | |
| 400 | .exe => |s| try code.print("// exe={s}\n", .{@tagName(s)}), | |
| 398 | 401 | .obj => |opt| if (opt) |s| { |
| 399 | try file.deprecatedWriter().print("// obj={s}\n", .{s}); | |
| 402 | try code.print("// obj={s}\n", .{s}); | |
| 400 | 403 | } else { |
| 401 | try file.deprecatedWriter().print("// obj\n", .{}); | |
| 404 | try code.print("// obj\n", .{}); | |
| 402 | 405 | }, |
| 403 | 406 | } |
| 404 | 407 | |
| 405 | 408 | if (mode != .Debug) |
| 406 | try file.deprecatedWriter().print("// optimize={s}\n", .{@tagName(mode)}); | |
| 409 | try code.print("// optimize={s}\n", .{@tagName(mode)}); | |
| 407 | 410 | |
| 408 | 411 | for (link_objects.items) |link_object| { |
| 409 | try file.deprecatedWriter().print("// link_object={s}\n", .{link_object}); | |
| 412 | try code.print("// link_object={s}\n", .{link_object}); | |
| 410 | 413 | } |
| 411 | 414 | |
| 412 | 415 | if (target_str) |s| |
| 413 | try file.deprecatedWriter().print("// target={s}\n", .{s}); | |
| 416 | try code.print("// target={s}\n", .{s}); | |
| 414 | 417 | |
| 415 | if (link_libc) try file.deprecatedWriter().print("// link_libc\n", .{}); | |
| 416 | if (disable_cache) try file.deprecatedWriter().print("// disable_cache\n", .{}); | |
| 417 | if (verbose_cimport) try file.deprecatedWriter().print("// verbose_cimport\n", .{}); | |
| 418 | if (link_libc) try code.print("// link_libc\n", .{}); | |
| 419 | if (disable_cache) try code.print("// disable_cache\n", .{}); | |
| 420 | if (verbose_cimport) try code.print("// verbose_cimport\n", .{}); | |
| 418 | 421 | |
| 419 | 422 | if (link_mode) |m| |
| 420 | try file.deprecatedWriter().print("// link_mode={s}\n", .{@tagName(m)}); | |
| 423 | try code.print("// link_mode={s}\n", .{@tagName(m)}); | |
| 421 | 424 | |
| 422 | 425 | for (additional_options.items) |o| { |
| 423 | try file.deprecatedWriter().print("// additional_option={s}\n", .{o}); | |
| 426 | try code.print("// additional_option={s}\n", .{o}); | |
| 424 | 427 | } |
| 428 | try code.flush(); | |
| 425 | 429 | try w.print("{{#code|{s}#}}\n", .{basename}); |
| 426 | 430 | } else { |
| 427 | 431 | const close_bracket = while (true) { |
tools/update_crc_catalog.zig+2-3| ... | ... | @@ -88,10 +88,9 @@ pub fn main() anyerror!void { |
| 88 | 88 | \\ |
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | var stream = std.io.fixedBufferStream(catalog_txt); | |
| 92 | const reader = stream.reader(); | |
| 91 | var reader: std.Io.Reader = .fixed(catalog_txt); | |
| 93 | 92 | |
| 94 | while (try reader.readUntilDelimiterOrEofAlloc(arena, '\n', std.math.maxInt(usize))) |line| { | |
| 93 | while (try reader.takeDelimiter('\n')) |line| { | |
| 95 | 94 | if (line.len == 0 or line[0] == '#') |
| 96 | 95 | continue; |
| 97 | 96 |