authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-30 21:21:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-30 21:24:41-07:00
logeeadd55d15852b6bc67b459b452e83a8a8ba2933
treed7fc29c3f7bcf7a7b5dd687b2502437bed312eab
parent1bb30c5e228f4a5ebc42cc23e593ebad3bd6dbbe

fix tools/process_headers.zig regression

When upgrading to the new std lib HashMap API, the process_headers code regressed because something that was supposed to be a pointer ended up being a copy of a value. This resulted in the modification of a field not being picked up. Also switch from Sha256 to Blake3 while we're at it.

1 files changed, 6 insertions(+), 6 deletions(-)

tools/process_headers.zig+6-6
...@@ -15,7 +15,7 @@ const Arch = std.Target.Cpu.Arch;...@@ -15,7 +15,7 @@ const Arch = std.Target.Cpu.Arch;
15const Abi = std.Target.Abi;15const Abi = std.Target.Abi;
16const OsTag = std.Target.Os.Tag;16const OsTag = std.Target.Os.Tag;
17const assert = std.debug.assert;17const assert = std.debug.assert;
18const Sha256 = std.crypto.hash.sha2.Sha256;18const Blake3 = std.crypto.hash.Blake3;
1919
20const LibCTarget = struct {20const LibCTarget = struct {
21 name: []const u8,21 name: []const u8,
...@@ -314,7 +314,7 @@ pub fn main() !void {...@@ -314,7 +314,7 @@ pub fn main() !void {
314 var max_bytes_saved: usize = 0;314 var max_bytes_saved: usize = 0;
315 var total_bytes: usize = 0;315 var total_bytes: usize = 0;
316316
317 var hasher = Sha256.init(.{});317 var hasher = Blake3.init(.{});
318318
319 for (libc_targets) |libc_target| {319 for (libc_targets) |libc_target| {
320 const dest_target = DestTarget{320 const dest_target = DestTarget{
...@@ -360,7 +360,7 @@ pub fn main() !void {...@@ -360,7 +360,7 @@ pub fn main() !void {
360 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");360 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
361 total_bytes += raw_bytes.len;361 total_bytes += raw_bytes.len;
362 const hash = try allocator.alloc(u8, 32);362 const hash = try allocator.alloc(u8, 32);
363 hasher = Sha256.init(.{});363 hasher = Blake3.init(.{});
364 hasher.update(rel_path);364 hasher.update(rel_path);
365 hasher.update(trimmed);365 hasher.update(trimmed);
366 hasher.final(hash);366 hasher.final(hash);
...@@ -412,12 +412,12 @@ pub fn main() !void {...@@ -412,12 +412,12 @@ pub fn main() !void {
412 {412 {
413 var hash_it = path_kv.value.iterator();413 var hash_it = path_kv.value.iterator();
414 while (hash_it.next()) |hash_kv| {414 while (hash_it.next()) |hash_kv| {
415 const contents = &hash_to_contents.get(hash_kv.value).?;415 const contents = &hash_to_contents.getEntry(hash_kv.value).?.value;
416 try contents_list.append(contents);416 try contents_list.append(contents);
417 }417 }
418 }418 }
419 std.sort.sort(*Contents, contents_list.span(), {}, Contents.hitCountLessThan);419 std.sort.sort(*Contents, contents_list.span(), {}, Contents.hitCountLessThan);
420 var best_contents = contents_list.popOrNull().?;420 const best_contents = contents_list.popOrNull().?;
421 if (best_contents.hit_count > 1) {421 if (best_contents.hit_count > 1) {
422 // worth it to make it generic422 // worth it to make it generic
423 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key });423 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key });
...@@ -434,7 +434,7 @@ pub fn main() !void {...@@ -434,7 +434,7 @@ pub fn main() !void {
434 }434 }
435 var hash_it = path_kv.value.iterator();435 var hash_it = path_kv.value.iterator();
436 while (hash_it.next()) |hash_kv| {436 while (hash_it.next()) |hash_kv| {
437 const contents = &hash_to_contents.get(hash_kv.value).?;437 const contents = &hash_to_contents.getEntry(hash_kv.value).?.value;
438 if (contents.is_generic) continue;438 if (contents.is_generic) continue;
439439
440 const dest_target = hash_kv.key;440 const dest_target = hash_kv.key;