some stage2 cleanups
This commit is contained in:
parent
5d4f17e6bf
commit
127d44e375
16
src/DB.zig
16
src/DB.zig
@ -297,7 +297,9 @@ pub fn packCGroupNoMembers(group: *const PackedGroup, buf: []u8) error{BufferToo
|
|||||||
return CGroup{
|
return CGroup{
|
||||||
.gr_name = buf[name_start .. name_start + name.len :0].ptr,
|
.gr_name = buf[name_start .. name_start + name.len :0].ptr,
|
||||||
.gr_gid = group.gid(),
|
.gr_gid = group.gid(),
|
||||||
.gr_mem = member_ptrs.ptr,
|
// TODO: how can we use bytesAsSlice in a way that does not need
|
||||||
|
// this ugly ptrCast?
|
||||||
|
.gr_mem = @ptrCast([*:null]align(1) const ?[*:0]const u8, member_ptrs.ptr),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,6 +337,7 @@ pub fn packCGroup(self: *const DB, group: *const PackedGroup, buf: []u8) error{B
|
|||||||
const ptr_end = @sizeOf(?[*:0]const u8) * (num_members + 1);
|
const ptr_end = @sizeOf(?[*:0]const u8) * (num_members + 1);
|
||||||
if (ptr_end > buf.len)
|
if (ptr_end > buf.len)
|
||||||
return error.BufferTooSmall;
|
return error.BufferTooSmall;
|
||||||
|
|
||||||
var member_ptrs = mem.bytesAsSlice(?[*:0]const u8, buf[0..ptr_end]);
|
var member_ptrs = mem.bytesAsSlice(?[*:0]const u8, buf[0..ptr_end]);
|
||||||
member_ptrs[member_ptrs.len - 1] = null;
|
member_ptrs[member_ptrs.len - 1] = null;
|
||||||
var buf_offset: usize = ptr_end;
|
var buf_offset: usize = ptr_end;
|
||||||
@ -352,10 +355,7 @@ pub fn packCGroup(self: *const DB, group: *const PackedGroup, buf: []u8) error{B
|
|||||||
buf_offset += name.len;
|
buf_offset += name.len;
|
||||||
buf[buf_offset] = 0;
|
buf[buf_offset] = 0;
|
||||||
buf_offset += 1;
|
buf_offset += 1;
|
||||||
|
member_ptrs[i] = buf[start .. buf_offset - 1 :0];
|
||||||
// TODO: arr[i] = buf[...] triggers a bug in zig pre-0.10
|
|
||||||
const terminated = buf[start .. buf_offset - 1 :0];
|
|
||||||
member_ptrs[i] = terminated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = group.name();
|
const name = group.name();
|
||||||
@ -366,7 +366,9 @@ pub fn packCGroup(self: *const DB, group: *const PackedGroup, buf: []u8) error{B
|
|||||||
return CGroup{
|
return CGroup{
|
||||||
.gr_name = buf[buf_offset .. buf_offset + name.len :0].ptr,
|
.gr_name = buf[buf_offset .. buf_offset + name.len :0].ptr,
|
||||||
.gr_gid = group.gid(),
|
.gr_gid = group.gid(),
|
||||||
.gr_mem = member_ptrs.ptr,
|
// TODO: how can we use bytesAsSlice in a way that does not need
|
||||||
|
// this ugly ptrCast?
|
||||||
|
.gr_mem = @ptrCast([*:null]align(1) const ?[*:0]const u8, member_ptrs.ptr),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,7 +670,7 @@ fn groupsSection(
|
|||||||
|
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (i < corpus.groups.len) : (i += 1) {
|
while (i < corpus.groups.len) : (i += 1) {
|
||||||
// TODO: this is inefficient; it's calling `.slice()` on every iteration
|
// TODO: this may be inefficient; it's calling `.slice()` on every iteration
|
||||||
const group = corpus.groups.get(i);
|
const group = corpus.groups.get(i);
|
||||||
const group_offset = @intCast(u32, blob.items.len);
|
const group_offset = @intCast(u32, blob.items.len);
|
||||||
assert(group_offset & 7 == 0);
|
assert(group_offset & 7 == 0);
|
||||||
|
@ -129,9 +129,8 @@ pub const CGroup = extern struct {
|
|||||||
gr_name: [*:0]const u8,
|
gr_name: [*:0]const u8,
|
||||||
gr_passwd: [*:0]const u8 = "x",
|
gr_passwd: [*:0]const u8 = "x",
|
||||||
gr_gid: u32,
|
gr_gid: u32,
|
||||||
// Should be [*:null]align(1) const ?[*:0]const u8
|
//gr_mem: [*:]align(1) const ?[*:0]const u8,
|
||||||
// https://github.com/ziglang/zig/issues/7517
|
gr_mem: [*:null]align(1) const ?[*:0]const u8,
|
||||||
gr_mem: [*]align(1) const ?[*:0]const u8,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// size of the pointer to a single member.
|
// size of the pointer to a single member.
|
||||||
|
@ -46,13 +46,10 @@ const Info = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
// This line is here because of https://github.com/ziglang/zig/issues/7807
|
|
||||||
const argv: []const [*:0]const u8 = os.argv;
|
|
||||||
|
|
||||||
const stderr = io.getStdErr().writer();
|
const stderr = io.getStdErr().writer();
|
||||||
const stdout = io.getStdOut().writer();
|
const stdout = io.getStdOut().writer();
|
||||||
|
|
||||||
const return_code = execute(stdout, stderr, argv[1..]);
|
const return_code = execute(stdout, stderr, os.argv[1..]);
|
||||||
os.exit(return_code);
|
os.exit(return_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,13 +36,10 @@ const usage =
|
|||||||
;
|
;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
// This line is here because of https://github.com/ziglang/zig/issues/7807
|
|
||||||
const argv: []const [*:0]const u8 = os.argv;
|
|
||||||
|
|
||||||
const stderr = io.getStdErr().writer();
|
const stderr = io.getStdErr().writer();
|
||||||
const stdout = io.getStdOut().writer();
|
const stdout = io.getStdOut().writer();
|
||||||
|
|
||||||
const return_code = execute(stdout, stderr, argv[1..]);
|
const return_code = execute(stdout, stderr, os.argv[1..]);
|
||||||
os.exit(return_code);
|
os.exit(return_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,12 +36,10 @@ const shells = &[_][]const u8{
|
|||||||
|
|
||||||
pub fn main() void {
|
pub fn main() void {
|
||||||
// This line is here because of https://github.com/ziglang/zig/issues/7807
|
// This line is here because of https://github.com/ziglang/zig/issues/7807
|
||||||
const argv: []const [*:0]const u8 = os.argv;
|
|
||||||
|
|
||||||
const stderr = io.getStdErr().writer();
|
const stderr = io.getStdErr().writer();
|
||||||
const stdout = io.getStdOut().writer();
|
const stdout = io.getStdOut().writer();
|
||||||
|
|
||||||
execute(stdout, stderr, argv[1..]) catch |err| switch (err) {
|
execute(stdout, stderr, os.argv[1..]) catch |err| switch (err) {
|
||||||
error.User => os.exit(1),
|
error.User => os.exit(1),
|
||||||
error.IO => os.exit(3),
|
error.IO => os.exit(3),
|
||||||
};
|
};
|
||||||
@ -79,8 +77,7 @@ fn execute(
|
|||||||
const num_groups = parseInt(stderr, myflags, "--num-groups", 10000) orelse return error.User;
|
const num_groups = parseInt(stderr, myflags, "--num-groups", 10000) orelse return error.User;
|
||||||
const avg_members = parseInt(stderr, myflags, "--avg-members", 1000) orelse return error.User;
|
const avg_members = parseInt(stderr, myflags, "--avg-members", 1000) orelse return error.User;
|
||||||
|
|
||||||
// longest possible path name: 16k? dunno.
|
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
|
||||||
var buf: [1 << 14]u8 = undefined;
|
|
||||||
var fixed = std.heap.FixedBufferAllocator.init(buf[0..]);
|
var fixed = std.heap.FixedBufferAllocator.init(buf[0..]);
|
||||||
const fixed_a = fixed.allocator();
|
const fixed_a = fixed.allocator();
|
||||||
const dir = myflags.argFlag("--directory") orelse ".";
|
const dir = myflags.argFlag("--directory") orelse ".";
|
||||||
|
@ -26,14 +26,12 @@ const usage =
|
|||||||
;
|
;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
// This line is here because of https://github.com/ziglang/zig/issues/7807
|
|
||||||
const argv: []const [*:0]const u8 = os.argv;
|
|
||||||
const gpa = heap.raw_c_allocator;
|
const gpa = heap.raw_c_allocator;
|
||||||
|
|
||||||
const stderr = io.getStdErr().writer();
|
const stderr = io.getStdErr().writer();
|
||||||
const stdout = io.getStdOut().writer();
|
const stdout = io.getStdOut().writer();
|
||||||
|
|
||||||
const return_code = execute(gpa, stdout, stderr, argv[1..]);
|
const return_code = execute(gpa, stdout, stderr, os.argv[1..]);
|
||||||
os.exit(return_code);
|
os.exit(return_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,8 +186,7 @@ test "turbonss-unix2db smoke test" {
|
|||||||
defer corpus.deinit();
|
defer corpus.deinit();
|
||||||
|
|
||||||
var tmp = testing.tmpDir(.{});
|
var tmp = testing.tmpDir(.{});
|
||||||
// TODO: defer
|
defer tmp.cleanup();
|
||||||
errdefer tmp.cleanup();
|
|
||||||
|
|
||||||
const tmp_path = blk: {
|
const tmp_path = blk: {
|
||||||
const relative_path = try fs.path.join(allocator, &[_][]const u8{
|
const relative_path = try fs.path.join(allocator, &[_][]const u8{
|
||||||
|
@ -100,7 +100,6 @@ test "validate name" {
|
|||||||
try testing.expectError(error.InvalidRecord, got);
|
try testing.expectError(error.InvalidRecord, got);
|
||||||
try testing.expectEqualStrings(wantErr, err.unwrap().constSlice());
|
try testing.expectEqualStrings(wantErr, err.unwrap().constSlice());
|
||||||
} else {
|
} else {
|
||||||
// TODO: how to assert `got` is a non-error in a single line?
|
|
||||||
if (got) |_| {} else |_| return error.TestUnExpectedError;
|
if (got) |_| {} else |_| return error.TestUnExpectedError;
|
||||||
try testing.expectEqualStrings("", err.unwrap().constSlice());
|
try testing.expectEqualStrings("", err.unwrap().constSlice());
|
||||||
}
|
}
|
||||||
@ -127,7 +126,6 @@ test "validate gecos" {
|
|||||||
try testing.expectError(error.InvalidRecord, got);
|
try testing.expectError(error.InvalidRecord, got);
|
||||||
try testing.expectEqualStrings(wantErr, err.unwrap().constSlice());
|
try testing.expectEqualStrings(wantErr, err.unwrap().constSlice());
|
||||||
} else {
|
} else {
|
||||||
// TODO: how to assert `got` is a non-error in a single line?
|
|
||||||
if (got) |_| {} else |_| return error.TestUnExpectedError;
|
if (got) |_| {} else |_| return error.TestUnExpectedError;
|
||||||
try testing.expectEqualStrings("", err.unwrap().constSlice());
|
try testing.expectEqualStrings("", err.unwrap().constSlice());
|
||||||
}
|
}
|
||||||
@ -154,7 +152,6 @@ test "validate path" {
|
|||||||
try testing.expectError(error.InvalidRecord, got);
|
try testing.expectError(error.InvalidRecord, got);
|
||||||
try testing.expectEqualStrings(wantErr, err.unwrap().constSlice());
|
try testing.expectEqualStrings(wantErr, err.unwrap().constSlice());
|
||||||
} else {
|
} else {
|
||||||
// TODO: how to assert `got` is a non-error in a single line?
|
|
||||||
if (got) |_| {} else |_| return error.TestUnExpectedError;
|
if (got) |_| {} else |_| return error.TestUnExpectedError;
|
||||||
try testing.expectEqualStrings("", err.unwrap().constSlice());
|
try testing.expectEqualStrings("", err.unwrap().constSlice());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user