fix lua oom errors

This commit is contained in:
Squibid 2025-12-10 22:31:18 -05:00
parent 9553e3831f
commit 1e973eff94
Signed by: squibid
GPG key ID: BECE5684D3C4005D
4 changed files with 14 additions and 23 deletions

View file

@ -2,6 +2,8 @@ const std = @import("std");
const zlua = @import("zlua");
const wlr = @import("wlroots");
const Utils = @import("../Utils.zig");
const gpa = std.heap.c_allocator;
const env_map = &@import("../main.zig").env_map;
@ -14,8 +16,9 @@ pub fn spawn(L: *zlua.Lua) i32 {
var child = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, gpa);
child.env_map = env_map;
child.spawn() catch {
L.raiseErrorStr("Unable to spawn process", .{}); // TODO: Give more descriptive error
child.spawn() catch |err| switch (err) {
error.OutOfMemory => Utils.oomPanic(),
else => L.raiseErrorStr("Unable to spawn process child process", .{}),
};
L.pushNil();

View file

@ -4,6 +4,7 @@ const std = @import("std");
const zlua = @import("zlua");
const Lua = @import("Lua.zig");
const Utils = @import("../Utils.zig");
const gpa = std.heap.c_allocator;
@ -17,9 +18,7 @@ pub fn joinpath(L: *zlua.Lua) i32 {
return 0;
}
var paths = std.ArrayList([:0]const u8).initCapacity(gpa, @intCast(nargs)) catch {
return 0;
};
var paths = std.ArrayList([:0]const u8).initCapacity(gpa, @intCast(nargs)) catch Utils.oomPanic();
defer paths.deinit(gpa);
var i: u8 = 1;
@ -30,17 +29,12 @@ pub fn joinpath(L: *zlua.Lua) i32 {
}
const partial_path = L.toString(i) catch unreachable;
paths.append(gpa, partial_path) catch {
// TODO: tell lua?
return 0;
};
paths.append(gpa, partial_path) catch Utils.oomPanic();
}
const final_path: []const u8 = std.fs.path.join(gpa, paths.items) catch {
// TODO: tell lua?
return 0;
};
_ = L.pushString(final_path);
const final_path: []const u8 = std.fs.path.join(gpa, paths.items) catch Utils.oomPanic();
defer gpa.free(final_path);
_ = L.pushString(final_path);
return 1;
}

View file

@ -39,9 +39,7 @@ pub fn add(L: *zlua.Lua) i32 {
_ = L.pushString("callback");
_ = L.getTable(2);
if (L.isFunction(-1)) {
hook.options.lua_cb_ref_idx = L.ref(zlua.registry_index) catch {
L.raiseErrorStr("Lua error check your config", .{}); // TODO: Give more descriptive error
};
hook.options.lua_cb_ref_idx = try L.ref(zlua.registry_index);
}
try server.hooks.append(gpa, hook);

View file

@ -41,17 +41,13 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
_ = L.pushString("press");
_ = L.getTable(3);
if (L.isFunction(-1)) {
keymap.options.lua_press_ref_idx = L.ref(zlua.registry_index) catch {
L.raiseErrorStr("Lua error check your config", .{}); // TODO: Insert more descrptive errors
};
keymap.options.lua_press_ref_idx = L.ref(zlua.registry_index) catch Utils.oomPanic();
}
_ = L.pushString("release");
_ = L.getTable(3);
if (L.isFunction(-1)) {
keymap.options.lua_release_ref_idx = L.ref(zlua.registry_index) catch {
L.raiseErrorStr("Lua error check your config", .{}); // TODO: Insert more descrptive errors
};
keymap.options.lua_release_ref_idx = L.ref(zlua.registry_index) catch Utils.oomPanic();
}
_ = L.pushString("repeat");