aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/znk.zig23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/znk.zig b/src/znk.zig
index fe66cb5..e59f11d 100644
--- a/src/znk.zig
+++ b/src/znk.zig
@@ -36,26 +36,11 @@ const usage =
36 \\ 36 \\
37; 37;
38 38
39var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
40
41pub fn main() anyerror!void { 39pub fn main() anyerror!void {
42 // Stolen from the Zig compiler 40 var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
43 var gpa_need_deinit = false; 41 defer std.debug.assert(!general_purpose_allocator.deinit());
44 const gpa = gpa: { 42 const gpa = &general_purpose_allocator.allocator;
45 if (!std.builtin.link_libc) { 43
46 gpa_need_deinit = true;
47 break :gpa &general_purpose_allocator.allocator;
48 }
49 // We would prefer to use raw libc allocator here, but cannot
50 // use it if it won't support the alignment we need.
51 if (@alignOf(std.c.max_align_t) < @alignOf(i128)) {
52 break :gpa std.heap.c_allocator;
53 }
54 break :gpa std.heap.raw_c_allocator;
55 };
56 defer if (gpa_need_deinit) {
57 std.debug.assert(!general_purpose_allocator.deinit());
58 };
59 var arena_instance = std.heap.ArenaAllocator.init(gpa); 44 var arena_instance = std.heap.ArenaAllocator.init(gpa);
60 defer arena_instance.deinit(); 45 defer arena_instance.deinit();
61 const arena = &arena_instance.allocator; 46 const arena = &arena_instance.allocator;