authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-08 16:22:53-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-08 16:22:53-05:00
log6ae36807b70e741ac1a7f8ee1b8d90466abfdda8
tree3b3a9e84f63e8b2c3d838f9c9e5f33cd741aafec
parent24d197b037f93d57e5c9b7d1c84cdc9ec7313081
signaturelock-open Commit is signed but in an unrecognized format.

solve recursion in std.atomic.Queue.dump

by adding a maximum depth

1 files changed, 13 insertions(+), 4 deletions(-)

lib/std/atomic/queue.zig+13-4
......@@ -113,11 +113,20 @@ pub fn Queue(comptime T: type) type {
113113
114114 pub fn dumpToStream(self: *Self, comptime Error: type, stream: *std.io.OutStream(Error)) Error!void {
115115 const S = struct {
116 fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void {
116 fn dumpRecursive(
117 s: *std.io.OutStream(Error),
118 optional_node: ?*Node,
119 indent: usize,
120 comptime depth: comptime_int,
121 ) Error!void {
117122 try s.writeByteNTimes(' ', indent);
118123 if (optional_node) |node| {
119124 try s.print("0x{x}={}\n", .{ @ptrToInt(node), node.data });
120 try dumpRecursive(s, node.next, indent + 1);
125 if (depth == 0) {
126 try s.print("(max depth)\n", .{});
127 return;
128 }
129 try dumpRecursive(s, node.next, indent + 1, depth - 1);
121130 } else {
122131 try s.print("(null)\n", .{});
123132 }
......@@ -127,9 +136,9 @@ pub fn Queue(comptime T: type) type {
127136 defer held.release();
128137
129138 try stream.print("head: ", .{});
130 try S.dumpRecursive(stream, self.head, 0);
139 try S.dumpRecursive(stream, self.head, 0, 4);
131140 try stream.print("tail: ", .{});
132 try S.dumpRecursive(stream, self.tail, 0);
141 try S.dumpRecursive(stream, self.tail, 0, 4);
133142 }
134143 };
135144}