diff options
author | Rutger Broekhoff | 2021-05-22 21:32:23 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2021-05-22 21:32:23 +0200 |
commit | 2830f5fc32db7767081beb4b1bb275270608fcab (patch) | |
tree | ef6e0e0da8ec49a081e0b62dbe21d44b62b0fa7f /src/znk.zig | |
parent | 07ac8dc00e7676d7845a881970c259679b0c5d23 (diff) | |
download | zig-nkeys-2830f5fc32db7767081beb4b1bb275270608fcab.tar.gz zig-nkeys-2830f5fc32db7767081beb4b1bb275270608fcab.zip |
Simplify znk main
Diffstat (limited to 'src/znk.zig')
-rw-r--r-- | src/znk.zig | 23 |
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 | ||
39 | var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; | ||
40 | |||
41 | pub fn main() anyerror!void { | 39 | pub 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; |