| ... | ... | @@ -117,10 +117,7 @@ const WorkItem = union(enum) { |
| 117 | 117 | |
| 118 | 118 | pub const CObject = struct { |
| 119 | 119 | /// Relative to cwd. Owned by arena. |
| 120 | | src_path: []const u8, |
| 121 | | /// Owned by arena. |
| 122 | | extra_flags: []const []const u8, |
| 123 | | arena: std.heap.ArenaAllocator.State, |
| 120 | src: CSourceFile, |
| 124 | 121 | status: union(enum) { |
| 125 | 122 | new, |
| 126 | 123 | success: struct { |
| ... | ... | @@ -154,7 +151,7 @@ pub const CObject = struct { |
| 154 | 151 | |
| 155 | 152 | pub fn destroy(self: *CObject, gpa: *Allocator) void { |
| 156 | 153 | _ = self.clearStatus(gpa); |
| 157 | | self.arena.promote(gpa).deinit(); |
| 154 | gpa.destroy(self); |
| 158 | 155 | } |
| 159 | 156 | }; |
| 160 | 157 | |
| ... | ... | @@ -627,17 +624,12 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 627 | 624 | // Add a `CObject` for each `c_source_files`. |
| 628 | 625 | try comp.c_object_table.ensureCapacity(gpa, options.c_source_files.len); |
| 629 | 626 | for (options.c_source_files) |c_source_file| { |
| 630 | | var local_arena = std.heap.ArenaAllocator.init(gpa); |
| 631 | | errdefer local_arena.deinit(); |
| 632 | | |
| 633 | | const c_object = try local_arena.allocator.create(CObject); |
| 627 | const c_object = try gpa.create(CObject); |
| 628 | errdefer gpa.destroy(c_object); |
| 634 | 629 | |
| 635 | 630 | c_object.* = .{ |
| 636 | 631 | .status = .{ .new = {} }, |
| 637 | | // TODO look into refactoring to turn these 2 fields simply into a CSourceFile |
| 638 | | .src_path = try local_arena.allocator.dupe(u8, c_source_file.src_path), |
| 639 | | .extra_flags = try local_arena.allocator.dupe([]const u8, c_source_file.extra_flags), |
| 640 | | .arena = local_arena.state, |
| 632 | .src = c_source_file, |
| 641 | 633 | }; |
| 642 | 634 | comp.c_object_table.putAssumeCapacityNoClobber(c_object, {}); |
| 643 | 635 | } |
| ... | ... | @@ -798,7 +790,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 798 | 790 | for (self.failed_c_objects.items()) |entry| { |
| 799 | 791 | const c_object = entry.key; |
| 800 | 792 | const err_msg = entry.value; |
| 801 | | try AllErrors.add(&arena, &errors, c_object.src_path, "", err_msg.*); |
| 793 | try AllErrors.add(&arena, &errors, c_object.src.src_path, "", err_msg.*); |
| 802 | 794 | } |
| 803 | 795 | if (self.bin_file.options.module) |module| { |
| 804 | 796 | for (module.failed_files.items()) |entry| { |
| ... | ... | @@ -981,13 +973,13 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void { |
| 981 | 973 | // TODO this logic can likely be improved by utilizing clang_options_data.zig. |
| 982 | 974 | const file_args = [_][]const u8{"-include"}; |
| 983 | 975 | var arg_i: usize = 0; |
| 984 | | while (arg_i < c_object.extra_flags.len) : (arg_i += 1) { |
| 985 | | const arg = c_object.extra_flags[arg_i]; |
| 976 | while (arg_i < c_object.src.extra_flags.len) : (arg_i += 1) { |
| 977 | const arg = c_object.src.extra_flags[arg_i]; |
| 986 | 978 | ch.hash.addBytes(arg); |
| 987 | 979 | for (file_args) |file_arg| { |
| 988 | | if (mem.eql(u8, file_arg, arg) and arg_i + 1 < c_object.extra_flags.len) { |
| 980 | if (mem.eql(u8, file_arg, arg) and arg_i + 1 < c_object.src.extra_flags.len) { |
| 989 | 981 | arg_i += 1; |
| 990 | | _ = try ch.addFile(c_object.extra_flags[arg_i], null); |
| 982 | _ = try ch.addFile(c_object.src.extra_flags[arg_i], null); |
| 991 | 983 | } |
| 992 | 984 | } |
| 993 | 985 | } |
| ... | ... | @@ -1028,7 +1020,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void { |
| 1028 | 1020 | try argv.append(out_obj_path); |
| 1029 | 1021 | |
| 1030 | 1022 | try argv.append(c_object.src_path); |
| 1031 | | try argv.appendSlice(c_object.extra_flags); |
| 1023 | try argv.appendSlice(c_object.src.extra_flags); |
| 1032 | 1024 | |
| 1033 | 1025 | if (comp.debug_cc) { |
| 1034 | 1026 | for (argv.items[0 .. argv.items.len - 1]) |arg| { |