zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 089c056dbe1fdbb1da9b1a5bab970ca688d3aa01 (tree)
parent 7a6104929b2d140235597d866dc0fabc93df036f
Author: Noam Preil <pleasantatk@gmail.com>
Date:   Tue,  7 Jul 2020 23:24:30 -0400

CBE: Improve resource cleanup

Diffstat:
Msrc-self-hosted/Module.zig | 5++---
Msrc-self-hosted/link.zig | 16++++++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src-self-hosted/Module.zig b/src-self-hosted/Module.zig @@ -744,7 +744,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { .object_format = options.object_format orelse options.target.getObjectFormat(), .cbe = options.cbe, }); - errdefer bin_file.*.deinit(); + errdefer bin_file.destroy(); const root_scope = blk: { if (mem.endsWith(u8, options.root_pkg.root_src_path, ".zig")) { @@ -793,9 +793,8 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { } pub fn deinit(self: *Module) void { - self.bin_file.deinit(); + self.bin_file.destroy(); const allocator = self.allocator; - allocator.destroy(self.bin_file); self.deletion_set.deinit(allocator); self.work_queue.deinit(); diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig @@ -159,6 +159,22 @@ pub const File = struct { } } + pub fn destroy(base: *File) void { + switch (base.tag) { + .Elf => { + const parent = @fieldParentPtr(Elf, "base", base); + parent.deinit(); + parent.allocator.destroy(parent); + }, + .C => { + const parent = @fieldParentPtr(C, "base", base); + parent.deinit(); + parent.allocator.destroy(parent); + }, + else => unreachable, + } + } + pub fn flush(base: *File) !void { try switch (base.tag) { .Elf => @fieldParentPtr(Elf, "base", base).flush(),