fixes for zig 0.10.0-dev.2473+e498fb155

This commit is contained in:
Motiejus Jakštys 2022-06-05 23:11:13 +03:00
parent d71f0d615b
commit 20bfa60f26
4 changed files with 14 additions and 14 deletions

View File

@ -456,9 +456,7 @@ fn usersSection(
while (i < corpus.users.len) : (i += 1) { while (i < corpus.users.len) : (i += 1) {
// TODO: this is inefficient by calling `.slice()` on every iteration // TODO: this is inefficient by calling `.slice()` on every iteration
const user = corpus.users.get(i); const user = corpus.users.get(i);
const user_offset = math.cast(u35, blob.items.len) catch |err| switch (err) { const user_offset = math.cast(u35, blob.items.len) orelse return error.TooMany;
error.Overflow => return error.TooMany,
};
assert(user_offset & 7 == 0); assert(user_offset & 7 == 0);
idx2offset[i] = @truncate(u32, user_offset >> 3); idx2offset[i] = @truncate(u32, user_offset >> 3);
try PackedUser.packTo( try PackedUser.packTo(

View File

@ -51,17 +51,23 @@ pub const TestFile = struct {
var tmp = testing.tmpDir(.{}); var tmp = testing.tmpDir(.{});
errdefer tmp.cleanup(); errdefer tmp.cleanup();
const base_path = blk: {
const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
const real_path = try fs.realpathAlloc(allocator, relative_path);
allocator.free(relative_path);
break :blk real_path;
};
const full_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "db.turbo\x00" });
allocator.free(base_path);
const mode = os.O.RDWR | os.O.CREAT | os.O.EXCL; const mode = os.O.RDWR | os.O.CREAT | os.O.EXCL;
const fd = try os.openat(tmp.dir.fd, "db.turbo", mode, 0o666); const fd = try os.openat(tmp.dir.fd, "db.turbo", mode, 0o666);
defer os.close(fd); defer os.close(fd);
_ = try os.writev(fd, db.iov().constSlice()); _ = try os.writev(fd, db.iov().constSlice());
const dir_path = try tmp.getFullPath(allocator);
defer allocator.free(dir_path);
const full = &[_][]const u8{ dir_path, "db.turbo\x00" }; return TestFile{ .dir = tmp, .path = full_path[0 .. full_path.len - 1 :0] };
var result = try fs.path.join(allocator, full);
return TestFile{ .dir = tmp, .path = result[0 .. result.len - 1 :0] };
} }
pub fn deinit(self: *TestFile, allocator: Allocator) void { pub fn deinit(self: *TestFile, allocator: Allocator) void {

View File

@ -3,7 +3,7 @@ const std = @import("std");
extern fn bdz_search_packed(packed_mphf: [*]const u8, key: [*]const u8, len: c_uint) u32; extern fn bdz_search_packed(packed_mphf: [*]const u8, key: [*]const u8, len: c_uint) u32;
pub fn search(packed_mphf: []const u8, key: []const u8) u32 { pub fn search(packed_mphf: []const u8, key: []const u8) u32 {
const len = std.math.cast(c_uint, key.len) catch unreachable; const len = std.math.cast(c_uint, key.len).?;
return @as(u32, bdz_search_packed(packed_mphf.ptr, key.ptr, len)); return @as(u32, bdz_search_packed(packed_mphf.ptr, key.ptr, len));
} }

View File

@ -1,11 +1,7 @@
const std = @import("std"); const std = @import("std");
pub fn downCast(comptime T: type, n: u64) error{InvalidRecord}!T { pub fn downCast(comptime T: type, n: u64) error{InvalidRecord}!T {
return std.math.cast(T, n) catch |err| switch (err) { return std.math.cast(T, n) orelse return error.InvalidRecord;
error.Overflow => {
return error.InvalidRecord;
},
};
} }
pub fn utf8(s: []const u8) error{InvalidRecord}!void { pub fn utf8(s: []const u8) error{InvalidRecord}!void {