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(
738738 value: V,
739739 };
740740
741 const Header = packed struct {
741 const Header = struct {
742742 values: [*]V,
743743 keys: [*]K,
744744 capacity: Size,
......@@ -932,7 +932,7 @@ pub fn HashMapUnmanaged(
932932 }
933933
934934 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);
936936 }
937937
938938 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 {
341341 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
342342 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
343343 const addr = bucket.page + slot_index * size_class;
344 log.err("memory address 0x{x} leaked: {s}", .{
345 @ptrToInt(addr), stack_trace,
346 });
344 if (builtin.zig_backend == .stage1) {
345 log.err("memory address 0x{x} leaked: {s}", .{
346 @ptrToInt(addr), stack_trace,
347 });
348 } else { // TODO
349 log.err("memory address 0x{x} leaked", .{
350 @ptrToInt(addr),
351 });
352 }
347353 leaks = true;
348354 }
349355 if (bit_index == math.maxInt(u3))
......@@ -372,9 +378,16 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
372378 var it = self.large_allocations.valueIterator();
373379 while (it.next()) |large_alloc| {
374380 if (config.retain_metadata and large_alloc.freed) continue;
375 log.err("memory address 0x{x} leaked: {s}", .{
376 @ptrToInt(large_alloc.bytes.ptr), large_alloc.getStackTrace(.alloc),
377 });
381 const stack_trace = large_alloc.getStackTrace(.alloc);
382 if (builtin.zig_backend == .stage1) {
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 }
378391 leaks = true;
379392 }
380393 return leaks;
lib/std/special/test_runner.zig+3-2
......@@ -46,9 +46,10 @@ pub fn main() void {
4646
4747 var leaks: usize = 0;
4848 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 = .{};
5051 defer {
51 if (builtin.zig_backend != .stage2_llvm and std.testing.allocator_instance.deinit()) {
52 if (gpa_works and std.testing.allocator_instance.deinit()) {
5253 leaks += 1;
5354 }
5455 }