summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rollback.zig30
-rw-r--r--src/views.zig6
2 files changed, 36 insertions, 0 deletions
diff --git a/src/rollback.zig b/src/rollback.zig
index bb3ac2dc..9c4f6c05 100644
--- a/src/rollback.zig
+++ b/src/rollback.zig
@@ -646,3 +646,33 @@ test "a rollback leaves the store and Recent as a speculation left them: they li
try std.testing.expectEqual(@as(usize, 0), e.live.count());
}
+test "a view drawn outside a step (a replica's own, another live) leaves the live view's slot holding nothing a rollback could put old bytes back through" {
+ var e: Epoch = .{};
+ defer e.deinit();
+ const gpa = e.allocator();
+ const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml", .image_allocator = gpa, .pdf_allocator = gpa, .tree_sitter_allocator = gpa, .frame_allocator = gpa });
+ defer p.deinit();
+ p.pump(.{}) catch {};
+ _ = p.openView() orelse return error.NoView;
+ const text = "the column tag of view 0, its own";
+ p.col_tags[0].own = try gpa.dupe(u8, text);
+ // View 1 read (as a replica client's frontend reads its own) while view
+ // 0 is live: 0 parked and put back.
+ const Read = struct {
+ fn read(_: void, _: *Pardes) anyerror!void {}
+ };
+ try pardes.views.within(p, 1, {}, Read.read);
+ const was = p.col_tags[0].own.?;
+ gpa.free(was);
+ p.col_tags[0].own = null;
+ const other = try gpa.alloc(u8, text.len);
+ defer gpa.free(other);
+ if (other.ptr != was.ptr) return error.SkipZigTest; // the heap handed out another
+ @memset(other, 'a');
+ var c: Copy = .{};
+ defer c.deinit();
+ try c.take(&e, p);
+ @memset(other, 'b');
+ c.restore();
+ try std.testing.expect(std.mem.allEqual(u8, other, 'b'));
+}
diff --git a/src/views.zig b/src/views.zig
index b9731089..34644a96 100644
--- a/src/views.zig
+++ b/src/views.zig
@@ -583,6 +583,10 @@ fn withParked(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pa
park(p);
defer {
copy(&fields, p, &p.parked[live].?.view);
+ // Its slot and its panes' shares, stale while it is live, keep no
+ // pointer to what they handed back, as `unpark` leaves them: a
+ // replica's rollback copy walks them (`emptied`).
+ emptied(p, live);
p.view = live;
for (p.panes) |s| if (s) |pane| {
const pv = &pane.pv[live];
@@ -593,6 +597,8 @@ fn withParked(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pa
pane.rows = pv.rows;
}
if (pane.file) |*file| file.scroll = pv.scroll;
+ pv.body.sels = &.{};
+ pv.body.nsel = 0;
};
}
try f(ctx, p, k);