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 {...@@ -1380,8 +1380,8 @@ const MachODumper = struct {
1380 },1380 },
1381 macho.BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM => {1381 macho.BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM => {
1382 name_buf.clearRetainingCapacity();1382 name_buf.clearRetainingCapacity();
1383 try br.streamDelimiterLimit(&name_buf, 0, .limited(std.math.maxInt(u32)));1383 _ = try br.streamDelimiterLimit(&name_buf.writer, 0, .limited(std.math.maxInt(u32)));
1384 try name_buf.writeByte(0);1384 try name_buf.writer.writeByte(0);
1385 },1385 },
1386 macho.BIND_OPCODE_SET_ADDEND_SLEB => {1386 macho.BIND_OPCODE_SET_ADDEND_SLEB => {
1387 addend = try br.takeLeb128(i64);1387 addend = try br.takeLeb128(i64);
...@@ -1588,7 +1588,7 @@ const MachODumper = struct {...@@ -1588,7 +1588,7 @@ const MachODumper = struct {
15881588
1589 var aw: std.io.Writer.Allocating = .init(gpa);1589 var aw: std.io.Writer.Allocating = .init(gpa);
1590 defer aw.deinit();1590 defer aw.deinit();
1591 const bw = &aw.interface;1591 const bw = &aw.writer;
15921592
1593 switch (check.kind) {1593 switch (check.kind) {
1594 .headers => {1594 .headers => {
...@@ -1741,7 +1741,7 @@ const ElfDumper = struct {...@@ -1741,7 +1741,7 @@ const ElfDumper = struct {
17411741
1742 var aw: std.io.Writer.Allocating = .init(gpa);1742 var aw: std.io.Writer.Allocating = .init(gpa);
1743 defer aw.deinit();1743 defer aw.deinit();
1744 const bw = &aw.interface;1744 const bw = &aw.writer;
17451745
1746 switch (check.kind) {1746 switch (check.kind) {
1747 .archive_symtab => if (ctx.symtab.len > 0) {1747 .archive_symtab => if (ctx.symtab.len > 0) {
...@@ -1888,7 +1888,7 @@ const ElfDumper = struct {...@@ -1888,7 +1888,7 @@ const ElfDumper = struct {
18881888
1889 var aw: std.io.Writer.Allocating = .init(gpa);1889 var aw: std.io.Writer.Allocating = .init(gpa);
1890 defer aw.deinit();1890 defer aw.deinit();
1891 const bw = &aw.interface;1891 const bw = &aw.writer;
18921892
1893 switch (check.kind) {1893 switch (check.kind) {
1894 .headers => {1894 .headers => {
...@@ -2338,7 +2338,7 @@ const WasmDumper = struct {...@@ -2338,7 +2338,7 @@ const WasmDumper = struct {
23382338
2339 var aw: std.io.Writer.Allocating = .init(gpa);2339 var aw: std.io.Writer.Allocating = .init(gpa);
2340 defer aw.deinit();2340 defer aw.deinit();
2341 const bw = &aw.interface;2341 const bw = &aw.writer;
23422342
2343 parseAndDumpInner(step, check, &br, bw) catch |err| switch (err) {2343 parseAndDumpInner(step, check, &br, bw) catch |err| switch (err) {
2344 error.EndOfStream => try bw.writeAll("\n<UnexpectedEndOfStream>"),2344 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 {...@@ -198,7 +198,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
198198
199 var aw: std.io.Writer.Allocating = .init(gpa);199 var aw: std.io.Writer.Allocating = .init(gpa);
200 defer aw.deinit();200 defer aw.deinit();
201 const bw = &aw.interface;201 const bw = &aw.writer;
202202
203 const header_text = "This file was generated by ConfigHeader using the Zig Build System.";203 const header_text = "This file was generated by ConfigHeader using the Zig Build System.";
204 const c_generated_line = "/* " ++ header_text ++ " */\n";204 const c_generated_line = "/* " ++ header_text ++ " */\n";
...@@ -335,7 +335,7 @@ fn render_autoconf_at(...@@ -335,7 +335,7 @@ fn render_autoconf_at(
335) !void {335) !void {
336 const build = step.owner;336 const build = step.owner;
337 const allocator = build.allocator;337 const allocator = build.allocator;
338 const bw = &aw.interface;338 const bw = &aw.writer;
339339
340 const used = allocator.alloc(bool, values.count()) catch @panic("OOM");340 const used = allocator.alloc(bool, values.count()) catch @panic("OOM");
341 for (used) |*u| u.* = false;341 for (used) |*u| u.* = false;
...@@ -753,17 +753,17 @@ fn testReplaceVariablesAutoconfAt(...@@ -753,17 +753,17 @@ fn testReplaceVariablesAutoconfAt(
753 expected: []const u8,753 expected: []const u8,
754 values: std.StringArrayHashMap(Value),754 values: std.StringArrayHashMap(Value),
755) !void {755) !void {
756 var output: std.io.Writer.Allocating = .init(allocator);756 var aw: std.io.Writer.Allocating = .init(allocator);
757 defer output.deinit();757 defer aw.deinit();
758758
759 const used = try allocator.alloc(bool, values.count());759 const used = try allocator.alloc(bool, values.count());
760 for (used) |*u| u.* = false;760 for (used) |*u| u.* = false;
761 defer allocator.free(used);761 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
765 for (used) |u| if (!u) return error.UnusedValue;765 for (used) |u| if (!u) return error.UnusedValue;
766 try std.testing.expectEqualStrings(expected, output.getWritten());766 try std.testing.expectEqualStrings(expected, aw.getWritten());
767}767}
768768
769fn testReplaceVariablesCMake(769fn testReplaceVariablesCMake(
lib/std/array_list.zig+1-1
...@@ -941,7 +941,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?mem.Alig...@@ -941,7 +941,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?mem.Alig
941 try self.ensureUnusedCapacity(gpa, fmt.len);941 try self.ensureUnusedCapacity(gpa, fmt.len);
942 var aw: std.io.Writer.Allocating = .fromArrayList(gpa, self);942 var aw: std.io.Writer.Allocating = .fromArrayList(gpa, self);
943 defer self.* = aw.toArrayList();943 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) {
945 error.WriteFailed => return error.OutOfMemory,945 error.WriteFailed => return error.OutOfMemory,
946 };946 };
947 }947 }
lib/std/debug.zig+2-2
...@@ -307,7 +307,7 @@ test dumpHexFallible {...@@ -307,7 +307,7 @@ test dumpHexFallible {
307 var aw: std.io.Writer.Allocating = .init(std.testing.allocator);307 var aw: std.io.Writer.Allocating = .init(std.testing.allocator);
308 defer aw.deinit();308 defer aw.deinit();
309309
310 try dumpHexFallible(&aw.interface, .no_color, bytes);310 try dumpHexFallible(&aw.writer, .no_color, bytes);
311 const expected = try std.fmt.allocPrint(std.testing.allocator,311 const expected = try std.fmt.allocPrint(std.testing.allocator,
312 \\{x:0>[2]} 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF .."3DUfw........312 \\{x:0>[2]} 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF .."3DUfw........
313 \\{x:0>[2]} 01 12 13 ...313 \\{x:0>[2]} 01 12 13 ...
...@@ -1230,7 +1230,7 @@ fn printLineFromFileAnyOs(writer: *Writer, source_location: SourceLocation) !voi...@@ -1230,7 +1230,7 @@ fn printLineFromFileAnyOs(writer: *Writer, source_location: SourceLocation) !voi
1230test printLineFromFileAnyOs {1230test printLineFromFileAnyOs {
1231 var aw: Writer.Allocating = .init(std.testing.allocator);1231 var aw: Writer.Allocating = .init(std.testing.allocator);
1232 defer aw.deinit();1232 defer aw.deinit();
1233 const output_stream = &aw.interface;1233 const output_stream = &aw.writer;
12341234
1235 const allocator = std.testing.allocator;1235 const allocator = std.testing.allocator;
1236 const join = std.fs.path.join;1236 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 {...@@ -759,7 +759,7 @@ pub fn count(comptime fmt: []const u8, args: anytype) usize {
759pub fn allocPrint(gpa: Allocator, comptime fmt: []const u8, args: anytype) Allocator.Error![]u8 {759pub fn allocPrint(gpa: Allocator, comptime fmt: []const u8, args: anytype) Allocator.Error![]u8 {
760 var aw = try Writer.Allocating.initCapacity(gpa, fmt.len);760 var aw = try Writer.Allocating.initCapacity(gpa, fmt.len);
761 defer aw.deinit();761 defer aw.deinit();
762 aw.interface.print(fmt, args) catch |err| switch (err) {762 aw.writer.print(fmt, args) catch |err| switch (err) {
763 error.WriteFailed => return error.OutOfMemory,763 error.WriteFailed => return error.OutOfMemory,
764 };764 };
765 return aw.toOwnedSlice();765 return aw.toOwnedSlice();
...@@ -773,7 +773,7 @@ pub fn allocPrintSentinel(...@@ -773,7 +773,7 @@ pub fn allocPrintSentinel(
773) Allocator.Error![:sentinel]u8 {773) Allocator.Error![:sentinel]u8 {
774 var aw = try Writer.Allocating.initCapacity(gpa, fmt.len);774 var aw = try Writer.Allocating.initCapacity(gpa, fmt.len);
775 defer aw.deinit();775 defer aw.deinit();
776 aw.interface.print(fmt, args) catch |err| switch (err) {776 aw.writer.print(fmt, args) catch |err| switch (err) {
777 error.WriteFailed => return error.OutOfMemory,777 error.WriteFailed => return error.OutOfMemory,
778 };778 };
779 return aw.toOwnedSliceSentinel(sentinel);779 return aw.toOwnedSliceSentinel(sentinel);
lib/std/io/Writer.zig+16-16
...@@ -2056,12 +2056,12 @@ pub fn Hashed(comptime Hasher: type) type {...@@ -2056,12 +2056,12 @@ pub fn Hashed(comptime Hasher: type) type {
2056/// When using this API, it is not necessary to call `flush`.2056/// When using this API, it is not necessary to call `flush`.
2057pub const Allocating = struct {2057pub const Allocating = struct {
2058 allocator: Allocator,2058 allocator: Allocator,
2059 interface: Writer,2059 writer: Writer,
20602060
2061 pub fn init(allocator: Allocator) Allocating {2061 pub fn init(allocator: Allocator) Allocating {
2062 return .{2062 return .{
2063 .allocator = allocator,2063 .allocator = allocator,
2064 .interface = .{2064 .writer = .{
2065 .buffer = &.{},2065 .buffer = &.{},
2066 .vtable = &vtable,2066 .vtable = &vtable,
2067 },2067 },
...@@ -2071,7 +2071,7 @@ pub const Allocating = struct {...@@ -2071,7 +2071,7 @@ pub const Allocating = struct {
2071 pub fn initCapacity(allocator: Allocator, capacity: usize) error{OutOfMemory}!Allocating {2071 pub fn initCapacity(allocator: Allocator, capacity: usize) error{OutOfMemory}!Allocating {
2072 return .{2072 return .{
2073 .allocator = allocator,2073 .allocator = allocator,
2074 .interface = .{2074 .writer = .{
2075 .buffer = try allocator.alloc(u8, capacity),2075 .buffer = try allocator.alloc(u8, capacity),
2076 .vtable = &vtable,2076 .vtable = &vtable,
2077 },2077 },
...@@ -2081,7 +2081,7 @@ pub const Allocating = struct {...@@ -2081,7 +2081,7 @@ pub const Allocating = struct {
2081 pub fn initOwnedSlice(allocator: Allocator, slice: []u8) Allocating {2081 pub fn initOwnedSlice(allocator: Allocator, slice: []u8) Allocating {
2082 return .{2082 return .{
2083 .allocator = allocator,2083 .allocator = allocator,
2084 .interface = .{2084 .writer = .{
2085 .buffer = slice,2085 .buffer = slice,
2086 .vtable = &vtable,2086 .vtable = &vtable,
2087 },2087 },
...@@ -2093,7 +2093,7 @@ pub const Allocating = struct {...@@ -2093,7 +2093,7 @@ pub const Allocating = struct {
2093 defer array_list.* = .empty;2093 defer array_list.* = .empty;
2094 return .{2094 return .{
2095 .allocator = allocator,2095 .allocator = allocator,
2096 .interface = .{2096 .writer = .{
2097 .vtable = &vtable,2097 .vtable = &vtable,
2098 .buffer = array_list.allocatedSlice(),2098 .buffer = array_list.allocatedSlice(),
2099 .end = array_list.items.len,2099 .end = array_list.items.len,
...@@ -2108,14 +2108,14 @@ pub const Allocating = struct {...@@ -2108,14 +2108,14 @@ pub const Allocating = struct {
2108 };2108 };
21092109
2110 pub fn deinit(a: *Allocating) void {2110 pub fn deinit(a: *Allocating) void {
2111 a.allocator.free(a.interface.buffer);2111 a.allocator.free(a.writer.buffer);
2112 a.* = undefined;2112 a.* = undefined;
2113 }2113 }
21142114
2115 /// Returns an array list that takes ownership of the allocated memory.2115 /// Returns an array list that takes ownership of the allocated memory.
2116 /// Resets the `Allocating` to an empty state.2116 /// Resets the `Allocating` to an empty state.
2117 pub fn toArrayList(a: *Allocating) std.ArrayListUnmanaged(u8) {2117 pub fn toArrayList(a: *Allocating) std.ArrayListUnmanaged(u8) {
2118 const w = &a.interface;2118 const w = &a.writer;
2119 const result: std.ArrayListUnmanaged(u8) = .{2119 const result: std.ArrayListUnmanaged(u8) = .{
2120 .items = w.buffer[0..w.end],2120 .items = w.buffer[0..w.end],
2121 .capacity = w.buffer.len,2121 .capacity = w.buffer.len,
...@@ -2137,13 +2137,13 @@ pub const Allocating = struct {...@@ -2137,13 +2137,13 @@ pub const Allocating = struct {
2137 }2137 }
21382138
2139 pub fn getWritten(a: *Allocating) []u8 {2139 pub fn getWritten(a: *Allocating) []u8 {
2140 return a.interface.buffered();2140 return a.writer.buffered();
2141 }2141 }
21422142
2143 pub fn shrinkRetainingCapacity(a: *Allocating, new_len: usize) void {2143 pub fn shrinkRetainingCapacity(a: *Allocating, new_len: usize) void {
2144 const shrink_by = a.interface.end - new_len;2144 const shrink_by = a.writer.end - new_len;
2145 a.interface.end = new_len;2145 a.writer.end = new_len;
2146 a.interface.count -= shrink_by;2146 a.writer.count -= shrink_by;
2147 }2147 }
21482148
2149 pub fn clearRetainingCapacity(a: *Allocating) void {2149 pub fn clearRetainingCapacity(a: *Allocating) void {
...@@ -2151,7 +2151,7 @@ pub const Allocating = struct {...@@ -2151,7 +2151,7 @@ pub const Allocating = struct {
2151 }2151 }
21522152
2153 fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {2153 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);
2155 const gpa = a.allocator;2155 const gpa = a.allocator;
2156 const pattern = data[data.len - 1];2156 const pattern = data[data.len - 1];
2157 const splat_len = pattern.len * splat;2157 const splat_len = pattern.len * splat;
...@@ -2177,7 +2177,7 @@ pub const Allocating = struct {...@@ -2177,7 +2177,7 @@ pub const Allocating = struct {
21772177
2178 fn sendFile(w: *Writer, file_reader: *File.Reader, limit: std.io.Limit) FileError!usize {2178 fn sendFile(w: *Writer, file_reader: *File.Reader, limit: std.io.Limit) FileError!usize {
2179 if (File.Handle == void) return error.Unimplemented;2179 if (File.Handle == void) return error.Unimplemented;
2180 const a: *Allocating = @fieldParentPtr("interface", w);2180 const a: *Allocating = @fieldParentPtr("writer", w);
2181 const gpa = a.allocator;2181 const gpa = a.allocator;
2182 var list = a.toArrayList();2182 var list = a.toArrayList();
2183 defer setArrayList(a, list);2183 defer setArrayList(a, list);
...@@ -2194,14 +2194,14 @@ pub const Allocating = struct {...@@ -2194,14 +2194,14 @@ pub const Allocating = struct {
2194 }2194 }
21952195
2196 fn setArrayList(a: *Allocating, list: std.ArrayListUnmanaged(u8)) void {2196 fn setArrayList(a: *Allocating, list: std.ArrayListUnmanaged(u8)) void {
2197 a.interface.buffer = list.allocatedSlice();2197 a.writer.buffer = list.allocatedSlice();
2198 a.interface.end = list.items.len;2198 a.writer.end = list.items.len;
2199 }2199 }
22002200
2201 test Allocating {2201 test Allocating {
2202 var a: Allocating = .init(std.testing.allocator);2202 var a: Allocating = .init(std.testing.allocator);
2203 defer a.deinit();2203 defer a.deinit();
2204 const w = &a.interface;2204 const w = &a.writer;
22052205
2206 const x: i32 = 42;2206 const x: i32 = 42;
2207 const y: i32 = 1234;2207 const y: i32 = 1234;
lib/std/zig/llvm/Builder.zig+1-1
...@@ -8962,7 +8962,7 @@ pub fn getIntrinsic(...@@ -8962,7 +8962,7 @@ pub fn getIntrinsic(
8962 const name = name: {8962 const name = name: {
8963 {8963 {
8964 var aw: Writer.Allocating = .fromArrayList(self.gpa, &self.strtab_string_bytes);8964 var aw: Writer.Allocating = .fromArrayList(self.gpa, &self.strtab_string_bytes);
8965 const w = &aw.interface;8965 const w = &aw.writer;
8966 defer self.strtab_string_bytes = aw.toArrayList();8966 defer self.strtab_string_bytes = aw.toArrayList();
8967 w.print("llvm.{s}", .{@tagName(id)}) catch return error.OutOfMemory;8967 w.print("llvm.{s}", .{@tagName(id)}) catch return error.OutOfMemory;
8968 for (overload) |ty| w.print(".{fm}", .{ty.fmt(self)}) catch return error.OutOfMemory;8968 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(...@@ -3026,7 +3026,7 @@ pub fn createTypeName(
30263026
3027 var aw: std.io.Writer.Allocating = .init(gpa);3027 var aw: std.io.Writer.Allocating = .init(gpa);
3028 defer aw.deinit();3028 defer aw.deinit();
3029 const bw = &aw.interface;3029 const bw = &aw.writer;
3030 bw.print("{f}(", .{block.type_name_ctx.fmt(ip)}) catch return error.OutOfMemory;3030 bw.print("{f}(", .{block.type_name_ctx.fmt(ip)}) catch return error.OutOfMemory;
30313031
3032 var arg_i: usize = 0;3032 var arg_i: usize = 0;
...@@ -5908,7 +5908,7 @@ fn zirCompileLog(...@@ -5908,7 +5908,7 @@ fn zirCompileLog(
59085908
5909 var aw: std.io.Writer.Allocating = .init(gpa);5909 var aw: std.io.Writer.Allocating = .init(gpa);
5910 defer aw.deinit();5910 defer aw.deinit();
5911 const bw = &aw.interface;5911 const bw = &aw.writer;
59125912
5913 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);5913 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
5914 const src_node = extra.data.src_node;5914 const src_node = extra.data.src_node;
...@@ -37224,7 +37224,7 @@ fn notePathToComptimeAllocPtr(sema: *Sema, msg: *Zcu.ErrorMsg, src: LazySrcLoc,...@@ -37224,7 +37224,7 @@ fn notePathToComptimeAllocPtr(sema: *Sema, msg: *Zcu.ErrorMsg, src: LazySrcLoc,
37224 const inter_name = try std.fmt.allocPrint(arena, "v{d}", .{intermediate_value_count});37224 const inter_name = try std.fmt.allocPrint(arena, "v{d}", .{intermediate_value_count});
37225 const deriv_start = @import("print_value.zig").printPtrDerivation(37225 const deriv_start = @import("print_value.zig").printPtrDerivation(
37226 derivation,37226 derivation,
37227 &second_path_aw.interface,37227 &second_path_aw.writer,
37228 pt,37228 pt,
37229 .lvalue,37229 .lvalue,
37230 .{ .str = inter_name },37230 .{ .str = inter_name },