authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-06-15 22:58:59+10:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-06-15 23:48:33+10:00
logce30357532395f46229052b5bcdc5f0a49d2b20d
tree60fc052806b10db0d387986a94ead8ec5581d65f
parente7207bc267d90b5be009fcd937b86cde9bf9ae77
signature Commit is signed but in an unrecognized format.

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

1 files changed, 6 insertions(+), 16 deletions(-)

lib/std/debug.zig+6-16
......@@ -50,14 +50,10 @@ pub const LineInfo = struct {
5050 }
5151};
5252
53/// Tries to write to stderr, unbuffered, and ignores any error returned.
54/// Does not append a newline.
55var stderr_file: File = undefined;
56var stderr_file_writer: File.Writer = undefined;
57
58var stderr_stream: ?*File.OutStream = null;
5953var stderr_mutex = std.Mutex.init();
6054
55/// Tries to write to stderr, unbuffered, and ignores any error returned.
56/// Does not append a newline.
6157pub fn warn(comptime fmt: []const u8, args: var) void {
6258 const held = stderr_mutex.acquire();
6359 defer held.release();
......@@ -65,16 +61,8 @@ pub fn warn(comptime fmt: []const u8, args: var) void {
6561 nosuspend stderr.print(fmt, args) catch return;
6662}
6763
68pub fn getStderrStream() *File.OutStream {
69 if (stderr_stream) |st| {
70 return st;
71 } else {
72 stderr_file = io.getStdErr();
73 stderr_file_writer = stderr_file.outStream();
74 const st = &stderr_file_writer;
75 stderr_stream = st;
76 return st;
77 }
64pub fn getStderrStream() File.OutStream {
65 return io.getStdErr().outStream();
7866}
7967
8068pub fn getStderrMutex() *std.Mutex {
......@@ -99,6 +87,7 @@ pub fn detectTTYConfig() TTY.Config {
9987 if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| {
10088 return .escape_codes;
10189 } else |_| {
90 const stderr_file = io.getStdErr();
10291 if (stderr_file.supportsAnsiEscapeCodes()) {
10392 return .escape_codes;
10493 } else if (builtin.os.tag == .windows and stderr_file.isTty()) {
......@@ -458,6 +447,7 @@ pub const TTY = struct {
458447 .Reset => out_stream.writeAll(RESET) catch return,
459448 },
460449 .windows_api => if (builtin.os.tag == .windows) {
450 const stderr_file = io.getStdErr();
461451 const S = struct {
462452 var attrs: windows.WORD = undefined;
463453 var init_attrs = false;