diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-05-19 10:26:50 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-05-19 10:26:50 -0700 |
| commit | bfd051a53c9d1db7a7f8743cd981646a6ac37114 (patch) | |
| tree | 79ac02632f813577a3f0585aad30b001b9def539 /src/main.zig | |
| parent | 1273bc277f7274683db5041d8b41d91903e3045e (diff) | |
| download | zig-bfd051a53c9d1db7a7f8743cd981646a6ac37114.tar.gz zig-bfd051a53c9d1db7a7f8743cd981646a6ac37114.zip | |
stage2: use c_allocator not raw_c_allocator
when the raw C allocator alignment is not sufficient.
closes #8835
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/main.zig b/src/main.zig index 5b0b62a886..b388329508 100644 --- a/src/main.zig +++ b/src/main.zig @@ -126,11 +126,20 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{ }){}; pub fn main() anyerror!void { - const gpa = if (std.builtin.link_libc) - std.heap.raw_c_allocator - else - &general_purpose_allocator.allocator; - defer if (!std.builtin.link_libc) { + var gpa_need_deinit = false; + const gpa = gpa: { + if (!std.builtin.link_libc) { + gpa_need_deinit = true; + break :gpa &general_purpose_allocator.allocator; + } + // We would prefer to use raw libc allocator here, but cannot + // use it if it won't support the alignment we need. + if (@alignOf(std.c.max_align_t) < @alignOf(i128)) { + break :gpa std.heap.c_allocator; + } + break :gpa std.heap.raw_c_allocator; + }; + defer if (gpa_need_deinit) { _ = general_purpose_allocator.deinit(); }; var arena_instance = std.heap.ArenaAllocator.init(gpa); |
