aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2024-08-06 11:22:37 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2024-08-16 15:22:55 -0400
commitef11bc9899002620d67cfce9c79b6c0dc0f5ea61 (patch)
tree7b05fe17340c06e4c40c45ebe249361c0c281c72 /lib/std/array_list.zig
parent90989be0e31a91335f8d1c1eafb84c3b34792a8c (diff)
downloadzig-ef11bc9899002620d67cfce9c79b6c0dc0f5ea61.tar.gz
zig-ef11bc9899002620d67cfce9c79b6c0dc0f5ea61.zip
Dwarf: rework self-hosted debug info from scratch
This is in preparation for incremental and actually being able to debug executables built by the x86_64 backend.
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 7b93668c5c..2510973692 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -359,6 +359,24 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
return m.len;
}
+ pub const FixedWriter = std.io.Writer(*Self, Allocator.Error, appendWriteFixed);
+
+ /// Initializes a Writer which will append to the list but will return
+ /// `error.OutOfMemory` rather than increasing capacity.
+ pub fn fixedWriter(self: *Self) FixedWriter {
+ return .{ .context = self };
+ }
+
+ /// The purpose of this function existing is to match `std.io.Writer` API.
+ fn appendWriteFixed(self: *Self, m: []const u8) error{OutOfMemory}!usize {
+ const available_capacity = self.capacity - self.items.len;
+ if (m.len > available_capacity)
+ return error.OutOfMemory;
+
+ self.appendSliceAssumeCapacity(m);
+ return m.len;
+ }
+
/// Append a value to the list `n` times.
/// Allocates more memory as necessary.
/// Invalidates element pointers if additional memory is needed.