summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 13:11:05 -0300
committerGabriel Schneider <[email protected]>2026-11-26 13:11:05 -0300
commit163c6202017f8389a67d42f1f1037633ca4dfaa1 (patch)
tree420ca766ada568bea31947b17d687b874ead2615 /core
parentc496956f395783085a249a4b1063abb577e4c3c2 (diff)
downloadpardes-163c6202017f8389a67d42f1f1037633ca4dfaa1.tar.gz
pardes-163c6202017f8389a67d42f1f1037633ca4dfaa1.zip
dump, Kind: a plain kind's pane a replica client opens with its own code (dump.plainHere) and then refuses closes what the kind's open made, as Kind.close would (FP's note: plainHere's error path did not close the kind it opened); THE CAUSE: plainHere's two refusals after Kind.reopen succeeded (no block made by the open, or the dumped record not the block's size) returned with only the slot's own errdefer (Slot.free and its destroy), so the kind's state `s.st` (a PDF's MuPDF document, its pictures) stayed open with no slot left to close it, once per refused join of that pane; THE FIX: `errdefer Kind.shut(s)` right after the reopen; `Kind.shut`, the kind's own close under a quiet Call, is the block Kind.close and Kind.fileChanged each wrote out, written once now (both call it); RUN (TEST FIRST): dump.zig "a plain kind's pane a client opens here (plainHere) and then refuses, ..." loads a plain kind that counts its opens and closes, gives plainHere a slot whose record is 5 bytes where the open makes a block of 4, and asks error.KindRefused and as many closes as opens: fails on the change before at dump.zig:1547 (expected 1 close, found 0), passes now; a user could hit it only on a far client joining a session whose PDF pane's record does not fit (a damaged or a version-skewed dump): the session's document then stayed open in the client until it exited; GATES (Debug tui): core-test 1165/1340 (175 skipped: the change before's + this test; the importer's 7 cached); load 1.5 to 1.9
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
-rw-r--r--core/Kind.zig24
-rw-r--r--core/dump.zig44
2 files changed, 56 insertions, 12 deletions
diff --git a/core/Kind.zig b/core/Kind.zig
index cf684a55..459ed6d8 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -399,12 +399,7 @@ pub fn fileChanged(p: *Pardes, id: usize, _: []const u8) bool {
const record = @import("dump.zig").slotRecord(s) catch null;
var place: [32]u8 = undefined;
s.where_text.set(where(s, &place));
- if (s.ops) |o| if (o.close) |f| {
- var cl: Call = .{ .p = null, .id = 0, .slot = s, .quiet = true };
- const prev = cl.begin("close");
- f(s.st);
- _ = cl.end(prev);
- };
+ shut(s);
s.st = null;
s.arena.deinit();
s.arena = .init(s.gpa);
@@ -434,18 +429,23 @@ pub fn close(p: *Pardes, pane: *Pane) void {
};
if (ready.items.len == 0) ready.clearAndFree(heap);
}
- if (s.ops) |ops| if (ops.close) |f| if (!kept) {
- var cl: Call = .{ .p = null, .id = 0, .slot = s, .quiet = true };
- const prev = cl.begin("close");
- f(s.st);
- _ = cl.end(prev);
- };
+ if (!kept) shut(s);
const gpa = s.gpa;
s.free();
gpa.destroy(s);
pane.addon = null;
}
+/// The kind's own close of what its open made (`s.st`), quiet.
+pub fn shut(s: *Slot) void {
+ const ops = s.ops orelse return;
+ const f = ops.close orelse return;
+ var cl: Call = .{ .p = null, .id = 0, .slot = s, .quiet = true };
+ const prev = cl.begin("close");
+ f(s.st);
+ _ = cl.end(prev);
+}
+
/// The pane's body painted over the `cols` x `rows` cells at (x, y):
/// its cells into `s`, its placements after the frame's others. A pane
/// whose kind has no code here, or a placeholder, says why in a line.
diff --git a/core/dump.zig b/core/dump.zig
index b1fad70e..9b68a559 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -1018,6 +1018,9 @@ pub fn plainHere(p: *Pardes, id: usize, old: *Kind.Slot, ops: *const Kind.Ops) !
const outside = p.outside;
defer p.outside = outside;
if (!Kind.reopen(p, id, s, old.file)) return error.KindRefused;
+ // Opened: refused from here, what the open made is closed with the
+ // slot (a PDF's document), never left with no pane to close it.
+ errdefer Kind.shut(s);
// Its block the session's, byte for byte (its record), never through
// the kind's load, which may tidy it.
const block = s.plain orelse return error.KindRefused;
@@ -1505,3 +1508,44 @@ test "a byte dump's views not live keep the ranges beside their primaries: loade
q.toView(.at(0));
try std.testing.expectEqual(nsel, q.panes[0].?.body.nsel);
}
+
+test "a plain kind's pane a client opens here (plainHere) and then refuses, the record not its block's size, closes what the kind's open made: nothing of the kind's is left open with no pane to close it" {
+ const gpa = std.testing.allocator;
+ const Counted = struct {
+ const pa = Kind.c;
+ var opened: usize = 0;
+ var closed: usize = 0;
+ fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque {
+ opened += 1;
+ return Kind.api.alloc.?(4);
+ }
+ fn close(_: ?*anyopaque) callconv(.c) void {
+ closed += 1;
+ }
+ fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {}
+ const ops = std.mem.zeroInit(Kind.Ops, .{
+ .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = Kind.abi, .name = "counted".* ++ @as([9]u8, @splat(0)), .version = 1, .exts = "", .flags = pa.PA_PLAIN }),
+ .open = open,
+ .close = close,
+ .paint = paint,
+ });
+ };
+ const p = try Pardes.init(gpa, .{ .tty_only = true });
+ defer p.deinit();
+ var words: [64]Kind.LoadedWord = undefined;
+ try std.testing.expect(p.kinds.take(p.tape, Kind.loadedOf(&Counted.ops, "", @splat(0), &words), "") == null);
+ _ = try p.setTestFile("x\n");
+ // The slot as a dump read it: its record 5 bytes, where the open makes
+ // a block of 4.
+ const old = try gpa.create(Kind.Slot);
+ old.* = .{ .gpa = gpa, .arena = .init(gpa), .version = 1, .live = true };
+ defer {
+ old.free();
+ gpa.destroy(old);
+ }
+ @memcpy(old.name[0..7], "counted");
+ old.record = try gpa.dupe(u8, "12345");
+ try std.testing.expectError(error.KindRefused, plainHere(p, p.view().active, old, &Counted.ops));
+ try std.testing.expectEqual(@as(usize, 1), Counted.opened);
+ try std.testing.expectEqual(Counted.opened, Counted.closed);
+}