zig icon indicating copy to clipboard operation
zig copied to clipboard

remove some newlines and other minor cleanups

Open wooster0 opened this issue 1 year ago • 0 comments

I noticed these things (see commits) when I was working on some other things.

Let me explain the std.builtin.StackTrace: don't print extra newline after stack trace commit more: Currently there is an extra newline printed after a stack trace and it can definitely add up when you have a lot of stack traces printed by the GPA when you have a lot of memory leaks. Example: x.zig:

const std = @import("std");

test {
    var gpa = std.testing.allocator;

    try x(gpa);
}

fn x(allocator: std.mem.Allocator) !void {
    const a = try allocator.alloc(u8, 5);
    _ = a;

    const b = try allocator.alloc(u8, 5);
    _ = b;
}

Before:

$ zig test x.zig
Test [1/1] test_0... [gpa] (err): memory address 0x7ff8c5ce9000 leaked:
/home/wooster/Desktop/zig/x.zig:10:34: 0x20ee89 in x (test)
    const a = try allocator.alloc(u8, 5);
                                 ^
/home/wooster/Desktop/zig/x.zig:6:10: 0x20f0cc in test_0 (test)
    try x(gpa);
         ^
/home/wooster/Desktop/zig-linux-x86_64/lib/test_runner.zig:177:28: 0x21d658 in mainTerminal (test)
        } else test_fn.func();
                           ^
/home/wooster/Desktop/zig-linux-x86_64/lib/test_runner.zig:37:28: 0x2145e7 in main (test)
        return mainTerminal();
                           ^
/home/wooster/Desktop/zig-linux-x86_64/lib/std/start.zig:599:22: 0x20f9b5 in posixCallMainAndExit (test)
            root.main();
                     ^
/home/wooster/Desktop/zig-linux-x86_64/lib/std/start.zig:368:5: 0x20f461 in _start (test)
    @call(.never_inline, posixCallMainAndExit, .{});
    ^


[gpa] (err): memory address 0x7ff8c5ce9008 leaked:
/home/wooster/Desktop/zig/x.zig:13:34: 0x20eeed in x (test)
    const b = try allocator.alloc(u8, 5);
                                 ^
/home/wooster/Desktop/zig/x.zig:6:10: 0x20f0cc in test_0 (test)
    try x(gpa);
         ^
/home/wooster/Desktop/zig-linux-x86_64/lib/test_runner.zig:177:28: 0x21d658 in mainTerminal (test)
        } else test_fn.func();
                           ^
/home/wooster/Desktop/zig-linux-x86_64/lib/test_runner.zig:37:28: 0x2145e7 in main (test)
        return mainTerminal();
                           ^
/home/wooster/Desktop/zig-linux-x86_64/lib/std/start.zig:599:22: 0x20f9b5 in posixCallMainAndExit (test)
            root.main();
                     ^
/home/wooster/Desktop/zig-linux-x86_64/lib/std/start.zig:368:5: 0x20f461 in _start (test)
    @call(.never_inline, posixCallMainAndExit, .{});
    ^


All 1 tests passed.

After:

$ zig test x.zig --zig-lib-dir lib
Test [1/1] test_0... [gpa] (err): memory address 0x7fd4e6542000 leaked:
/home/wooster/Desktop/zig/x.zig:10:34: 0x20ee79 in x (test)
    const a = try allocator.alloc(u8, 5);
                                 ^
/home/wooster/Desktop/zig/x.zig:6:10: 0x20f0bc in test_0 (test)
    try x(gpa);
         ^
/home/wooster/Desktop/zig/lib/test_runner.zig:177:28: 0x21d648 in mainTerminal (test)
        } else test_fn.func();
                           ^
/home/wooster/Desktop/zig/lib/test_runner.zig:37:28: 0x2145d7 in main (test)
        return mainTerminal();
                           ^
/home/wooster/Desktop/zig/lib/std/start.zig:599:22: 0x20f9a5 in posixCallMainAndExit (test)
            root.main();
                     ^
/home/wooster/Desktop/zig/lib/std/start.zig:368:5: 0x20f451 in _start (test)
    @call(.never_inline, posixCallMainAndExit, .{});
    ^

[gpa] (err): memory address 0x7fd4e6542008 leaked:
/home/wooster/Desktop/zig/x.zig:13:34: 0x20eedd in x (test)
    const b = try allocator.alloc(u8, 5);
                                 ^
/home/wooster/Desktop/zig/x.zig:6:10: 0x20f0bc in test_0 (test)
    try x(gpa);
         ^
/home/wooster/Desktop/zig/lib/test_runner.zig:177:28: 0x21d648 in mainTerminal (test)
        } else test_fn.func();
                           ^
/home/wooster/Desktop/zig/lib/test_runner.zig:37:28: 0x2145d7 in main (test)
        return mainTerminal();
                           ^
/home/wooster/Desktop/zig/lib/std/start.zig:599:22: 0x20f9a5 in posixCallMainAndExit (test)
            root.main();
                     ^
/home/wooster/Desktop/zig/lib/std/start.zig:368:5: 0x20f451 in _start (test)
    @call(.never_inline, posixCallMainAndExit, .{});
    ^

All 1 tests passed.

This can make a difference when scrolling through a lot of memory leaks.

wooster0 avatar May 19 '23 14:05 wooster0