authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-07-07 23:24:30-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-07-07 23:24:30-04:00
log089c056dbe1fdbb1da9b1a5bab970ca688d3aa01
tree2f3b88181b0da90e4ceae6739d265112dfff0c7d
parent7a6104929b2d140235597d866dc0fabc93df036f
signature Commit is signed but in an unrecognized format.

CBE: Improve resource cleanup


2 files changed, 18 insertions(+), 3 deletions(-)

src-self-hosted/Module.zig+2-3
...@@ -744,7 +744,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {...@@ -744,7 +744,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {
744 .object_format = options.object_format orelse options.target.getObjectFormat(),744 .object_format = options.object_format orelse options.target.getObjectFormat(),
745 .cbe = options.cbe,745 .cbe = options.cbe,
746 });746 });
747 errdefer bin_file.*.deinit();747 errdefer bin_file.destroy();
748748
749 const root_scope = blk: {749 const root_scope = blk: {
750 if (mem.endsWith(u8, options.root_pkg.root_src_path, ".zig")) {750 if (mem.endsWith(u8, options.root_pkg.root_src_path, ".zig")) {
...@@ -793,9 +793,8 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {...@@ -793,9 +793,8 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {
793}793}
794794
795pub fn deinit(self: *Module) void {795pub fn deinit(self: *Module) void {
796 self.bin_file.deinit();796 self.bin_file.destroy();
797 const allocator = self.allocator;797 const allocator = self.allocator;
798 allocator.destroy(self.bin_file);
799 self.deletion_set.deinit(allocator);798 self.deletion_set.deinit(allocator);
800 self.work_queue.deinit();799 self.work_queue.deinit();
801800
src-self-hosted/link.zig+16
...@@ -159,6 +159,22 @@ pub const File = struct {...@@ -159,6 +159,22 @@ pub const File = struct {
159 }159 }
160 }160 }
161161
162 pub fn destroy(base: *File) void {
163 switch (base.tag) {
164 .Elf => {
165 const parent = @fieldParentPtr(Elf, "base", base);
166 parent.deinit();
167 parent.allocator.destroy(parent);
168 },
169 .C => {
170 const parent = @fieldParentPtr(C, "base", base);
171 parent.deinit();
172 parent.allocator.destroy(parent);
173 },
174 else => unreachable,
175 }
176 }
177
162 pub fn flush(base: *File) !void {178 pub fn flush(base: *File) !void {
163 try switch (base.tag) {179 try switch (base.tag) {
164 .Elf => @fieldParentPtr(Elf, "base", base).flush(),180 .Elf => @fieldParentPtr(Elf, "base", base).flush(),