Added arena allocator for caonfig file to manage lua string lifetimes.
Browse files
+3 −0 src/config/config.zig
| @@ -109,6 +109,7 @@ pub const Color_Scheme = struct { | ||
| 109 | 109 | |
| 110 | 110 | pub const Config = struct { |
| 111 | 111 | allocator: std.mem.Allocator, |
| 112 | + string_arena: std.heap.ArenaAllocator, | |
| 112 | 113 | |
| 113 | 114 | terminal: []const u8 = "st", |
| 114 | 115 | font: []const u8 = "monospace:size=10", |
| @@ -149,10 +150,12 @@ pub const Config = struct { | ||
| 149 | 150 | pub fn init(allocator: std.mem.Allocator) Config { |
| 150 | 151 | return Config{ |
| 151 | 152 | .allocator = allocator, |
| 153 | + .string_arena = std.heap.ArenaAllocator.init(allocator), | |
| 152 | 154 | }; |
| 153 | 155 | } |
| 154 | 156 | |
| 155 | 157 | pub fn deinit(self: *Config) void { |
| 158 | + self.string_arena.deinit(); | |
| 156 | 159 | self.keybinds.deinit(self.allocator); |
| 157 | 160 | self.rules.deinit(self.allocator); |
| 158 | 161 | self.blocks.deinit(self.allocator); |
+2 −1 src/config/lua.zig
| @@ -1161,7 +1161,8 @@ fn get_lua_string(state: *c.lua_State, idx: c_int) ?[]const u8 { | ||
| 1161 | 1161 | fn dupe_lua_string(state: *c.lua_State, idx: c_int) ?[]const u8 { |
| 1162 | 1162 | const cfg = config orelse return null; |
| 1163 | 1163 | const lua_str = get_lua_string(state, idx) orelse return null; |
| 1164 | - const duped = cfg.allocator.dupe(u8, lua_str) catch return null; | |
| 1164 | + const arena_allocator = cfg.string_arena.allocator(); | |
| 1165 | + const duped = arena_allocator.dupe(u8, lua_str) catch return null; | |
| 1165 | 1166 | return duped; |
| 1166 | 1167 | } |
| 1167 | 1168 |
+17 −2 src/main.zig
| @@ -136,8 +136,10 @@ pub fn main() !void { | ||
| 136 | 136 | const allocator = gpa.allocator(); |
| 137 | 137 | defer _ = gpa.deinit(); |
| 138 | 138 | |
| 139 | - var config_path: []const u8 = try get_config_path(allocator); | |
| 140 | - defer allocator.free(config_path); | |
| 139 | + const default_config_path = try get_config_path(allocator); | |
| 140 | + defer allocator.free(default_config_path); | |
| 141 | + | |
| 142 | + var config_path: []const u8 = default_config_path; | |
| 141 | 143 | var args = std.process.args(); |
| 142 | 144 | _ = args.skip(); |
| 143 | 145 | while (args.next()) |arg| { |
| @@ -218,6 +220,19 @@ pub fn main() !void { | ||
| 218 | 220 | std.debug.print("entering event loop\n", .{}); |
| 219 | 221 | run_event_loop(&display); |
| 220 | 222 | |
| 223 | + bar_mod.destroy_bars(allocator, display.handle); | |
| 224 | + | |
| 225 | + var mon = monitor_mod.monitors; | |
| 226 | + while (mon) |m| { | |
| 227 | + const next = m.next; | |
| 228 | + monitor_mod.destroy(m); | |
| 229 | + mon = next; | |
| 230 | + } | |
| 231 | + | |
| 232 | + if (keybind_overlay) |overlay| { | |
| 233 | + overlay.deinit(allocator); | |
| 234 | + } | |
| 235 | + | |
| 221 | 236 | lua.deinit(); |
| 222 | 237 | std.debug.print("oxwm exiting\n", .{}); |
| 223 | 238 | } |