authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 09:41:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 22:43:52-07:00
logfac5fe57beb3ee34d5687da4258be22f0ed2f2f3
treee25921f5c1793af0883120c25b0d1f7980008481
parentfc310ee7bcbe7b96cc46f993277cc3933e4a0fda

std.io.Writer.Allocating: rename interface to writer


8 files changed, 37 insertions(+), 37 deletions(-)

lib/std/Build/Step/CheckObject.zig+6-6
......@@ -1380,8 +1380,8 @@ const MachODumper = struct {
13801380 },
13811381 macho.BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM => {
13821382 name_buf.clearRetainingCapacity();
1383 try br.streamDelimiterLimit(&name_buf, 0, .limited(std.math.maxInt(u32)));
1384 try name_buf.writeByte(0);
1383 _ = try br.streamDelimiterLimit(&name_buf.writer, 0, .limited(std.math.maxInt(u32)));
1384 try name_buf.writer.writeByte(0);
13851385 },
13861386 macho.BIND_OPCODE_SET_ADDEND_SLEB => {
13871387 addend = try br.takeLeb128(i64);
......@@ -1588,7 +1588,7 @@ const MachODumper = struct {
15881588
15891589 var aw: std.io.Writer.Allocating = .init(gpa);
15901590 defer aw.deinit();
1591 const bw = &aw.interface;
1591 const bw = &aw.writer;
15921592
15931593 switch (check.kind) {
15941594 .headers => {
......@@ -1741,7 +1741,7 @@ const ElfDumper = struct {
17411741
17421742 var aw: std.io.Writer.Allocating = .init(gpa);
17431743 defer aw.deinit();
1744 const bw = &aw.interface;
1744 const bw = &aw.writer;
17451745
17461746 switch (check.kind) {
17471747 .archive_symtab => if (ctx.symtab.len > 0) {
......@@ -1888,7 +1888,7 @@ const ElfDumper = struct {
18881888
18891889 var aw: std.io.Writer.Allocating = .init(gpa);
18901890 defer aw.deinit();
1891 const bw = &aw.interface;
1891 const bw = &aw.writer;
18921892
18931893 switch (check.kind) {
18941894 .headers => {
......@@ -2338,7 +2338,7 @@ const WasmDumper = struct {
23382338
23392339 var aw: std.io.Writer.Allocating = .init(gpa);
23402340 defer aw.deinit();
2341 const bw = &aw.interface;
2341 const bw = &aw.writer;
23422342
23432343 parseAndDumpInner(step, check, &br, bw) catch |err| switch (err) {
23442344 error.EndOfStream => try bw.writeAll("\n<UnexpectedEndOfStream>"),
lib/std/Build/Step/ConfigHeader.zig+6-6
......@@ -198,7 +198,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
198198
199199 var aw: std.io.Writer.Allocating = .init(gpa);
200200 defer aw.deinit();
201 const bw = &aw.interface;
201 const bw = &aw.writer;
202202
203203 const header_text = "This file was generated by ConfigHeader using the Zig Build System.";
204204 const c_generated_line = "/* " ++ header_text ++ " */\n";
......@@ -335,7 +335,7 @@ fn render_autoconf_at(
335335) !void {
336336 const build = step.owner;
337337 const allocator = build.allocator;
338 const bw = &aw.interface;
338 const bw = &aw.writer;
339339
340340 const used = allocator.alloc(bool, values.count()) catch @panic("OOM");
341341 for (used) |*u| u.* = false;
......@@ -753,17 +753,17 @@ fn testReplaceVariablesAutoconfAt(
753753 expected: []const u8,
754754 values: std.StringArrayHashMap(Value),
755755) !void {
756 var output: std.io.Writer.Allocating = .init(allocator);
757 defer output.deinit();
756 var aw: std.io.Writer.Allocating = .init(allocator);
757 defer aw.deinit();
758758
759759 const used = try allocator.alloc(bool, values.count());
760760 for (used) |*u| u.* = false;
761761 defer allocator.free(used);
762762
763 try expand_variables_autoconf_at(&output.interface, contents, values, used);
763 try expand_variables_autoconf_at(&aw.writer, contents, values, used);
764764
765765 for (used) |u| if (!u) return error.UnusedValue;
766 try std.testing.expectEqualStrings(expected, output.getWritten());
766 try std.testing.expectEqualStrings(expected, aw.getWritten());
767767}
768768
769769fn testReplaceVariablesCMake(
lib/std/array_list.zig+1-1
......@@ -941,7 +941,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?mem.Alig
941941 try self.ensureUnusedCapacity(gpa, fmt.len);
942942 var aw: std.io.Writer.Allocating = .fromArrayList(gpa, self);
943943 defer self.* = aw.toArrayList();
944 return aw.interface.print(fmt, args) catch |err| switch (err) {
944 return aw.writer.print(fmt, args) catch |err| switch (err) {
945945 error.WriteFailed => return error.OutOfMemory,
946946 };
947947 }
lib/std/debug.zig+2-2
......@@ -307,7 +307,7 @@ test dumpHexFallible {
307307 var aw: std.io.Writer.Allocating = .init(std.testing.allocator);
308308 defer aw.deinit();
309309
310 try dumpHexFallible(&aw.interface, .no_color, bytes);
310 try dumpHexFallible(&aw.writer, .no_color, bytes);
311311 const expected = try std.fmt.allocPrint(std.testing.allocator,
312312 \\{x:0>[2]} 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF .."3DUfw........
313313 \\{x:0>[2]} 01 12 13 ...
......@@ -1230,7 +1230,7 @@ fn printLineFromFileAnyOs(writer: *Writer, source_location: SourceLocation) !voi
12301230test printLineFromFileAnyOs {
12311231 var aw: Writer.Allocating = .init(std.testing.allocator);
12321232 defer aw.deinit();
1233 const output_stream = &aw.interface;
1233 const output_stream = &aw.writer;
12341234
12351235 const allocator = std.testing.allocator;
12361236 const join = std.fs.path.join;
lib/std/fmt.zig+2-2
......@@ -759,7 +759,7 @@ pub fn count(comptime fmt: []const u8, args: anytype) usize {
759759pub fn allocPrint(gpa: Allocator, comptime fmt: []const u8, args: anytype) Allocator.Error![]u8 {
760760 var aw = try Writer.Allocating.initCapacity(gpa, fmt.len);
761761 defer aw.deinit();
762 aw.interface.print(fmt, args) catch |err| switch (err) {
762 aw.writer.print(fmt, args) catch |err| switch (err) {
763763 error.WriteFailed => return error.OutOfMemory,
764764 };
765765 return aw.toOwnedSlice();
......@@ -773,7 +773,7 @@ pub fn allocPrintSentinel(
773773) Allocator.Error![:sentinel]u8 {
774774 var aw = try Writer.Allocating.initCapacity(gpa, fmt.len);
775775 defer aw.deinit();
776 aw.interface.print(fmt, args) catch |err| switch (err) {
776 aw.writer.print(fmt, args) catch |err| switch (err) {
777777 error.WriteFailed => return error.OutOfMemory,
778778 };
779779 return aw.toOwnedSliceSentinel(sentinel);
lib/std/io/Writer.zig+16-16
......@@ -2056,12 +2056,12 @@ pub fn Hashed(comptime Hasher: type) type {
20562056/// When using this API, it is not necessary to call `flush`.
20572057pub const Allocating = struct {
20582058 allocator: Allocator,
2059 interface: Writer,
2059 writer: Writer,
20602060
20612061 pub fn init(allocator: Allocator) Allocating {
20622062 return .{
20632063 .allocator = allocator,
2064 .interface = .{
2064 .writer = .{
20652065 .buffer = &.{},
20662066 .vtable = &vtable,
20672067 },
......@@ -2071,7 +2071,7 @@ pub const Allocating = struct {
20712071 pub fn initCapacity(allocator: Allocator, capacity: usize) error{OutOfMemory}!Allocating {
20722072 return .{
20732073 .allocator = allocator,
2074 .interface = .{
2074 .writer = .{
20752075 .buffer = try allocator.alloc(u8, capacity),
20762076 .vtable = &vtable,
20772077 },
......@@ -2081,7 +2081,7 @@ pub const Allocating = struct {
20812081 pub fn initOwnedSlice(allocator: Allocator, slice: []u8) Allocating {
20822082 return .{
20832083 .allocator = allocator,
2084 .interface = .{
2084 .writer = .{
20852085 .buffer = slice,
20862086 .vtable = &vtable,
20872087 },
......@@ -2093,7 +2093,7 @@ pub const Allocating = struct {
20932093 defer array_list.* = .empty;
20942094 return .{
20952095 .allocator = allocator,
2096 .interface = .{
2096 .writer = .{
20972097 .vtable = &vtable,
20982098 .buffer = array_list.allocatedSlice(),
20992099 .end = array_list.items.len,
......@@ -2108,14 +2108,14 @@ pub const Allocating = struct {
21082108 };
21092109
21102110 pub fn deinit(a: *Allocating) void {
2111 a.allocator.free(a.interface.buffer);
2111 a.allocator.free(a.writer.buffer);
21122112 a.* = undefined;
21132113 }
21142114
21152115 /// Returns an array list that takes ownership of the allocated memory.
21162116 /// Resets the `Allocating` to an empty state.
21172117 pub fn toArrayList(a: *Allocating) std.ArrayListUnmanaged(u8) {
2118 const w = &a.interface;
2118 const w = &a.writer;
21192119 const result: std.ArrayListUnmanaged(u8) = .{
21202120 .items = w.buffer[0..w.end],
21212121 .capacity = w.buffer.len,
......@@ -2137,13 +2137,13 @@ pub const Allocating = struct {
21372137 }
21382138
21392139 pub fn getWritten(a: *Allocating) []u8 {
2140 return a.interface.buffered();
2140 return a.writer.buffered();
21412141 }
21422142
21432143 pub fn shrinkRetainingCapacity(a: *Allocating, new_len: usize) void {
2144 const shrink_by = a.interface.end - new_len;
2145 a.interface.end = new_len;
2146 a.interface.count -= shrink_by;
2144 const shrink_by = a.writer.end - new_len;
2145 a.writer.end = new_len;
2146 a.writer.count -= shrink_by;
21472147 }
21482148
21492149 pub fn clearRetainingCapacity(a: *Allocating) void {
......@@ -2151,7 +2151,7 @@ pub const Allocating = struct {
21512151 }
21522152
21532153 fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {
2154 const a: *Allocating = @fieldParentPtr("interface", w);
2154 const a: *Allocating = @fieldParentPtr("writer", w);
21552155 const gpa = a.allocator;
21562156 const pattern = data[data.len - 1];
21572157 const splat_len = pattern.len * splat;
......@@ -2177,7 +2177,7 @@ pub const Allocating = struct {
21772177
21782178 fn sendFile(w: *Writer, file_reader: *File.Reader, limit: std.io.Limit) FileError!usize {
21792179 if (File.Handle == void) return error.Unimplemented;
2180 const a: *Allocating = @fieldParentPtr("interface", w);
2180 const a: *Allocating = @fieldParentPtr("writer", w);
21812181 const gpa = a.allocator;
21822182 var list = a.toArrayList();
21832183 defer setArrayList(a, list);
......@@ -2194,14 +2194,14 @@ pub const Allocating = struct {
21942194 }
21952195
21962196 fn setArrayList(a: *Allocating, list: std.ArrayListUnmanaged(u8)) void {
2197 a.interface.buffer = list.allocatedSlice();
2198 a.interface.end = list.items.len;
2197 a.writer.buffer = list.allocatedSlice();
2198 a.writer.end = list.items.len;
21992199 }
22002200
22012201 test Allocating {
22022202 var a: Allocating = .init(std.testing.allocator);
22032203 defer a.deinit();
2204 const w = &a.interface;
2204 const w = &a.writer;
22052205
22062206 const x: i32 = 42;
22072207 const y: i32 = 1234;
lib/std/zig/llvm/Builder.zig+1-1
......@@ -8962,7 +8962,7 @@ pub fn getIntrinsic(
89628962 const name = name: {
89638963 {
89648964 var aw: Writer.Allocating = .fromArrayList(self.gpa, &self.strtab_string_bytes);
8965 const w = &aw.interface;
8965 const w = &aw.writer;
89668966 defer self.strtab_string_bytes = aw.toArrayList();
89678967 w.print("llvm.{s}", .{@tagName(id)}) catch return error.OutOfMemory;
89688968 for (overload) |ty| w.print(".{fm}", .{ty.fmt(self)}) catch return error.OutOfMemory;
src/Sema.zig+3-3
......@@ -3026,7 +3026,7 @@ pub fn createTypeName(
30263026
30273027 var aw: std.io.Writer.Allocating = .init(gpa);
30283028 defer aw.deinit();
3029 const bw = &aw.interface;
3029 const bw = &aw.writer;
30303030 bw.print("{f}(", .{block.type_name_ctx.fmt(ip)}) catch return error.OutOfMemory;
30313031
30323032 var arg_i: usize = 0;
......@@ -5908,7 +5908,7 @@ fn zirCompileLog(
59085908
59095909 var aw: std.io.Writer.Allocating = .init(gpa);
59105910 defer aw.deinit();
5911 const bw = &aw.interface;
5911 const bw = &aw.writer;
59125912
59135913 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
59145914 const src_node = extra.data.src_node;
......@@ -37224,7 +37224,7 @@ fn notePathToComptimeAllocPtr(sema: *Sema, msg: *Zcu.ErrorMsg, src: LazySrcLoc,
3722437224 const inter_name = try std.fmt.allocPrint(arena, "v{d}", .{intermediate_value_count});
3722537225 const deriv_start = @import("print_value.zig").printPtrDerivation(
3722637226 derivation,
37227 &second_path_aw.interface,
37227 &second_path_aw.writer,
3722837228 pt,
3722937229 .lvalue,
3723037230 .{ .str = inter_name },