Update to Zig 0.17.0-dev.1824+7988f7952

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2026-08-25 23:36:43 +02:00
commit a9cbfbddbf
No known key found for this signature in database
8 changed files with 56 additions and 42 deletions

View file

@ -28,9 +28,7 @@ pub fn build(b: *std.Build) void {
});
mod.addImport("zlua", zlua.module("zlua"));
const translate_c = b.dependency("translate_c", .{
.target = target,
});
const translate_c = b.dependency("translate_c", .{});
addCImport(b, mod, translate_c, target, optimize, "pam", "#include <security/pam_appl.h>");
addCImport(b, mod, translate_c, target, optimize, "utmp", "#include <utmpx.h>");

View file

@ -9,12 +9,12 @@
.hash = "zigini-0.6.0-BSkB7UtYAAB6b6HEm3Pjj5WIy-uiuBYsNTNCUENVwL1t",
},
.translate_c = .{
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#2d71d6e68dd9e9ee1da2a248a1dcb5aeba683dec",
.hash = "translate_c-0.0.0-Q_BUWtI4BwDTFS7O6WTn-3qixa_s81nw_C0FHbf2aLqj",
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#3da873cacdd7e9190fe1cf40372ddf5387c970ea",
.hash = "translate_c-0.0.0-Q_BUWktLBwBO7VLbmrOKUcAMRtE5fmOxI35189X5XbJs",
},
.zlua = .{
.url = "git+https://github.com/natecraddock/ziglua?ref=zig-0.16#8f271c82baa5fc43aa02a72f6da020c2025d9436",
.hash = "zlua-0.1.0-hGRpC2aABQD4D9PBVH3wAW8k32-I4969MRQ0CpOwoley",
.url = "git+https://github.com/AnErrupTion/ziglua?ref=zig-0.17#4159a5592a8de728022e0c491a3bdde7decbdc16",
.hash = "zlua-0.1.0-hGRpCw6VBQDaOiIiYsLOcQTlcJCpqDqIrhyDVqkanTSB",
},
},
.paths = .{

View file

@ -422,7 +422,7 @@ pub fn getNextUsernameEntry() ?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);
const entry = pwd.getpwnam(username_z);

View file

@ -131,13 +131,11 @@ pub fn LuaParser(comptime Struct: type) type {
var arena = std.heap.ArenaAllocator.init(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: {
break :load_error Struct{};
};
var maybe_load_error: ?anyerror = null;
if (global_errors.items.len != 0) {
maybe_load_error = error.InvalidConfig;
}
@ -176,8 +174,8 @@ pub fn LuaParser(comptime Struct: type) type {
defer lua.pop(1); // pop ly table
if (ly_type == .nil) return error.MissingLyTable;
inline for (struc.fields) |field| {
try setField(allocator, lua, field, &data);
inline for (struc.field_names, struc.field_types) |name, ftype| {
try setField(allocator, lua, name, ftype, &data);
}
},
else => @compileError("Expected a struct."),
@ -188,21 +186,47 @@ pub fn LuaParser(comptime Struct: type) type {
return data;
}
pub fn setField(allocator: std.mem.Allocator, lua: *Lua, comptime field: std.builtin.Type.StructField, data: *Struct) !void {
const type_info = @typeInfo(field.type);
pub fn setField(
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: {
if (type_info == .optional) {
break :blk .{ type_info.optional.child, true };
}
break :blk .{ field.type, false };
break :blk .{ field_type, false };
};
// push value to top of stack
_ = lua.getField(-1, field.name);
_ = lua.getField(-1, field_name);
defer lua.pop(1);
// handle null, i.e. undefined fields
if (is_optional and lua.isNil(-1)) {
@field(data, field.name) = null;
@field(data, field_name) = null;
return;
}
@ -212,17 +236,11 @@ pub fn LuaParser(comptime Struct: type) 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
if (actual_type_info == .int and is_optional) {
if (lua.isNumber(-1)) {
const value = try lua.toNumber(-1);
@field(data, field.name) = @trunc(value);
@field(data, field_name) = @trunc(value);
} else {
const str = try lua.toString(-1);
@ -233,13 +251,13 @@ pub fn LuaParser(comptime Struct: type) type {
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
} else if (actual_type_info == .int) {
if (lua.isNumber(-1)) {
const value = try lua.toNumber(-1);
@field(data, field.name) = @trunc(value);
@field(data, field_name) = @trunc(value);
} else {
const str = try lua.toString(-1);
@ -250,27 +268,27 @@ pub fn LuaParser(comptime Struct: type) type {
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
const value = try lua.toNumber(-1);
@field(data, field.name) = @floatCast(value);
@field(data, field_name) = @floatCast(value);
} else if (actual_type_info == .bool) {
if (!lua.isBoolean(-1)) return error.ExpectedBoolean;
const value = lua.toBoolean(-1);
@field(data, field.name) = value;
@field(data, field_name) = value;
} else if (actual_type == []const u8) {
const value = try lua.toString(-1);
const duped = try allocator.dupe(u8, value);
@field(data, field.name) = duped;
@field(data, field_name) = duped;
} else if (actual_type == [:0]const u8) {
const value = try lua.toString(-1);
const duped = try allocator.dupeSentinel(u8, value, 0);
@field(data, field.name) = duped;
@field(data, field_name) = duped;
} else if (actual_type_info == .@"enum") {
const value = try lua.toString(-1);
const variant = std.meta.stringToEnum(actual_type, value) orelse return error.InvalidVariant;
@field(data, field.name) = variant;
@field(data, field_name) = variant;
} else unreachable;
}

View file

@ -28,9 +28,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
const translate_c_dep = b.dependency("translate_c", .{
.target = target,
});
const translate_c_dep = b.dependency("translate_c", .{});
const termbox2: Translator = .init(translate_c_dep, .{
.c_source_file = termbox_dep.path("termbox2.h"),

View file

@ -12,8 +12,8 @@
.hash = "N-V-__8AAOEWBQDt5tNdIzIFY6n8DdZsCP-6MyLoNS20wgpA",
},
.translate_c = .{
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#2d71d6e68dd9e9ee1da2a248a1dcb5aeba683dec",
.hash = "translate_c-0.0.0-Q_BUWtI4BwDTFS7O6WTn-3qixa_s81nw_C0FHbf2aLqj",
.url = "git+https://codeberg.org/ziglang/translate-c?ref=master#3da873cacdd7e9190fe1cf40372ddf5387c970ea",
.hash = "translate_c-0.0.0-Q_BUWktLBwBO7VLbmrOKUcAMRtE5fmOxI35189X5XbJs",
},
},
.paths = .{

View file

@ -326,7 +326,7 @@ fn loginConv(
for (0..message_count) |i| set_credentials: {
switch (messages[i].?.msg_style) {
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;
break :set_credentials;
};
@ -341,7 +341,7 @@ fn loginConv(
data.authreq_responded = true;
}
password = allocator.dupeZ(u8, pass) catch {
password = allocator.dupeSentinel(u8, pass, 0) catch {
status = interop.pam.PAM_BUF_ERR;
break :set_credentials;
};

View file

@ -154,8 +154,8 @@ pub fn main(init: std.process.Init) !void {
}
var gpa: std.heap.DebugAllocator(.{
.never_unmap = builtin.mode == .Debug,
.retain_metadata = builtin.mode == .Debug,
.never_unmap = builtin.mode == .debug,
.retain_metadata = builtin.mode == .debug,
}) = .init;
defer if (gpa.deinit() == .leak) std.log.err("attention please, memory has been leaked!", .{});