diff options
Diffstat (limited to 'core/dump.zig')
| -rw-r--r-- | core/dump.zig | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/core/dump.zig b/core/dump.zig index 8e44d82d..2dde9c8c 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -455,7 +455,11 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: else => return err, }; views.undumped(p, others); - // What it made, as the mounts' (above). + // What it made, as the mounts' (above), but each share's ranges + // beside its primary: `undumped` gave them to the core, or freed them. + for (others) |o| for (o.panes) |sh| for (l.shared.items[at..]) |*m| { + if (sh.pv.body.sels.len > 0 and @intFromPtr(m.bytes.ptr) == @intFromPtr(sh.pv.body.sels.ptr)) m.bytes = &.{}; + }; for (l.shared.items[at..]) |m| if (m.bytes.len > 0) m.gpa.rawFree(m.bytes, m.alignment, @returnAddress()); l.shared.shrinkRetainingCapacity(at); afterLoad(p); @@ -1441,3 +1445,26 @@ test "a load refused after the core frees what a script's open held once: the ro // refuses the load there. try std.testing.expectError(error.MountConflict, load(gpa, .{ .mounts = &.{.{ .name = "peer", .dial = "/tmp/other.sock" }} }, bytes, null)); } + +test "a byte dump's views not live keep the ranges beside their primaries: loaded, the core holds them, each freed once" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + const pane = try p.setTestFile("one\ntwo\nthree\nfour\n"); + // A second cursor below, and a key typed in insert mode at both. + for ("Cix") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + const nsel = pane.body.nsel; + try std.testing.expect(nsel > 0); + // Another view live: the first's share, its ranges, parked, as a + // client's is in the session a join's dump is made of. + const k = p.openView().?; + p.toView(k); + const bytes = try byteDump(p); + defer gpa.free(bytes); + const q = try load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, bytes, null); + defer q.deinit(); + try std.testing.expectEqual(walk.digest(Pardes, p), walk.digest(Pardes, q)); + q.toView(.at(0)); + try std.testing.expectEqual(nsel, q.panes[0].?.body.nsel); +} |
