mirror of
https://github.com/fairyglade/ly.git
synced 2026-09-22 03:50:23 +00:00
Update to Zig 0.17.0-dev.1824+7988f7952
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -28,9 +28,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
});
|
});
|
||||||
mod.addImport("zlua", zlua.module("zlua"));
|
mod.addImport("zlua", zlua.module("zlua"));
|
||||||
|
|
||||||
const translate_c = b.dependency("translate_c", .{
|
const translate_c = b.dependency("translate_c", .{});
|
||||||
.target = target,
|
|
||||||
});
|
|
||||||
|
|
||||||
addCImport(b, mod, translate_c, target, optimize, "pam", "#include <security/pam_appl.h>");
|
addCImport(b, mod, translate_c, target, optimize, "pam", "#include <security/pam_appl.h>");
|
||||||
addCImport(b, mod, translate_c, target, optimize, "utmp", "#include <utmpx.h>");
|
addCImport(b, mod, translate_c, target, optimize, "utmp", "#include <utmpx.h>");
|
||||||
|
|||||||
@@ -9,12 +9,12 @@
|
|||||||
.hash = "zigini-0.6.0-BSkB7UtYAAB6b6HEm3Pjj5WIy-uiuBYsNTNCUENVwL1t",
|
.hash = "zigini-0.6.0-BSkB7UtYAAB6b6HEm3Pjj5WIy-uiuBYsNTNCUENVwL1t",
|
||||||
},
|
},
|
||||||
.translate_c = .{
|
.translate_c = .{
|
||||||
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#2d71d6e68dd9e9ee1da2a248a1dcb5aeba683dec",
|
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#3da873cacdd7e9190fe1cf40372ddf5387c970ea",
|
||||||
.hash = "translate_c-0.0.0-Q_BUWtI4BwDTFS7O6WTn-3qixa_s81nw_C0FHbf2aLqj",
|
.hash = "translate_c-0.0.0-Q_BUWktLBwBO7VLbmrOKUcAMRtE5fmOxI35189X5XbJs",
|
||||||
},
|
},
|
||||||
.zlua = .{
|
.zlua = .{
|
||||||
.url = "git+https://github.com/natecraddock/ziglua?ref=zig-0.16#8f271c82baa5fc43aa02a72f6da020c2025d9436",
|
.url = "git+https://github.com/AnErrupTion/ziglua?ref=zig-0.17#4159a5592a8de728022e0c491a3bdde7decbdc16",
|
||||||
.hash = "zlua-0.1.0-hGRpC2aABQD4D9PBVH3wAW8k32-I4969MRQ0CpOwoley",
|
.hash = "zlua-0.1.0-hGRpCw6VBQDaOiIiYsLOcQTlcJCpqDqIrhyDVqkanTSB",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|||||||
@@ -422,7 +422,7 @@ pub fn getNextUsernameEntry() ?UsernameEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getUsernameEntry(allocator: std.mem.Allocator, username: []const u8) ?UsernameEntry {
|
pub fn getUsernameEntry(allocator: std.mem.Allocator, username: []const u8) ?UsernameEntry {
|
||||||
const username_z = allocator.dupeZ(u8, username) catch return null;
|
const username_z = allocator.dupeSentinel(u8, username, 0) catch return null;
|
||||||
defer allocator.free(username_z);
|
defer allocator.free(username_z);
|
||||||
|
|
||||||
const entry = pwd.getpwnam(username_z);
|
const entry = pwd.getpwnam(username_z);
|
||||||
|
|||||||
@@ -131,13 +131,11 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
var arena = std.heap.ArenaAllocator.init(allocator);
|
var arena = std.heap.ArenaAllocator.init(allocator);
|
||||||
const arena_alloc = arena.allocator();
|
const arena_alloc = arena.allocator();
|
||||||
|
|
||||||
var maybe_load_error: ?anyerror = null;
|
|
||||||
errdefer |err| maybe_load_error = err;
|
|
||||||
|
|
||||||
const data = parseLua(arena_alloc, path) catch load_error: {
|
const data = parseLua(arena_alloc, path) catch load_error: {
|
||||||
break :load_error Struct{};
|
break :load_error Struct{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var maybe_load_error: ?anyerror = null;
|
||||||
if (global_errors.items.len != 0) {
|
if (global_errors.items.len != 0) {
|
||||||
maybe_load_error = error.InvalidConfig;
|
maybe_load_error = error.InvalidConfig;
|
||||||
}
|
}
|
||||||
@@ -176,8 +174,8 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
defer lua.pop(1); // pop ly table
|
defer lua.pop(1); // pop ly table
|
||||||
if (ly_type == .nil) return error.MissingLyTable;
|
if (ly_type == .nil) return error.MissingLyTable;
|
||||||
|
|
||||||
inline for (struc.fields) |field| {
|
inline for (struc.field_names, struc.field_types) |name, ftype| {
|
||||||
try setField(allocator, lua, field, &data);
|
try setField(allocator, lua, name, ftype, &data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
else => @compileError("Expected a struct."),
|
else => @compileError("Expected a struct."),
|
||||||
@@ -188,21 +186,47 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setField(allocator: std.mem.Allocator, lua: *Lua, comptime field: std.builtin.Type.StructField, data: *Struct) !void {
|
pub fn setField(
|
||||||
const type_info = @typeInfo(field.type);
|
allocator: std.mem.Allocator,
|
||||||
|
lua: *Lua,
|
||||||
|
comptime field_name: [:0]const u8,
|
||||||
|
field_type: type,
|
||||||
|
data: *Struct,
|
||||||
|
) !void {
|
||||||
|
return setFieldInner(
|
||||||
|
allocator,
|
||||||
|
lua,
|
||||||
|
field_name,
|
||||||
|
field_type,
|
||||||
|
data,
|
||||||
|
) catch |err| {
|
||||||
|
const value = lua.toString(-1) catch "";
|
||||||
|
const duped = allocator.dupe(u8, value) catch "";
|
||||||
|
errorHandler(@typeName(field_type), field_name, duped, err);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setFieldInner(
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
lua: *Lua,
|
||||||
|
comptime field_name: [:0]const u8,
|
||||||
|
field_type: type,
|
||||||
|
data: *Struct,
|
||||||
|
) !void {
|
||||||
|
const type_info = @typeInfo(field_type);
|
||||||
const actual_type, const is_optional = blk: {
|
const actual_type, const is_optional = blk: {
|
||||||
if (type_info == .optional) {
|
if (type_info == .optional) {
|
||||||
break :blk .{ type_info.optional.child, true };
|
break :blk .{ type_info.optional.child, true };
|
||||||
}
|
}
|
||||||
break :blk .{ field.type, false };
|
break :blk .{ field_type, false };
|
||||||
};
|
};
|
||||||
// push value to top of stack
|
// push value to top of stack
|
||||||
_ = lua.getField(-1, field.name);
|
_ = lua.getField(-1, field_name);
|
||||||
defer lua.pop(1);
|
defer lua.pop(1);
|
||||||
|
|
||||||
// handle null, i.e. undefined fields
|
// handle null, i.e. undefined fields
|
||||||
if (is_optional and lua.isNil(-1)) {
|
if (is_optional and lua.isNil(-1)) {
|
||||||
@field(data, field.name) = null;
|
@field(data, field_name) = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,17 +236,11 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
}
|
}
|
||||||
const actual_type_info = @typeInfo(actual_type);
|
const actual_type_info = @typeInfo(actual_type);
|
||||||
|
|
||||||
errdefer |err| {
|
|
||||||
const value = lua.toString(-1) catch "";
|
|
||||||
const duped = allocator.dupe(u8, value) catch "";
|
|
||||||
errorHandler(@typeName(field.type), field.name, duped, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dispatch depending on type
|
// dispatch depending on type
|
||||||
if (actual_type_info == .int and is_optional) {
|
if (actual_type_info == .int and is_optional) {
|
||||||
if (lua.isNumber(-1)) {
|
if (lua.isNumber(-1)) {
|
||||||
const value = try lua.toNumber(-1);
|
const value = try lua.toNumber(-1);
|
||||||
@field(data, field.name) = @trunc(value);
|
@field(data, field_name) = @trunc(value);
|
||||||
} else {
|
} else {
|
||||||
const str = try lua.toString(-1);
|
const str = try lua.toString(-1);
|
||||||
|
|
||||||
@@ -233,13 +251,13 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
|
|
||||||
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
||||||
|
|
||||||
@field(data, field.name) = if (codepoint) |cp| @intCast(cp) else null;
|
@field(data, field_name) = if (codepoint) |cp| @intCast(cp) else null;
|
||||||
}
|
}
|
||||||
// non null integer
|
// non null integer
|
||||||
} else if (actual_type_info == .int) {
|
} else if (actual_type_info == .int) {
|
||||||
if (lua.isNumber(-1)) {
|
if (lua.isNumber(-1)) {
|
||||||
const value = try lua.toNumber(-1);
|
const value = try lua.toNumber(-1);
|
||||||
@field(data, field.name) = @trunc(value);
|
@field(data, field_name) = @trunc(value);
|
||||||
} else {
|
} else {
|
||||||
const str = try lua.toString(-1);
|
const str = try lua.toString(-1);
|
||||||
|
|
||||||
@@ -250,27 +268,27 @@ pub fn LuaParser(comptime Struct: type) type {
|
|||||||
|
|
||||||
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
if (iter.nextCodepoint() != null) return error.ExpectedSingleCharacter;
|
||||||
|
|
||||||
@field(data, field.name) = @intCast(codepoint);
|
@field(data, field_name) = @intCast(codepoint);
|
||||||
}
|
}
|
||||||
} else if (actual_type_info == .float) { // all floats
|
} else if (actual_type_info == .float) { // all floats
|
||||||
const value = try lua.toNumber(-1);
|
const value = try lua.toNumber(-1);
|
||||||
@field(data, field.name) = @floatCast(value);
|
@field(data, field_name) = @floatCast(value);
|
||||||
} else if (actual_type_info == .bool) {
|
} else if (actual_type_info == .bool) {
|
||||||
if (!lua.isBoolean(-1)) return error.ExpectedBoolean;
|
if (!lua.isBoolean(-1)) return error.ExpectedBoolean;
|
||||||
const value = lua.toBoolean(-1);
|
const value = lua.toBoolean(-1);
|
||||||
@field(data, field.name) = value;
|
@field(data, field_name) = value;
|
||||||
} else if (actual_type == []const u8) {
|
} else if (actual_type == []const u8) {
|
||||||
const value = try lua.toString(-1);
|
const value = try lua.toString(-1);
|
||||||
const duped = try allocator.dupe(u8, value);
|
const duped = try allocator.dupe(u8, value);
|
||||||
@field(data, field.name) = duped;
|
@field(data, field_name) = duped;
|
||||||
} else if (actual_type == [:0]const u8) {
|
} else if (actual_type == [:0]const u8) {
|
||||||
const value = try lua.toString(-1);
|
const value = try lua.toString(-1);
|
||||||
const duped = try allocator.dupeSentinel(u8, value, 0);
|
const duped = try allocator.dupeSentinel(u8, value, 0);
|
||||||
@field(data, field.name) = duped;
|
@field(data, field_name) = duped;
|
||||||
} else if (actual_type_info == .@"enum") {
|
} else if (actual_type_info == .@"enum") {
|
||||||
const value = try lua.toString(-1);
|
const value = try lua.toString(-1);
|
||||||
const variant = std.meta.stringToEnum(actual_type, value) orelse return error.InvalidVariant;
|
const variant = std.meta.stringToEnum(actual_type, value) orelse return error.InvalidVariant;
|
||||||
@field(data, field.name) = variant;
|
@field(data, field_name) = variant;
|
||||||
} else unreachable;
|
} else unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
const translate_c_dep = b.dependency("translate_c", .{
|
const translate_c_dep = b.dependency("translate_c", .{});
|
||||||
.target = target,
|
|
||||||
});
|
|
||||||
|
|
||||||
const termbox2: Translator = .init(translate_c_dep, .{
|
const termbox2: Translator = .init(translate_c_dep, .{
|
||||||
.c_source_file = termbox_dep.path("termbox2.h"),
|
.c_source_file = termbox_dep.path("termbox2.h"),
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
.hash = "N-V-__8AAOEWBQDt5tNdIzIFY6n8DdZsCP-6MyLoNS20wgpA",
|
.hash = "N-V-__8AAOEWBQDt5tNdIzIFY6n8DdZsCP-6MyLoNS20wgpA",
|
||||||
},
|
},
|
||||||
.translate_c = .{
|
.translate_c = .{
|
||||||
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#2d71d6e68dd9e9ee1da2a248a1dcb5aeba683dec",
|
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#3da873cacdd7e9190fe1cf40372ddf5387c970ea",
|
||||||
.hash = "translate_c-0.0.0-Q_BUWtI4BwDTFS7O6WTn-3qixa_s81nw_C0FHbf2aLqj",
|
.hash = "translate_c-0.0.0-Q_BUWktLBwBO7VLbmrOKUcAMRtE5fmOxI35189X5XbJs",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ fn loginConv(
|
|||||||
for (0..message_count) |i| set_credentials: {
|
for (0..message_count) |i| set_credentials: {
|
||||||
switch (messages[i].?.msg_style) {
|
switch (messages[i].?.msg_style) {
|
||||||
interop.pam.PAM_PROMPT_ECHO_ON => {
|
interop.pam.PAM_PROMPT_ECHO_ON => {
|
||||||
username = allocator.dupeZ(u8, data.username) catch {
|
username = allocator.dupeSentinel(u8, data.username, 0) catch {
|
||||||
status = interop.pam.PAM_BUF_ERR;
|
status = interop.pam.PAM_BUF_ERR;
|
||||||
break :set_credentials;
|
break :set_credentials;
|
||||||
};
|
};
|
||||||
@@ -341,7 +341,7 @@ fn loginConv(
|
|||||||
data.authreq_responded = true;
|
data.authreq_responded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
password = allocator.dupeZ(u8, pass) catch {
|
password = allocator.dupeSentinel(u8, pass, 0) catch {
|
||||||
status = interop.pam.PAM_BUF_ERR;
|
status = interop.pam.PAM_BUF_ERR;
|
||||||
break :set_credentials;
|
break :set_credentials;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -154,8 +154,8 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var gpa: std.heap.DebugAllocator(.{
|
var gpa: std.heap.DebugAllocator(.{
|
||||||
.never_unmap = builtin.mode == .Debug,
|
.never_unmap = builtin.mode == .debug,
|
||||||
.retain_metadata = builtin.mode == .Debug,
|
.retain_metadata = builtin.mode == .debug,
|
||||||
}) = .init;
|
}) = .init;
|
||||||
defer if (gpa.deinit() == .leak) std.log.err("attention please, memory has been leaked!", .{});
|
defer if (gpa.deinit() == .leak) std.log.err("attention please, memory has been leaked!", .{});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user