aboutsummaryrefslogtreecommitdiff
path: root/lib/std/heap/logging_allocator.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-01-09 13:04:08 -0800
committerGitHub <noreply@github.com>2021-01-09 13:04:08 -0800
commit29928af6005997d2b02b4c3a3576a696a02fa269 (patch)
tree9852e606adc5bc065e758482445bb6d1c5ead99c /lib/std/heap/logging_allocator.zig
parenta0ad2dee6a0b3bb7fd04032f6113206f7b4e73eb (diff)
parente72472d953f5e91d37bc5f1bf1ec7b6fb5b1afe2 (diff)
downloadzig-29928af6005997d2b02b4c3a3576a696a02fa269.tar.gz
zig-29928af6005997d2b02b4c3a3576a696a02fa269.zip
Merge pull request #7729 from jayschwa/remove-deprecated-stream
Remove deprecated stream aliases
Diffstat (limited to 'lib/std/heap/logging_allocator.zig')
-rw-r--r--lib/std/heap/logging_allocator.zig30
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/std/heap/logging_allocator.zig b/lib/std/heap/logging_allocator.zig
index 7920138e9b..7885571ab3 100644
--- a/lib/std/heap/logging_allocator.zig
+++ b/lib/std/heap/logging_allocator.zig
@@ -9,22 +9,22 @@ const Allocator = std.mem.Allocator;
/// This allocator is used in front of another allocator and logs to the provided stream
/// on every call to the allocator. Stream errors are ignored.
/// If https://github.com/ziglang/zig/issues/2586 is implemented, this API can be improved.
-pub fn LoggingAllocator(comptime OutStreamType: type) type {
+pub fn LoggingAllocator(comptime Writer: type) type {
return struct {
allocator: Allocator,
parent_allocator: *Allocator,
- out_stream: OutStreamType,
+ writer: Writer,
const Self = @This();
- pub fn init(parent_allocator: *Allocator, out_stream: OutStreamType) Self {
+ pub fn init(parent_allocator: *Allocator, writer: Writer) Self {
return Self{
.allocator = Allocator{
.allocFn = alloc,
.resizeFn = resize,
},
.parent_allocator = parent_allocator,
- .out_stream = out_stream,
+ .writer = writer,
};
}
@@ -36,12 +36,12 @@ pub fn LoggingAllocator(comptime OutStreamType: type) type {
ra: usize,
) error{OutOfMemory}![]u8 {
const self = @fieldParentPtr(Self, "allocator", allocator);
- self.out_stream.print("alloc : {}", .{len}) catch {};
+ self.writer.print("alloc : {}", .{len}) catch {};
const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra);
if (result) |buff| {
- self.out_stream.print(" success!\n", .{}) catch {};
+ self.writer.print(" success!\n", .{}) catch {};
} else |err| {
- self.out_stream.print(" failure!\n", .{}) catch {};
+ self.writer.print(" failure!\n", .{}) catch {};
}
return result;
}
@@ -56,20 +56,20 @@ pub fn LoggingAllocator(comptime OutStreamType: type) type {
) error{OutOfMemory}!usize {
const self = @fieldParentPtr(Self, "allocator", allocator);
if (new_len == 0) {
- self.out_stream.print("free : {}\n", .{buf.len}) catch {};
+ self.writer.print("free : {}\n", .{buf.len}) catch {};
} else if (new_len <= buf.len) {
- self.out_stream.print("shrink: {} to {}\n", .{ buf.len, new_len }) catch {};
+ self.writer.print("shrink: {} to {}\n", .{ buf.len, new_len }) catch {};
} else {
- self.out_stream.print("expand: {} to {}", .{ buf.len, new_len }) catch {};
+ self.writer.print("expand: {} to {}", .{ buf.len, new_len }) catch {};
}
if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ra)) |resized_len| {
if (new_len > buf.len) {
- self.out_stream.print(" success!\n", .{}) catch {};
+ self.writer.print(" success!\n", .{}) catch {};
}
return resized_len;
} else |e| {
std.debug.assert(new_len > buf.len);
- self.out_stream.print(" failure!\n", .{}) catch {};
+ self.writer.print(" failure!\n", .{}) catch {};
return e;
}
}
@@ -78,9 +78,9 @@ pub fn LoggingAllocator(comptime OutStreamType: type) type {
pub fn loggingAllocator(
parent_allocator: *Allocator,
- out_stream: anytype,
-) LoggingAllocator(@TypeOf(out_stream)) {
- return LoggingAllocator(@TypeOf(out_stream)).init(parent_allocator, out_stream);
+ writer: anytype,
+) LoggingAllocator(@TypeOf(writer)) {
+ return LoggingAllocator(@TypeOf(writer)).init(parent_allocator, writer);
}
test "LoggingAllocator" {