-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LoggingAllocator prototype #2338
Conversation
Instead of a |
6533469
to
ad7927a
Compare
Please feel free to open a new PR with something that is ready for review. |
This was ready to review? |
I guess I was looking for a 2nd opinion on the phrasing in the log messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to a proposal I've been meaning to type up. I'll go ahead and do that now.
@@ -565,6 +565,53 @@ pub fn StackFallbackAllocator(comptime size: usize) type { | |||
}; | |||
} | |||
|
|||
pub const NoErrorOutStream = std.io.OutStream(error{}); | |||
pub const LoggingAllocator = struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc comments please. when should someone use this? what are the semantics?
@@ -565,6 +565,53 @@ pub fn StackFallbackAllocator(comptime size: usize) type { | |||
}; | |||
} | |||
|
|||
pub const NoErrorOutStream = std.io.OutStream(error{}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does one acquire a NoErrorOutStream? If I were to for example use (try std.io.getStdErr()).outStream()
this outstream has errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used this before....:
diff --git a/std/debug.zig b/std/debug.zig
index c5741f390..6425a7526 100644
--- a/std/debug.zig
+++ b/std/debug.zig
@@ -2339,7 +2339,15 @@ fn readILeb128(in_stream: var) !i64 {
}
/// This should only be used in temporary test programs.
-pub const global_allocator = &global_fixed_allocator.allocator;
+var NoErrorStdErrStream = std.heap.NoErrorOutStream {
+ .writeFn = struct {
+ pub fn writeFn(out_stream: *std.heap.NoErrorOutStream, bytes: []const u8) error{}!void {
+ const stderr = io.getStdErr() catch return;
+ stderr.write(bytes) catch return;
+ }
+ }.writeFn,
+};
+pub const global_allocator = &std.heap.LoggingAllocator.init(&global_fixed_allocator.allocator, &NoErrorStdErrStream).allocator;
This proposal would remove the need for the OutStream component: #2586 |
Concept for #2337
Open questions:
how to allow custom logging function? trying
fails with error: parameter of type 'fn([]const u8,var)var' must be declared comptime