| ... | @@ -126,11 +126,20 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{ | ... | @@ -126,11 +126,20 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{ |
| 126 | }){}; | 126 | }){}; |
| 127 | | 127 | |
| 128 | pub fn main() anyerror!void { | 128 | pub fn main() anyerror!void { |
| 129 | const gpa = if (std.builtin.link_libc) | 129 | var gpa_need_deinit = false; |
| 130 | std.heap.raw_c_allocator | 130 | const gpa = gpa: { |
| 131 | else | 131 | if (!std.builtin.link_libc) { |
| 132 | &general_purpose_allocator.allocator; | 132 | gpa_need_deinit = true; |
| 133 | defer if (!std.builtin.link_libc) { | 133 | break :gpa &general_purpose_allocator.allocator; |
| | 134 | } |
| | 135 | // We would prefer to use raw libc allocator here, but cannot |
| | 136 | // use it if it won't support the alignment we need. |
| | 137 | if (@alignOf(std.c.max_align_t) < @alignOf(i128)) { |
| | 138 | break :gpa std.heap.c_allocator; |
| | 139 | } |
| | 140 | break :gpa std.heap.raw_c_allocator; |
| | 141 | }; |
| | 142 | defer if (gpa_need_deinit) { |
| 134 | _ = general_purpose_allocator.deinit(); | 143 | _ = general_purpose_allocator.deinit(); |
| 135 | }; | 144 | }; |
| 136 | var arena_instance = std.heap.ArenaAllocator.init(gpa); | 145 | var arena_instance = std.heap.ArenaAllocator.init(gpa); |