diff options
Diffstat (limited to 'core/dump.zig')
| -rw-r--r-- | core/dump.zig | 44 |
1 files changed, 44 insertions, 0 deletions
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); +} |
