zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ce30357532395f46229052b5bcdc5f0a49d2b20d (tree)
parent e7207bc267d90b5be009fcd937b86cde9bf9ae77
Author: daurnimator <quae@daurnimator.com>
Date:   Mon, 15 Jun 2020 22:58:59 +1000

std: clean up debug stderr variables

  - stderr_file_writer was unused
  - stderr_stream was a pointer to a stream, rather than a stream
  - other functions assumed that getStderrStream has already been called

Diffstat:
Mlib/std/debug.zig | 22++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/lib/std/debug.zig b/lib/std/debug.zig @@ -50,14 +50,10 @@ pub const LineInfo = struct { } }; -/// Tries to write to stderr, unbuffered, and ignores any error returned. -/// Does not append a newline. -var stderr_file: File = undefined; -var stderr_file_writer: File.Writer = undefined; - -var stderr_stream: ?*File.OutStream = null; var stderr_mutex = std.Mutex.init(); +/// Tries to write to stderr, unbuffered, and ignores any error returned. +/// Does not append a newline. pub fn warn(comptime fmt: []const u8, args: var) void { const held = stderr_mutex.acquire(); defer held.release(); @@ -65,16 +61,8 @@ pub fn warn(comptime fmt: []const u8, args: var) void { nosuspend stderr.print(fmt, args) catch return; } -pub fn getStderrStream() *File.OutStream { - if (stderr_stream) |st| { - return st; - } else { - stderr_file = io.getStdErr(); - stderr_file_writer = stderr_file.outStream(); - const st = &stderr_file_writer; - stderr_stream = st; - return st; - } +pub fn getStderrStream() File.OutStream { + return io.getStdErr().outStream(); } pub fn getStderrMutex() *std.Mutex { @@ -99,6 +87,7 @@ pub fn detectTTYConfig() TTY.Config { if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| { return .escape_codes; } else |_| { + const stderr_file = io.getStdErr(); if (stderr_file.supportsAnsiEscapeCodes()) { return .escape_codes; } else if (builtin.os.tag == .windows and stderr_file.isTty()) { @@ -458,6 +447,7 @@ pub const TTY = struct { .Reset => out_stream.writeAll(RESET) catch return, }, .windows_api => if (builtin.os.tag == .windows) { + const stderr_file = io.getStdErr(); const S = struct { var attrs: windows.WORD = undefined; var init_attrs = false;