Skip to content

Commit 8aa9cfe

Browse files
committed
std.tar: chore - update to latest zig
* builtins * mem.alignForward * fs.file.File.Kind
1 parent abba0c6 commit 8aa9cfe

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

lib/std/compress/tar/reader_test.zig

+10-10
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test "std.tar validate testdata headers" {
7272
.gid = 1000,
7373
.size = 200,
7474
.mtime = try unixTime(1392395740, 0),
75-
.type = @intToEnum(FileType, 0x53),
75+
.type = @enumFromInt(FileType, 0x53),
7676
.linkname = "",
7777
.uname = "david",
7878
.gname = "david",
@@ -86,7 +86,7 @@ test "std.tar validate testdata headers" {
8686
.gid = 1000,
8787
.size = 200,
8888
.mtime = try unixTime(1392342187, 0),
89-
.type = @intToEnum(FileType, 0x30),
89+
.type = @enumFromInt(FileType, 0x30),
9090
.linkname = "",
9191
.uname = "david",
9292
.gname = "david",
@@ -105,7 +105,7 @@ test "std.tar validate testdata headers" {
105105
.gid = 1000,
106106
.size = 200,
107107
.mtime = try unixTime(1392340456, 0),
108-
.type = @intToEnum(FileType, 0x30),
108+
.type = @enumFromInt(FileType, 0x30),
109109
.linkname = "",
110110
.uname = "david",
111111
.gname = "david",
@@ -125,7 +125,7 @@ test "std.tar validate testdata headers" {
125125
.gid = 1000,
126126
.size = 200,
127127
.mtime = try unixTime(1392337404, 0),
128-
.type = @intToEnum(FileType, 0x30),
128+
.type = @enumFromInt(FileType, 0x30),
129129
.linkname = "",
130130
.uname = "david",
131131
.gname = "david",
@@ -145,7 +145,7 @@ test "std.tar validate testdata headers" {
145145
.gid = 1000,
146146
.size = 4,
147147
.mtime = try unixTime(1392398319, 0),
148-
.type = @intToEnum(FileType, 0x30),
148+
.type = @enumFromInt(FileType, 0x30),
149149
.linkname = "",
150150
.uname = "david",
151151
.gname = "david",
@@ -426,7 +426,7 @@ test "std.tar validate testdata headers" {
426426
.gid = 1000,
427427
.size = 14,
428428
.mtime = try unixTime(1441973427, 0),
429-
.type = @intToEnum(FileType, 'D'),
429+
.type = @enumFromInt(FileType, 'D'),
430430
.uname = "rawr",
431431
.gname = "dsnet",
432432
.atime = try unixTime(1441974501, 0),
@@ -452,7 +452,7 @@ test "std.tar validate testdata headers" {
452452
.gid = 1000,
453453
.size = 536870912,
454454
.mtime = try unixTime(1441973427, 0),
455-
.type = @intToEnum(FileType, 'S'),
455+
.type = @enumFromInt(FileType, 'S'),
456456
.uname = "rawr",
457457
.gname = "dsnet",
458458
.atime = try unixTime(1441991948, 0),
@@ -467,7 +467,7 @@ test "std.tar validate testdata headers" {
467467
.name = "bar",
468468
.linkname = "PAX4/PAX4/long-linkpath-name",
469469
.mtime = try unixTime(0, 0),
470-
.type = @intToEnum(tar.FileType, '2'),
470+
.type = @enumFromInt(tar.FileType, '2'),
471471
.pax_recs = &.{
472472
"linkpath", "PAX4/PAX4/long-linkpath-name",
473473
},
@@ -715,7 +715,7 @@ test "std.tar validate testdata headers" {
715715
}
716716

717717
if (actual.size == -1) continue;
718-
const block_size = std.mem.alignForwardGeneric(usize, @intCast(usize, actual.size), 512);
718+
const block_size = std.mem.alignForward(usize, @intCast(usize, actual.size), 512);
719719
// validate checksums if exist or skip over file contents
720720
if (test_case.chksums.len > i) {
721721
var h = std.crypto.hash.Md5.init(.{});
@@ -746,7 +746,7 @@ test "std.tar validate testdata headers" {
746746
}
747747

748748
if (test_case.err) |e| {
749-
if (e != merr) {
749+
if (merr == null or e != merr.?) {
750750
errors += 1;
751751
std.log.err("errors don't match. expecting {!} found {?!}", .{ e, merr });
752752
}

lib/std/tar.zig

+13-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub const FileType = enum(u8) {
2424
gnu_long_link = 'K',
2525
_,
2626

27-
pub const sentinel = @intToEnum(FileType, 0xff);
27+
pub const sentinel = @enumFromInt(FileType, 0xff);
2828

2929
pub const NamedTypesBitset = std.StaticBitSet(128);
3030

@@ -35,21 +35,21 @@ pub const FileType = enum(u8) {
3535
.symbolic_link, .character_special, .block_special, .fifo,
3636
.contiguous,
3737
}) |ft|
38-
result.set(@enumToInt(ft));
38+
result.set(@intFromEnum(ft));
3939
break :blk result;
4040
};
4141

4242
pub fn isNamedType(ft: FileType) bool {
4343
return
4444
// verify not beyond NamedTypesBitset.bit_length to avoid assertion
4545
// failure in std.bit_set
46-
@enumToInt(ft) < NamedTypesBitset.bit_length and
47-
named_types_bitset.isSet(@enumToInt(ft));
46+
@intFromEnum(ft) < NamedTypesBitset.bit_length and
47+
named_types_bitset.isSet(@intFromEnum(ft));
4848
}
4949

5050
pub fn tagName(ft: FileType) ?[]const u8 {
5151
return inline for (std.meta.fields(FileType)) |f| {
52-
if (@enumToInt(ft) == f.value) break f.name;
52+
if (@intFromEnum(ft) == f.value) break f.name;
5353
} else null;
5454
}
5555
};
@@ -76,12 +76,12 @@ fn parseNumeric(b: []const u8) !i64 {
7676
// data bytes and treat the value as an unsigned number.
7777

7878
// inv = 0xff if negative else 0
79-
const inv = @as(u8, @boolToInt(b[0] & 0x40 != 0)) * 0xff;
79+
const inv = @as(u8, @intFromBool(b[0] & 0x40 != 0)) * 0xff;
8080

8181
var x: u64 = 0;
8282
for (0..b.len) |i| {
8383
// ignore the signal bit in first byte
84-
const mask = @as(u8, 0xff) >> @boolToInt(i == 0);
84+
const mask = @as(u8, 0xff) >> @intFromBool(i == 0);
8585
const c = b[i] ^ inv & mask;
8686
if (x > 0x00ff_ffff_ffff_ffff) return error.Overflow;
8787
x = x << 8 | c;
@@ -442,14 +442,14 @@ pub const Header = struct {
442442
// TODO remove when unused
443443
pub fn format(h: Header, comptime _: []const u8, _: fmt.FormatOptions, writer: anytype) !void {
444444
const tagname = inline for (std.meta.fields(FileType)) |field| {
445-
if (@enumToInt(h.type) == field.value) break field.name;
445+
if (@intFromEnum(h.type) == field.value) break field.name;
446446
} else "null";
447447
try writer.print("type={s} size={} name={s} mtime={} mode=0o{o}", .{ tagname, h.size, h.name, h.mtime, h.mode });
448448
try debugFormatSet(h.fmt, writer);
449449
}
450450

451451
fn structField(comptime field_enum: std.meta.FieldEnum(Header)) std.builtin.Type.StructField {
452-
return @typeInfo(Header).Struct.fields[@enumToInt(field_enum)];
452+
return @typeInfo(Header).Struct.fields[@intFromEnum(field_enum)];
453453
}
454454

455455
fn fieldDefault(comptime field: std.builtin.Type.StructField) field.type {
@@ -766,7 +766,7 @@ pub fn HeaderIterator(comptime Reader: type) type {
766766
size: usize,
767767
outbuf: *std.ArrayListUnmanaged(u8),
768768
) ![]u8 {
769-
var want = mem.alignForwardGeneric(usize, size, block_len);
769+
var want = mem.alignForward(usize, size, block_len);
770770
outbuf.items.len = 0;
771771
var w = outbuf.writer(self.allocator);
772772
var buf: [block_len]u8 = undefined;
@@ -1080,7 +1080,7 @@ fn makeSymLink(dir: fs.Dir, target_path: []const u8, symlink_path: []const u8) !
10801080
};
10811081
defer file.close();
10821082
const stat = try file.stat();
1083-
break :blk stat.kind == .Directory;
1083+
break :blk stat.kind == .directory;
10841084
};
10851085
try dir.symLink(target_path, symlink_path, .{ .is_directory = is_directory });
10861086
}
@@ -1146,7 +1146,7 @@ pub fn pipeToFileSystem(
11461146
defer file.close();
11471147
const size = math.cast(usize, header.size) orelse
11481148
return error.Header;
1149-
const want = mem.alignForwardGeneric(usize, size, block_len);
1149+
const want = mem.alignForward(usize, size, block_len);
11501150
var lim_reader = std.io.limitedReader(reader, want);
11511151
var bytes_left = size;
11521152
while (true) {
@@ -1195,7 +1195,7 @@ pub fn pipeToFileSystem(
11951195
format.setIntersection(fmt_pax);
11961196
},
11971197
else => {
1198-
log.err("unsupported type '{?s}':{}", .{ header.type.tagName(), @enumToInt(header.type) });
1198+
log.err("unsupported type '{?s}':{}", .{ header.type.tagName(), @intFromEnum(header.type) });
11991199
return error.TarUnexpectedFileType;
12001200
},
12011201
}

0 commit comments

Comments
 (0)