authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-27 16:05:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-28 18:30:57-07:00
logf7884961c230367cefd3dfbf730ac5277297dc63
treee9f49ef21141371c1643a28ac7aa7347afc43cba
parent4f510dba10872cf7b71d1a48b4dc5879444f89d7

update more to avoid GenericWriter


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 {
784784}
785785
786786/// 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.
788788///
789789/// Returned slice excludes the delimiter. End-of-stream is treated equivalent
790790/// 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 {
814814 return result[0 .. result.len - 1];
815815}
816816
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`
834pub 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
817848/// Returns a slice of the next bytes of buffered data from the stream until
818849/// `delimiter` is found, without advancing the seek position.
819850///
src/link/MachO/dyld_info/Rebase.zig+6-7
......@@ -228,13 +228,13 @@ fn setTypePointer(writer: anytype) !void {
228228fn setSegmentOffset(segment_id: u8, offset: u64, writer: anytype) !void {
229229 log.debug(">>> set segment: {d} and offset: {x}", .{ segment_id, offset });
230230 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);
232232}
233233
234234fn rebaseAddAddr(addr: u64, writer: anytype) !void {
235235 log.debug(">>> rebase with add: {x}", .{addr});
236236 try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB);
237 try std.leb.writeUleb128(writer, addr);
237 try writer.writeUleb128(addr);
238238}
239239
240240fn rebaseTimes(count: usize, writer: anytype) !void {
......@@ -243,15 +243,15 @@ fn rebaseTimes(count: usize, writer: anytype) !void {
243243 try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_IMM_TIMES | @as(u4, @truncate(count)));
244244 } else {
245245 try writer.writeByte(macho.REBASE_OPCODE_DO_REBASE_ULEB_TIMES);
246 try std.leb.writeUleb128(writer, count);
246 try writer.writeUleb128(count);
247247 }
248248}
249249
250250fn rebaseTimesSkip(count: usize, skip: u64, writer: anytype) !void {
251251 log.debug(">>> rebase with count: {d} and skip: {x}", .{ count, skip });
252252 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);
255255}
256256
257257fn addAddr(addr: u64, writer: anytype) !void {
......@@ -264,7 +264,7 @@ fn addAddr(addr: u64, writer: anytype) !void {
264264 }
265265 }
266266 try writer.writeByte(macho.REBASE_OPCODE_ADD_ADDR_ULEB);
267 try std.leb.writeUleb128(writer, addr);
267 try writer.writeUleb128(addr);
268268}
269269
270270fn done(writer: anytype) !void {
......@@ -651,7 +651,6 @@ test "rebase - composite" {
651651
652652const std = @import("std");
653653const assert = std.debug.assert;
654const leb = std.leb;
655654const log = std.log.scoped(.link_dyld_info);
656655const macho = std.macho;
657656const 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
262262 // TODO Implement for special flags.
263263 assert(export_flags & macho.EXPORT_SYMBOL_FLAGS_REEXPORT == 0 and
264264 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);
267267
268268 // Encode the size of the terminal node info.
269269 var size_buf: [@sizeOf(u64)]u8 = undefined;
270270 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);
272272
273273 // Now, write them to the output stream.
274274 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
285285 // Write edge label and offset to next node in trie.
286286 try writer.writeAll(edge.label);
287287 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]);
289289 }
290290}
291291
......@@ -419,7 +419,6 @@ test "ordering bug" {
419419}
420420
421421const assert = std.debug.assert;
422const leb = std.leb;
423422const log = std.log.scoped(.macho);
424423const macho = std.macho;
425424const mem = std.mem;
src/link/MachO/dyld_info/bind.zig+6-7
......@@ -605,7 +605,7 @@ pub const LazyBind = struct {
605605fn setSegmentOffset(segment_id: u8, offset: u64, writer: *std.Io.Writer) !void {
606606 log.debug(">>> set segment: {d} and offset: {x}", .{ segment_id, offset });
607607 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);
609609}
610610
611611fn setSymbol(name: []const u8, flags: u8, writer: *std.Io.Writer) !void {
......@@ -639,7 +639,7 @@ fn setDylibOrdinal(ordinal: i16, writer: *std.Io.Writer) !void {
639639 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | @as(u4, @truncate(cast)));
640640 } else {
641641 try writer.writeByte(macho.BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB);
642 try std.leb.writeUleb128(writer, cast);
642 try writer.writeUleb128(cast);
643643 }
644644 }
645645}
......@@ -667,20 +667,20 @@ fn doBindAddAddr(addr: u64, writer: *std.Io.Writer) !void {
667667 }
668668 }
669669 try writer.writeByte(macho.BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB);
670 try std.leb.writeUleb128(writer, addr);
670 try writer.writeUleb128(addr);
671671}
672672
673673fn doBindTimesSkip(count: usize, skip: u64, writer: *std.Io.Writer) !void {
674674 log.debug(">>> bind with count: {d} and skip: {x}", .{ count, skip });
675675 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);
678678}
679679
680680fn addAddr(addr: u64, writer: *std.Io.Writer) !void {
681681 log.debug(">>> add: {x}", .{addr});
682682 try writer.writeByte(macho.BIND_OPCODE_ADD_ADDR_ULEB);
683 try std.leb.writeUleb128(writer, addr);
683 try writer.writeUleb128(addr);
684684}
685685
686686fn done(writer: *std.Io.Writer) !void {
......@@ -689,7 +689,6 @@ fn done(writer: *std.Io.Writer) !void {
689689}
690690
691691const assert = std.debug.assert;
692const leb = std.leb;
693692const log = std.log.scoped(.link_dyld_info);
694693const macho = std.macho;
695694const mem = std.mem;
test/standalone/run_output_paths/create_file.zig+2-1
......@@ -10,7 +10,8 @@ pub fn main() !void {
1010 dir_name, .{});
1111 const file_name = args.next().?;
1212 const file = try dir.createFile(file_name, .{});
13 try file.deprecatedWriter().print(
13 var file_writer = file.writer(&.{});
14 try file_writer.interface.print(
1415 \\{s}
1516 \\{s}
1617 \\Hello, world!
tools/doctest.zig+45-45
......@@ -7,6 +7,7 @@ const process = std.process;
77const Allocator = std.mem.Allocator;
88const testing = std.testing;
99const getExternalExecutor = std.zig.system.getExternalExecutor;
10const Writer = std.Io.Writer;
1011
1112const max_doc_file_size = 10 * 1024 * 1024;
1213
......@@ -108,7 +109,7 @@ pub fn main() !void {
108109
109110fn printOutput(
110111 arena: Allocator,
111 out: anytype,
112 out: *Writer,
112113 code: Code,
113114 /// Relative to this process' cwd.
114115 tmp_dir_path: []const u8,
......@@ -610,7 +611,7 @@ fn dumpArgs(args: []const []const u8) void {
610611 std.debug.print("\n", .{});
611612}
612613
613fn printSourceBlock(arena: Allocator, out: anytype, source_bytes: []const u8, name: []const u8) !void {
614fn printSourceBlock(arena: Allocator, out: *Writer, source_bytes: []const u8, name: []const u8) !void {
614615 try out.print("<figure><figcaption class=\"{s}-cap\"><cite class=\"file\">{s}</cite></figcaption><pre>", .{
615616 "zig", name,
616617 });
......@@ -618,7 +619,7 @@ fn printSourceBlock(arena: Allocator, out: anytype, source_bytes: []const u8, na
618619 try out.writeAll("</pre></figure>");
619620}
620621
621fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void {
622fn tokenizeAndPrint(arena: Allocator, out: *Writer, raw_src: []const u8) !void {
622623 const src_non_terminated = mem.trim(u8, raw_src, " \r\n");
623624 const src = try arena.dupeZ(u8, src_non_terminated);
624625
......@@ -846,7 +847,7 @@ fn tokenizeAndPrint(arena: Allocator, out: anytype, raw_src: []const u8) !void {
846847 try out.writeAll("</code>");
847848}
848849
849fn writeEscapedLines(out: anytype, text: []const u8) !void {
850fn writeEscapedLines(out: *Writer, text: []const u8) !void {
850851 return writeEscaped(out, text);
851852}
852853
......@@ -983,7 +984,7 @@ fn escapeHtml(allocator: Allocator, input: []const u8) ![]u8 {
983984 return try buf.toOwnedSlice();
984985}
985986
986fn writeEscaped(out: anytype, input: []const u8) !void {
987fn writeEscaped(out: *Writer, input: []const u8) !void {
987988 for (input) |c| {
988989 try switch (c) {
989990 '&' => out.writeAll("&amp;"),
......@@ -1014,7 +1015,6 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 {
10141015 var buf = std.array_list.Managed(u8).init(allocator);
10151016 defer buf.deinit();
10161017
1017 var out = buf.writer();
10181018 var sgr_param_start_index: usize = undefined;
10191019 var sgr_num: u8 = undefined;
10201020 var sgr_color: u8 = undefined;
......@@ -1037,10 +1037,10 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 {
10371037 .start => switch (c) {
10381038 '\x1b' => state = .escape,
10391039 '\n' => {
1040 try out.writeByte(c);
1040 try buf.append(c);
10411041 last_new_line = buf.items.len;
10421042 },
1043 else => try out.writeByte(c),
1043 else => try buf.append(c),
10441044 },
10451045 .escape => switch (c) {
10461046 '[' => state = .lbracket,
......@@ -1101,16 +1101,16 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 {
11011101 'm' => {
11021102 state = .start;
11031103 while (open_span_count != 0) : (open_span_count -= 1) {
1104 try out.writeAll("</span>");
1104 try buf.appendSlice("</span>");
11051105 }
11061106 if (sgr_num == 0) {
11071107 if (sgr_color != 0) return error.UnsupportedColor;
11081108 continue;
11091109 }
11101110 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 });
11121112 } else {
1113 try out.print("<span class=\"sgr-{d}m\">", .{sgr_num});
1113 try buf.print("<span class=\"sgr-{d}m\">", .{sgr_num});
11141114 }
11151115 open_span_count += 1;
11161116 },
......@@ -1156,7 +1156,7 @@ fn run(
11561156 return result;
11571157}
11581158
1159fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void {
1159fn printShell(out: *Writer, shell_content: []const u8, escape: bool) !void {
11601160 const trimmed_shell_content = mem.trim(u8, shell_content, " \r\n");
11611161 try out.writeAll("<figure><figcaption class=\"shell-cap\">Shell</figcaption><pre><samp>");
11621162 var cmd_cont: bool = false;
......@@ -1401,11 +1401,11 @@ test "printShell" {
14011401 \\</samp></pre></figure>
14021402 ;
14031403
1404 var buffer = std.array_list.Managed(u8).init(test_allocator);
1404 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
14051405 defer buffer.deinit();
14061406
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());
14091409 }
14101410 {
14111411 const shell_out =
......@@ -1418,11 +1418,11 @@ test "printShell" {
14181418 \\</samp></pre></figure>
14191419 ;
14201420
1421 var buffer = std.array_list.Managed(u8).init(test_allocator);
1421 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
14221422 defer buffer.deinit();
14231423
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());
14261426 }
14271427 {
14281428 const shell_out = "$ zig build test.zig\r\nbuild output\r\n";
......@@ -1432,11 +1432,11 @@ test "printShell" {
14321432 \\</samp></pre></figure>
14331433 ;
14341434
1435 var buffer = std.array_list.Managed(u8).init(test_allocator);
1435 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
14361436 defer buffer.deinit();
14371437
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());
14401440 }
14411441 {
14421442 const shell_out =
......@@ -1451,11 +1451,11 @@ test "printShell" {
14511451 \\</samp></pre></figure>
14521452 ;
14531453
1454 var buffer = std.array_list.Managed(u8).init(test_allocator);
1454 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
14551455 defer buffer.deinit();
14561456
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());
14591459 }
14601460 {
14611461 const shell_out =
......@@ -1472,11 +1472,11 @@ test "printShell" {
14721472 \\</samp></pre></figure>
14731473 ;
14741474
1475 var buffer = std.array_list.Managed(u8).init(test_allocator);
1475 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
14761476 defer buffer.deinit();
14771477
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());
14801480 }
14811481 {
14821482 const shell_out =
......@@ -1491,11 +1491,11 @@ test "printShell" {
14911491 \\</samp></pre></figure>
14921492 ;
14931493
1494 var buffer = std.array_list.Managed(u8).init(test_allocator);
1494 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
14951495 defer buffer.deinit();
14961496
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());
14991499 }
15001500 {
15011501 const shell_out =
......@@ -1514,11 +1514,11 @@ test "printShell" {
15141514 \\</samp></pre></figure>
15151515 ;
15161516
1517 var buffer = std.array_list.Managed(u8).init(test_allocator);
1517 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
15181518 defer buffer.deinit();
15191519
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());
15221522 }
15231523 {
15241524 // intentional space after "--build-option1 \"
......@@ -1536,11 +1536,11 @@ test "printShell" {
15361536 \\</samp></pre></figure>
15371537 ;
15381538
1539 var buffer = std.array_list.Managed(u8).init(test_allocator);
1539 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
15401540 defer buffer.deinit();
15411541
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());
15441544 }
15451545 {
15461546 const shell_out =
......@@ -1553,11 +1553,11 @@ test "printShell" {
15531553 \\</samp></pre></figure>
15541554 ;
15551555
1556 var buffer = std.array_list.Managed(u8).init(test_allocator);
1556 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
15571557 defer buffer.deinit();
15581558
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());
15611561 }
15621562 {
15631563 const shell_out =
......@@ -1572,11 +1572,11 @@ test "printShell" {
15721572 \\</samp></pre></figure>
15731573 ;
15741574
1575 var buffer = std.array_list.Managed(u8).init(test_allocator);
1575 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
15761576 defer buffer.deinit();
15771577
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());
15801580 }
15811581 {
15821582 const shell_out =
......@@ -1587,10 +1587,10 @@ test "printShell" {
15871587 \\</samp></pre></figure>
15881588 ;
15891589
1590 var buffer = std.array_list.Managed(u8).init(test_allocator);
1590 var buffer: std.Io.Writer.Allocating = .init(test_allocator);
15911591 defer buffer.deinit();
15921592
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());
15951595 }
15961596}
tools/gen_outline_atomics.zig+1-1
......@@ -49,7 +49,7 @@ pub fn main() !void {
4949 @tagName(op), n.toBytes(), @tagName(order),
5050 });
5151 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", .{
5353 name, name,
5454 });
5555 }
tools/gen_spirv_spec.zig+8-11
......@@ -82,13 +82,11 @@ pub fn main() !void {
8282
8383 try readExtRegistry(&exts, std.fs.cwd(), args[2]);
8484
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];
9290
9391 var tree = try std.zig.Ast.parse(allocator, output, .zig);
9492 var color: std.zig.Color = .on;
......@@ -429,10 +427,9 @@ fn renderClass(writer: *std.io.Writer, instructions: []const Instruction) !void
429427const Formatter = struct {
430428 data: []const u8,
431429
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 {
433431 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);
436433 for (f.data, 0..) |c, i| {
437434 switch (c) {
438435 '-', '_', '.', '~', ' ' => fw.writeByte('_') catch return error.WriteFailed,
......@@ -452,7 +449,7 @@ const Formatter = struct {
452449 }
453450
454451 // 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())});
456453 }
457454};
458455
tools/migrate_langref.zig+22-18
......@@ -382,46 +382,50 @@ fn walk(arena: Allocator, tokenizer: *Tokenizer, out_dir: std.fs.Dir, w: anytype
382382 fatal("unable to create file '{s}': {s}", .{ name, @errorName(err) });
383383 };
384384 defer file.close();
385 var file_buffer: [1024]u8 = undefined;
386 var file_writer = file.writer(&file_buffer);
387 const code = &file_writer.interface;
385388
386389 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");
389392
390393 if (just_check_syntax) {
391 try file.deprecatedWriter().print("// syntax\n", .{});
394 try code.print("// syntax\n", .{});
392395 } 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)}),
398401 .obj => |opt| if (opt) |s| {
399 try file.deprecatedWriter().print("// obj={s}\n", .{s});
402 try code.print("// obj={s}\n", .{s});
400403 } else {
401 try file.deprecatedWriter().print("// obj\n", .{});
404 try code.print("// obj\n", .{});
402405 },
403406 }
404407
405408 if (mode != .Debug)
406 try file.deprecatedWriter().print("// optimize={s}\n", .{@tagName(mode)});
409 try code.print("// optimize={s}\n", .{@tagName(mode)});
407410
408411 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});
410413 }
411414
412415 if (target_str) |s|
413 try file.deprecatedWriter().print("// target={s}\n", .{s});
416 try code.print("// target={s}\n", .{s});
414417
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", .{});
418421
419422 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)});
421424
422425 for (additional_options.items) |o| {
423 try file.deprecatedWriter().print("// additional_option={s}\n", .{o});
426 try code.print("// additional_option={s}\n", .{o});
424427 }
428 try code.flush();
425429 try w.print("{{#code|{s}#}}\n", .{basename});
426430 } else {
427431 const close_bracket = while (true) {
tools/update_crc_catalog.zig+2-3
......@@ -88,10 +88,9 @@ pub fn main() anyerror!void {
8888 \\
8989 );
9090
91 var stream = std.io.fixedBufferStream(catalog_txt);
92 const reader = stream.reader();
91 var reader: std.Io.Reader = .fixed(catalog_txt);
9392
94 while (try reader.readUntilDelimiterOrEofAlloc(arena, '\n', std.math.maxInt(usize))) |line| {
93 while (try reader.takeDelimiter('\n')) |line| {
9594 if (line.len == 0 or line[0] == '#')
9695 continue;
9796