Skip to content

Commit 19ccd5c

Browse files
authored
Merge pull request #82 from kubkon/zig-sync
update to latest zig
2 parents 72dae32 + 32a2d1e commit 19ccd5c

15 files changed

+39
-40
lines changed

build.zig.zon

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
.dependencies = .{
66
.@"zig-yaml" = .{
7-
.url = "https://github.com/kubkon/zig-yaml/archive/2b6de6354b7211abd1cf6c9d22d0b23402613e24.tar.gz",
8-
.hash = "122055ce75eb5bf7dafab5dcb007f945672e10bf89156f2eec4ae0de6e682adb2596",
7+
.url = "https://github.com/kubkon/zig-yaml/archive/1ed4925bed911b73a189526a6ad82bd8c5c2079a.tar.gz",
8+
.hash = "1220f56d186377820d7ad62ee03987acdd53bc24da83e8f6dff571bc7343f789f69a",
99
},
1010
.@"zig-dis-x86_64" = .{
11-
.url = "https://github.com/kubkon/zig-dis-x86_64/archive/7b27010130df6763f813d2439e075e45327ac745.tar.gz",
12-
.hash = "122047272f21ffb6e2577dc000c3bea9377049252c4bdcf6c56a4d56ad59b1ae6280",
11+
.url = "https://github.com/kubkon/zig-dis-x86_64/archive/a9155631990aa6d56fa06fddef304cabb94a0681.tar.gz",
12+
.hash = "1220a4d63ba372f6b5a0fc262f863572dc119727b469f6ccf527ad91790e353bb0f0",
1313
},
1414
},
1515

16-
.paths = .{ "" },
16+
.paths = .{""},
1717
}

src/Elf.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,7 @@ fn writeAtoms(self: *Elf) !void {
21242124

21252125
log.debug("writing atoms in '{s}' section", .{self.shstrtab.getAssumeExists(shdr.sh_name)});
21262126

2127-
var buffer = try self.base.allocator.alloc(u8, shdr.sh_size);
2127+
const buffer = try self.base.allocator.alloc(u8, shdr.sh_size);
21282128
defer self.base.allocator.free(buffer);
21292129
const padding_byte: u8 = if (shdr.sh_type == elf.SHT_PROGBITS and
21302130
shdr.sh_flags & elf.SHF_EXECINSTR != 0)

src/Elf/eh_frame.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub const Iterator = struct {
223223
var stream = std.io.fixedBufferStream(it.data[it.pos..]);
224224
const reader = stream.reader();
225225

226-
var size = try reader.readInt(u32, .little);
226+
const size = try reader.readInt(u32, .little);
227227
if (size == 0xFFFFFFFF) @panic("TODO");
228228

229229
const id = try reader.readInt(u32, .little);

src/MachO.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub fn flush(self: *MachO) !void {
388388
const size = linkedit.fileoff - start;
389389
if (size > 0) {
390390
log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });
391-
var padding = try self.base.allocator.alloc(u8, size);
391+
const padding = try self.base.allocator.alloc(u8, size);
392392
defer self.base.allocator.free(padding);
393393
@memset(padding, 0);
394394
try self.base.file.pwriteAll(padding, start);
@@ -3006,7 +3006,7 @@ fn writeDyldInfoData(self: *MachO) !void {
30063006
link_seg.filesize = needed_size;
30073007
assert(mem.isAlignedGeneric(u64, link_seg.fileoff + link_seg.filesize, @alignOf(u64)));
30083008

3009-
var buffer = try gpa.alloc(u8, needed_size);
3009+
const buffer = try gpa.alloc(u8, needed_size);
30103010
defer gpa.free(buffer);
30113011
@memset(buffer, 0);
30123012

src/MachO/Archive.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn parse(self: *Archive, allocator: Allocator, reader: anytype, macho_file:
112112
self.header = try reader.readStruct(ar_hdr);
113113

114114
const name_or_length = try self.header.nameOrLength();
115-
var embedded_name = try parseName(allocator, name_or_length, reader);
115+
const embedded_name = try parseName(allocator, name_or_length, reader);
116116
log.debug("parsing archive '{s}' at '{s}'", .{ embedded_name, self.name });
117117
defer allocator.free(embedded_name);
118118

@@ -138,7 +138,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader:
138138

139139
fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype, macho_file: *MachO) !void {
140140
const symtab_size = try reader.readInt(u32, .little);
141-
var symtab = try allocator.alloc(u8, symtab_size);
141+
const symtab = try allocator.alloc(u8, symtab_size);
142142
defer allocator.free(symtab);
143143

144144
reader.readNoEof(symtab) catch return macho_file.base.fatal(
@@ -147,7 +147,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype, m
147147
);
148148

149149
const strtab_size = try reader.readInt(u32, .little);
150-
var strtab = try allocator.alloc(u8, strtab_size);
150+
const strtab = try allocator.alloc(u8, strtab_size);
151151
defer allocator.free(strtab);
152152

153153
reader.readNoEof(strtab) catch return macho_file.base.fatal(

src/MachO/Dylib.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn parseFromBinary(
185185
.REEXPORT_DYLIB => {
186186
if (should_lookup_reexports) {
187187
// Parse install_name to dependent dylib.
188-
var id = try Id.fromLoadCommand(
188+
const id = try Id.fromLoadCommand(
189189
allocator,
190190
cmd.cast(macho.dylib_command).?,
191191
cmd.getDylibPathName(),
@@ -442,7 +442,7 @@ pub fn parseFromStub(
442442

443443
log.debug(" (found re-export '{s}')", .{lib});
444444

445-
var dep_id = try Id.default(allocator, lib);
445+
const dep_id = try Id.default(allocator, lib);
446446
try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id });
447447
}
448448
}
@@ -559,7 +559,7 @@ pub fn parseFromStub(
559559

560560
log.debug(" (found re-export '{s}')", .{lib});
561561

562-
var dep_id = try Id.default(allocator, lib);
562+
const dep_id = try Id.default(allocator, lib);
563563
try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id });
564564
}
565565
}

src/MachO/Object.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ pub fn getSourceSectionIndexByName(self: Object, segname: []const u8, sectname:
888888
} else return null;
889889
}
890890

891-
pub fn getSourceSections(self: Object) []const macho.section_64 {
891+
pub fn getSourceSections(self: Object) []align(1) const macho.section_64 {
892892
var it = LoadCommandIterator{
893893
.ncmds = self.header.ncmds,
894894
.buffer = self.contents[@sizeOf(macho.mach_header_64)..][0..self.header.sizeofcmds],

src/MachO/Trie.zig

+10-10
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub const Node = struct {
9595
// To: A -> C -> B
9696
const mid = try allocator.create(Node);
9797
mid.* = .{ .base = self.base };
98-
var to_label = try allocator.dupe(u8, edge.label[match..]);
98+
const to_label = try allocator.dupe(u8, edge.label[match..]);
9999
allocator.free(edge.label);
100100
const to_node = edge.to;
101101
edge.to = mid;
@@ -242,7 +242,7 @@ pub const Node = struct {
242242
/// Updates offset of this node in the output byte stream.
243243
fn finalize(self: *Node, offset_in_trie: u64) !FinalizeResult {
244244
var stream = std.io.countingWriter(std.io.null_writer);
245-
var writer = stream.writer();
245+
const writer = stream.writer();
246246

247247
var node_size: u64 = 0;
248248
if (self.terminal_info) |info| {
@@ -392,7 +392,7 @@ pub fn deinit(self: *Trie, allocator: Allocator) void {
392392
}
393393

394394
test "Trie node count" {
395-
var gpa = testing.allocator;
395+
const gpa = testing.allocator;
396396
var trie: Trie = .{};
397397
defer trie.deinit(gpa);
398398
try trie.init(gpa);
@@ -438,7 +438,7 @@ test "Trie node count" {
438438
}
439439

440440
test "Trie basic" {
441-
var gpa = testing.allocator;
441+
const gpa = testing.allocator;
442442
var trie: Trie = .{};
443443
defer trie.deinit(gpa);
444444
try trie.init(gpa);
@@ -496,7 +496,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {
496496
const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)});
497497
defer testing.allocator.free(given_fmt);
498498
const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
499-
var padding = try testing.allocator.alloc(u8, idx + 5);
499+
const padding = try testing.allocator.alloc(u8, idx + 5);
500500
defer testing.allocator.free(padding);
501501
@memset(padding, ' ');
502502
std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });
@@ -534,7 +534,7 @@ test "write Trie to a byte stream" {
534534
0x3, 0x0, 0x80, 0x20, 0x0, // terminal node
535535
};
536536

537-
var buffer = try gpa.alloc(u8, trie.size);
537+
const buffer = try gpa.alloc(u8, trie.size);
538538
defer gpa.free(buffer);
539539
var stream = std.io.fixedBufferStream(buffer);
540540
{
@@ -550,7 +550,7 @@ test "write Trie to a byte stream" {
550550
}
551551

552552
test "parse Trie from byte stream" {
553-
var gpa = testing.allocator;
553+
const gpa = testing.allocator;
554554

555555
const in_buffer = [_]u8{
556556
0x0, 0x1, // node root
@@ -573,15 +573,15 @@ test "parse Trie from byte stream" {
573573

574574
try trie.finalize(gpa);
575575

576-
var out_buffer = try gpa.alloc(u8, trie.size);
576+
const out_buffer = try gpa.alloc(u8, trie.size);
577577
defer gpa.free(out_buffer);
578578
var out_stream = std.io.fixedBufferStream(out_buffer);
579579
_ = try trie.write(out_stream.writer());
580580
try expectEqualHexStrings(&in_buffer, out_buffer);
581581
}
582582

583583
test "ordering bug" {
584-
var gpa = testing.allocator;
584+
const gpa = testing.allocator;
585585
var trie: Trie = .{};
586586
defer trie.deinit(gpa);
587587
try trie.init(gpa);
@@ -605,7 +605,7 @@ test "ordering bug" {
605605
0x00, 0x12, 0x03, 0x00, 0xD8, 0x0A, 0x00,
606606
};
607607

608-
var buffer = try gpa.alloc(u8, trie.size);
608+
const buffer = try gpa.alloc(u8, trie.size);
609609
defer gpa.free(buffer);
610610
var stream = std.io.fixedBufferStream(buffer);
611611
// Writing finalized trie again should yield the same result.

src/MachO/UnwindInfo.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ pub fn collect(info: *UnwindInfo, macho_file: *MachO) !void {
441441
gop.value_ptr.count += 1;
442442
}
443443

444-
var slice = common_encodings_counts.values();
444+
const slice = common_encodings_counts.values();
445445
mem.sort(CommonEncWithCount, slice, {}, CommonEncWithCount.greaterThan);
446446

447447
var i: u7 = 0;

src/MachO/eh_frame.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ pub const Iterator = struct {
600600
var stream = std.io.fixedBufferStream(it.data[it.pos..]);
601601
const reader = stream.reader();
602602

603-
var size = try reader.readInt(u32, .little);
603+
const size = try reader.readInt(u32, .little);
604604
if (size == 0xFFFFFFFF) {
605605
macho_file.base.fatal("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{});
606606
return null;

src/MachO/load_commands.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn calcMinHeaderPad(macho_file: *MachO) !u64 {
112112
log.debug("minimum requested headerpad size 0x{x}", .{padding + @sizeOf(macho.mach_header_64)});
113113

114114
if (options.headerpad_max_install_names) {
115-
var min_headerpad_size: u32 = try calcLCsSize(macho_file, true);
115+
const min_headerpad_size: u32 = try calcLCsSize(macho_file, true);
116116
log.debug("headerpad_max_install_names minimum headerpad size 0x{x}", .{
117117
min_headerpad_size + @sizeOf(macho.mach_header_64),
118118
});

src/Wasm.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ fn resolveSymbolsInArchives(wasm: *Wasm) !void {
674674
// Parse object and and resolve symbols again before we check remaining
675675
// undefined symbols.
676676
const object_file_index = @as(u16, @intCast(wasm.objects.items.len));
677-
var object = try archive.parseObject(wasm.base.allocator, offset.items[0]);
677+
const object = try archive.parseObject(wasm.base.allocator, offset.items[0]);
678678
try wasm.objects.append(wasm.base.allocator, object);
679679
try wasm.resolveSymbolsInObject(object_file_index);
680680

src/Wasm/Object.zig

+7-8
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ fn checkLegacyIndirectFunctionTable(object: *Object) !?Symbol {
260260
return error.MissingTableSymbols;
261261
}
262262

263-
var table_import: types.Import = for (object.imports) |imp| {
263+
const table_import: types.Import = for (object.imports) |imp| {
264264
if (imp.kind == .table) {
265265
break imp;
266266
}
@@ -532,7 +532,7 @@ fn Parser(comptime ReaderType: type) type {
532532
try assertEnd(reader);
533533
},
534534
.code => {
535-
var start = reader.context.bytes_left;
535+
const start = reader.context.bytes_left;
536536
var index: u32 = 0;
537537
const count = try readLeb(u32, reader);
538538
const imported_function_count = parser.object.importedCountByKind(.function);
@@ -556,7 +556,7 @@ fn Parser(comptime ReaderType: type) type {
556556
try parser.object.relocatable_data.put(gpa, .code, try relocatable_data.toOwnedSlice());
557557
},
558558
.data => {
559-
var start = reader.context.bytes_left;
559+
const start = reader.context.bytes_left;
560560
var index: u32 = 0;
561561
const count = try readLeb(u32, reader);
562562
var relocatable_data = try std.ArrayList(RelocatableData).initCapacity(gpa, count);
@@ -861,11 +861,10 @@ fn ElementType(comptime ptr: type) type {
861861
/// signedness of the given type `T`.
862862
/// Asserts `T` is an integer.
863863
fn readLeb(comptime T: type, reader: anytype) !T {
864-
if (comptime std.meta.trait.isSignedInt(T)) {
865-
return try leb.readILEB128(T, reader);
866-
} else {
867-
return try leb.readULEB128(T, reader);
868-
}
864+
return switch (@typeInfo(T).Int.signedness) {
865+
.signed => try leb.readILEB128(T, reader),
866+
.unsigned => try leb.readULEB128(T, reader),
867+
};
869868
}
870869

871870
/// Reads an enum type from the given reader.

src/Wasm/emit_wasm.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ fn emitExport(exported: std.wasm.Export, writer: anytype) !void {
554554

555555
fn emitElement(wasm: *Wasm, writer: anytype) !void {
556556
// passive, with implicit 0-index table
557-
var flags: u32 = 0;
557+
const flags: u32 = 0;
558558
try leb.writeULEB128(writer, flags);
559559
// Start the function table at index 1
560560
try emitInitExpression(.{ .i32_const = 1 }, writer);

test/elf.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub fn addElfTests(b: *Build, options: common.Options) *Step {
33

44
if (builtin.target.ofmt != .elf) return skipTestStep(elf_step);
55

6-
var opts = Options{
6+
const opts = Options{
77
.zld = options.zld,
88
.is_musl = options.is_musl,
99
.has_zig = options.has_zig,

0 commit comments

Comments
 (0)