authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-05 01:55:36-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:26:56-04:00
log5b7881cb2a1c83b8db7c6bae2ddaba8925a65a80
tree8537a7400b0d62afcf47bb817016ad8752c6b1bb
parent48869bec3d39af0394c90cf6f7e67e656d26eb2b

MappedFile: fix the trailing resize path in realignNode


1 files changed, 28 insertions(+), 17 deletions(-)

src/link/MappedFile.zig+28-17
......@@ -1362,7 +1362,7 @@ test {
13621362
13631363 const a = try mf.addFirstChildNode(gpa, .root, .{ .fixed = true, .alignment = .@"4" });
13641364 const c = try mf.addLastChildNode(gpa, .root, .{ .fixed = true, .alignment = .@"4" });
1365 const b = try mf.addNodeAfter(gpa, a, .{ .fixed = true, .alignment = .@"4" });
1365 const b = try mf.addNodeAfter(gpa, a, .{ .fixed = true, .alignment = .@"16" });
13661366 const d = try mf.addNodeAfter(gpa, b, .{ .alignment = .@"4" });
13671367
13681368 const a_init_size = 8;
......@@ -1426,26 +1426,14 @@ test {
14261426 try testVerifyContent(&mf, d, 0xdd, d_init_size);
14271427 }
14281428
1429 // Re-align nodes
1430 {
1431 try b.realign(&mf, gpa, .@"8", true);
1432 try a.realign(&mf, gpa, .@"16", true);
1433 mf.verify();
1434
1435 try testVerifyContent(&mf, a, 0xaa, a_init_size);
1436 try testVerifyContent(&mf, b, 0xbb, b_init_size);
1437 try testVerifyContent(&mf, c, 0xcc, c_init_size);
1438 try testVerifyContent(&mf, d, 0xdd, d_init_size);
1439 }
1440
14411429 const child_init: []const struct { std.mem.Alignment, usize } = &.{
1442 .{ .@"8", 16 },
1430 .{ .@"16", 16 },
14431431 .{ .@"1", 1 },
14441432 .{ .@"1", 19 },
14451433 .{ .@"1", 3 },
1446 .{ .@"4", 30 },
1434 .{ .@"8", 30 },
14471435 .{ .@"2", 5 },
1448 .{ .@"16", 60 },
1436 .{ .@"1", 60 },
14491437 .{ .@"2", 2 },
14501438 .{ .@"16", 32 },
14511439 };
......@@ -1463,7 +1451,7 @@ test {
14631451
14641452 @memset(ni.slice(&mf)[0..opts.@"1"], @intCast(i + 1));
14651453 }
1466 // Shift differenntly-aligned nodes
1454 // Shift differently-aligned nodes by inserting a node
14671455 children[children.len - 1] = try mf.addNodeAfter(gpa, children[3], .{
14681456 .alignment = child_init[children.len - 1].@"0",
14691457 .size = child_init[children.len - 1].@"1",
......@@ -1490,6 +1478,29 @@ test {
14901478 }
14911479 }
14921480
1481 // Re-align last node into trailing free space within parent
1482 {
1483 try b.resize(&mf, gpa, b.location(&mf).resolve(&mf)[1] + 64);
1484
1485 const last = children[children.len - 2];
1486 try last.realign(&mf, gpa, .@"4", true);
1487 mf.verify();
1488
1489 for (children, child_init, 0..) |ni, opts, i|
1490 try testVerifyContent(&mf, ni, @intCast(i + 1), opts.@"1");
1491 try testVerifyContent(&mf, c, 0xcc, c_init_size);
1492 }
1493
1494 // Re-align, shifting sibling nodes
1495 {
1496 try children[1].realign(&mf, gpa, .@"8", true);
1497 mf.verify();
1498
1499 for (children, child_init, 0..) |ni, opts, i|
1500 try testVerifyContent(&mf, ni, @intCast(i + 1), opts.@"1");
1501 try testVerifyContent(&mf, c, 0xcc, c_init_size);
1502 }
1503
14931504 // Shrink and shift start of trailing node into free space
14941505 {
14951506 try mf.shrinkNode(gpa, a, 16, true);