summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 15:38:44 -0300
committerGabriel Schneider <[email protected]>2026-10-30 16:49:16 -0300
commitac57e8c3a05cdd8f587b6faf47e7f9d2c4357dee (patch)
tree6597aa97a1d2a682b62fc212848fdfc6a12c5b05 /src
parent470b8098a53ad3b3b0a2ef90f0d43416ea50a9b0 (diff)
downloadpardes-ac57e8c3a05cdd8f587b6faf47e7f9d2c4357dee.tar.gz
pardes-ac57e8c3a05cdd8f587b6faf47e7f9d2c4357dee.zip
views: a view drawn or read outside a step (a replica client's own while another is live) leaves the live view's slot and its panes' shares holding nothing, as unpark and drawOthers leave them
withParked parked the live view and copied it back, but left its slot (column tags' texts, a chord's argument, the presentation) and each pane's share (its selections) pointing at what the live fields own. A rollback copy walks every slot (src/rollback.zig): once the live view freed one of them and the heap gave the memory to another, the copy saved that and put its old bytes back over it, which `emptied` exists to prevent (the slot left as H5's hypothesis had it, in a path it did not name: Replica.draw and Replica.within). Test (failing before): a view drawn outside a step leaves the live view's slot holding nothing a rollback could put old bytes back through. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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);