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 {...@@ -50,14 +50,10 @@ pub const LineInfo = struct {
50 }50 }
51};51};
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;
59var stderr_mutex = std.Mutex.init();53var stderr_mutex = std.Mutex.init();
6054
55/// Tries to write to stderr, unbuffered, and ignores any error returned.
56/// Does not append a newline.
61pub fn warn(comptime fmt: []const u8, args: var) void {57pub fn warn(comptime fmt: []const u8, args: var) void {
62 const held = stderr_mutex.acquire();58 const held = stderr_mutex.acquire();
63 defer held.release();59 defer held.release();
...@@ -65,16 +61,8 @@ pub fn warn(comptime fmt: []const u8, args: var) void {...@@ -65,16 +61,8 @@ pub fn warn(comptime fmt: []const u8, args: var) void {
65 nosuspend stderr.print(fmt, args) catch return;61 nosuspend stderr.print(fmt, args) catch return;
66}62}
6763
68pub fn getStderrStream() *File.OutStream {64pub fn getStderrStream() File.OutStream {
69 if (stderr_stream) |st| {65 return io.getStdErr().outStream();
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 }
78}66}
7967
80pub fn getStderrMutex() *std.Mutex {68pub fn getStderrMutex() *std.Mutex {
...@@ -99,6 +87,7 @@ pub fn detectTTYConfig() TTY.Config {...@@ -99,6 +87,7 @@ pub fn detectTTYConfig() TTY.Config {
99 if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| {87 if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| {
100 return .escape_codes;88 return .escape_codes;
101 } else |_| {89 } else |_| {
90 const stderr_file = io.getStdErr();
102 if (stderr_file.supportsAnsiEscapeCodes()) {91 if (stderr_file.supportsAnsiEscapeCodes()) {
103 return .escape_codes;92 return .escape_codes;
104 } else if (builtin.os.tag == .windows and stderr_file.isTty()) {93 } else if (builtin.os.tag == .windows and stderr_file.isTty()) {
...@@ -458,6 +447,7 @@ pub const TTY = struct {...@@ -458,6 +447,7 @@ pub const TTY = struct {
458 .Reset => out_stream.writeAll(RESET) catch return,447 .Reset => out_stream.writeAll(RESET) catch return,
459 },448 },
460 .windows_api => if (builtin.os.tag == .windows) {449 .windows_api => if (builtin.os.tag == .windows) {
450 const stderr_file = io.getStdErr();
461 const S = struct {451 const S = struct {
462 var attrs: windows.WORD = undefined;452 var attrs: windows.WORD = undefined;
463 var init_attrs = false;453 var init_attrs = false;