summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
+}