authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-28 10:20:29+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-28 13:09:14-07:00
log2682b41da54e9b652dc570140d52f85418d6b89d
tree1ef33283fb9004aa0e5ab0dcc8fe72b8dff389d5
parentdfeffcfbf825c29d89ccec281ab95dd2383317ac

make gpa.deinit work with stage2


3 files changed, 24 insertions(+), 10 deletions(-)

lib/std/hash_map.zig+2-2
...@@ -738,7 +738,7 @@ pub fn HashMapUnmanaged(...@@ -738,7 +738,7 @@ pub fn HashMapUnmanaged(
738 value: V,738 value: V,
739 };739 };
740740
741 const Header = packed struct {741 const Header = struct {
742 values: [*]V,742 values: [*]V,
743 keys: [*]K,743 keys: [*]K,
744 capacity: Size,744 capacity: Size,
...@@ -932,7 +932,7 @@ pub fn HashMapUnmanaged(...@@ -932,7 +932,7 @@ pub fn HashMapUnmanaged(
932 }932 }
933933
934 fn header(self: *const Self) *Header {934 fn header(self: *const Self) *Header {
935 return @ptrCast(*Header, @ptrCast([*]Header, self.metadata.?) - 1);935 return @ptrCast(*Header, @ptrCast([*]Header, @alignCast(@alignOf(Header), self.metadata.?)) - 1);
936 }936 }
937937
938 fn keys(self: *const Self) [*]K {938 fn keys(self: *const Self) [*]K {
lib/std/heap/general_purpose_allocator.zig+19-6
...@@ -341,9 +341,15 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -341,9 +341,15 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
341 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);341 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
342 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);342 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
343 const addr = bucket.page + slot_index * size_class;343 const addr = bucket.page + slot_index * size_class;
344 log.err("memory address 0x{x} leaked: {s}", .{344 if (builtin.zig_backend == .stage1) {
345 @ptrToInt(addr), stack_trace,345 log.err("memory address 0x{x} leaked: {s}", .{
346 });346 @ptrToInt(addr), stack_trace,
347 });
348 } else { // TODO
349 log.err("memory address 0x{x} leaked", .{
350 @ptrToInt(addr),
351 });
352 }
347 leaks = true;353 leaks = true;
348 }354 }
349 if (bit_index == math.maxInt(u3))355 if (bit_index == math.maxInt(u3))
...@@ -372,9 +378,16 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -372,9 +378,16 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
372 var it = self.large_allocations.valueIterator();378 var it = self.large_allocations.valueIterator();
373 while (it.next()) |large_alloc| {379 while (it.next()) |large_alloc| {
374 if (config.retain_metadata and large_alloc.freed) continue;380 if (config.retain_metadata and large_alloc.freed) continue;
375 log.err("memory address 0x{x} leaked: {s}", .{381 const stack_trace = large_alloc.getStackTrace(.alloc);
376 @ptrToInt(large_alloc.bytes.ptr), large_alloc.getStackTrace(.alloc),382 if (builtin.zig_backend == .stage1) {
377 });383 log.err("memory address 0x{x} leaked: {s}", .{
384 @ptrToInt(large_alloc.bytes.ptr), stack_trace,
385 });
386 } else { // TODO
387 log.err("memory address 0x{x} leaked", .{
388 @ptrToInt(large_alloc.bytes.ptr),
389 });
390 }
378 leaks = true;391 leaks = true;
379 }392 }
380 return leaks;393 return leaks;
lib/std/special/test_runner.zig+3-2
...@@ -46,9 +46,10 @@ pub fn main() void {...@@ -46,9 +46,10 @@ pub fn main() void {
4646
47 var leaks: usize = 0;47 var leaks: usize = 0;
48 for (test_fn_list) |test_fn, i| {48 for (test_fn_list) |test_fn, i| {
49 if (builtin.zig_backend != .stage2_llvm) std.testing.allocator_instance = .{};49 const gpa_works = builtin.zig_backend == .stage1 or builtin.os.tag != .macos;
50 if (gpa_works) std.testing.allocator_instance = .{};
50 defer {51 defer {
51 if (builtin.zig_backend != .stage2_llvm and std.testing.allocator_instance.deinit()) {52 if (gpa_works and std.testing.allocator_instance.deinit()) {
52 leaks += 1;53 leaks += 1;
53 }54 }
54 }55 }