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 zlua = @import("zlua");
const wlr = @import("wlroots"); const wlr = @import("wlroots");
const Utils = @import("../Utils.zig");
const gpa = std.heap.c_allocator; const gpa = std.heap.c_allocator;
const env_map = &@import("../main.zig").env_map; 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); var child = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, gpa);
child.env_map = env_map; child.env_map = env_map;
child.spawn() catch { child.spawn() catch |err| switch (err) {
L.raiseErrorStr("Unable to spawn process", .{}); // TODO: Give more descriptive error error.OutOfMemory => Utils.oomPanic(),
else => L.raiseErrorStr("Unable to spawn process child process", .{}),
}; };
L.pushNil(); L.pushNil();

View file

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

View file

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

View file

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