aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-08-07 22:06:20 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-08-07 22:26:42 -0700
commit94dd28b7f7bdbbebe652d3e7a791bc86591ed9c8 (patch)
tree49c9e9f8c69b800c998b1d7b99fc71f7463d2903 /src
parent3fb86841cc65437c65a6d599117833e260ea797c (diff)
downloadzig-94dd28b7f7bdbbebe652d3e7a791bc86591ed9c8.tar.gz
zig-94dd28b7f7bdbbebe652d3e7a791bc86591ed9c8.zip
std.Io: delete CountingWriter
Diffstat (limited to 'src')
-rw-r--r--src/arch/x86_64/encoder.zig7
-rw-r--r--src/link/Elf.zig9
-rw-r--r--src/link/Elf/synthetic_sections.zig21
-rw-r--r--src/link/MachO/dyld_info/Trie.zig15
4 files changed, 24 insertions, 28 deletions
diff --git a/src/arch/x86_64/encoder.zig b/src/arch/x86_64/encoder.zig
index 43d23af5fc..ed31c068dc 100644
--- a/src/arch/x86_64/encoder.zig
+++ b/src/arch/x86_64/encoder.zig
@@ -1204,11 +1204,10 @@ const TestEncode = struct {
mnemonic: Instruction.Mnemonic,
ops: []const Instruction.Operand,
) !void {
- var stream = std.io.fixedBufferStream(&enc.buffer);
- var count_writer = std.io.countingWriter(stream.writer());
+ var writer: std.Io.Writer = .fixed(&enc.buffer);
const inst: Instruction = try .new(.none, mnemonic, ops);
- try inst.encode(count_writer.writer(), .{});
- enc.index = count_writer.bytes_written;
+ try inst.encode(&writer, .{});
+ enc.index = writer.bufferedLen();
}
fn code(enc: TestEncode) []const u8 {
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 785f200928..be6c050e5e 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -3152,10 +3152,11 @@ fn writeSyntheticSections(self: *Elf) !void {
if (self.section_indexes.gnu_hash) |shndx| {
const shdr = slice.items(.shdr)[shndx];
- var buffer = try std.ArrayList(u8).initCapacity(gpa, self.gnu_hash.size());
- defer buffer.deinit();
- try self.gnu_hash.write(self, buffer.writer());
- try self.pwriteAll(buffer.items, shdr.sh_offset);
+ var aw: std.Io.Writer.Allocating = .init(gpa);
+ try aw.ensureUnusedCapacity(self.gnu_hash.size());
+ defer aw.deinit();
+ try self.gnu_hash.write(self, &aw.writer);
+ try self.pwriteAll(aw.getWritten(), shdr.sh_offset);
}
if (self.section_indexes.versym) |shndx| {
diff --git a/src/link/Elf/synthetic_sections.zig b/src/link/Elf/synthetic_sections.zig
index 2ab71d8c49..efad44f68b 100644
--- a/src/link/Elf/synthetic_sections.zig
+++ b/src/link/Elf/synthetic_sections.zig
@@ -1237,17 +1237,14 @@ pub const GnuHashSection = struct {
return header_size + hash.num_bloom * 8 + hash.num_buckets * 4 + hash.num_exports * 4;
}
- pub fn write(hash: GnuHashSection, elf_file: *Elf, writer: anytype) !void {
+ pub fn write(hash: GnuHashSection, elf_file: *Elf, writer: *std.Io.Writer) !void {
const exports = getExports(elf_file);
const export_off = elf_file.dynsym.count() - hash.num_exports;
- var counting = std.io.countingWriter(writer);
- const cwriter = counting.writer();
-
- try cwriter.writeInt(u32, hash.num_buckets, .little);
- try cwriter.writeInt(u32, export_off, .little);
- try cwriter.writeInt(u32, hash.num_bloom, .little);
- try cwriter.writeInt(u32, bloom_shift, .little);
+ try writer.writeInt(u32, hash.num_buckets, .little);
+ try writer.writeInt(u32, export_off, .little);
+ try writer.writeInt(u32, hash.num_bloom, .little);
+ try writer.writeInt(u32, bloom_shift, .little);
const comp = elf_file.base.comp;
const gpa = comp.gpa;
@@ -1271,7 +1268,7 @@ pub const GnuHashSection = struct {
bloom[idx] |= @as(u64, 1) << @as(u6, @intCast((h >> bloom_shift) % 64));
}
- try cwriter.writeAll(mem.sliceAsBytes(bloom));
+ try writer.writeAll(mem.sliceAsBytes(bloom));
// Fill in the hash bucket indices
const buckets = try gpa.alloc(u32, hash.num_buckets);
@@ -1284,7 +1281,7 @@ pub const GnuHashSection = struct {
}
}
- try cwriter.writeAll(mem.sliceAsBytes(buckets));
+ try writer.writeAll(mem.sliceAsBytes(buckets));
// Finally, write the hash table
const table = try gpa.alloc(u32, hash.num_exports);
@@ -1300,9 +1297,7 @@ pub const GnuHashSection = struct {
}
}
- try cwriter.writeAll(mem.sliceAsBytes(table));
-
- assert(counting.bytes_written == hash.size());
+ try writer.writeAll(mem.sliceAsBytes(table));
}
pub fn hasher(name: [:0]const u8) u32 {
diff --git a/src/link/MachO/dyld_info/Trie.zig b/src/link/MachO/dyld_info/Trie.zig
index ce56101e54..d96f2a54c8 100644
--- a/src/link/MachO/dyld_info/Trie.zig
+++ b/src/link/MachO/dyld_info/Trie.zig
@@ -186,17 +186,18 @@ const FinalizeNodeResult = struct {
/// Updates offset of this node in the output byte stream.
fn finalizeNode(self: *Trie, node_index: Node.Index, offset_in_trie: u32) !FinalizeNodeResult {
- var stream = std.io.countingWriter(std.io.null_writer);
- const writer = stream.writer();
+ var trash_buffer: [64]u8 = undefined;
+ var stream: std.Io.Writer.Discarding = .init(&trash_buffer);
+ const writer = &stream.writer;
const slice = self.nodes.slice();
var node_size: u32 = 0;
if (slice.items(.is_terminal)[node_index]) {
const export_flags = slice.items(.export_flags)[node_index];
const vmaddr_offset = slice.items(.vmaddr_offset)[node_index];
- try leb.writeUleb128(writer, export_flags);
- try leb.writeUleb128(writer, vmaddr_offset);
- try leb.writeUleb128(writer, stream.bytes_written);
+ try writer.writeUleb128(export_flags);
+ try writer.writeUleb128(vmaddr_offset);
+ try writer.writeUleb128(stream.fullCount());
} else {
node_size += 1; // 0x0 for non-terminal nodes
}
@@ -206,13 +207,13 @@ fn finalizeNode(self: *Trie, node_index: Node.Index, offset_in_trie: u32) !Final
const edge = &self.edges.items[edge_index];
const next_node_offset = slice.items(.trie_offset)[edge.node];
node_size += @intCast(edge.label.len + 1);
- try leb.writeUleb128(writer, next_node_offset);
+ try writer.writeUleb128(next_node_offset);
}
const trie_offset = slice.items(.trie_offset)[node_index];
const updated = offset_in_trie != trie_offset;
slice.items(.trie_offset)[node_index] = offset_in_trie;
- node_size += @intCast(stream.bytes_written);
+ node_size += @intCast(stream.fullCount());
return .{ .node_size = node_size, .updated = updated };
}