From aa3ff349f840f568ea0f052c1f051cdc0dbb18c1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 09:16:28 -0300 Subject: Kind, dump, replica: a plain kind's state opened or closed in a pane that stays (a picker's preview of a PDF, Pick.showKind; a file changed under its pane; an addon reloaded) is a write outside a client's rollback copy, so a client lets the copy go with that unit and never replays it over the copy (agent T23's find, which blocked the install: the soak `replicas -- --clients 5 --rtt 30,80,207` died with `allocator leaks detected` at seed 0 rtt 80 on T1's base and on M2, MuPDF's allocations of documents a picker previewed: contexts, documents, lanes, from Kind.reopen under Pick.showKind); THE CAUSE: no path of the preview forgets its close (the next row and a source change close through Pick.preview, Esc and every roll-up through restore and putBack, ⏎ through land's roll-up, a pane's end through teardownPane, the session's through Core.deinit; a dump carries the slot and the client's join opens it, closed the same ways), but replica.confirm's `ahead` rule: a client idle with its copy taken ahead (Replica.ready) replays the session's units on it and keeps each in `since` to replay again when the copy is put back, unless the unit wrote outside the copy (Pardes.outside, counted by the emulators alone) or opened or closed a pane (its serials); a preview opens the pdf addon's state in the pane the picker lands in, which stays, and that state (the document and its lanes, MuPDF's on the kind heap, the addon's `Own` found by its block's address) is no copy's; so a rollback (another's unit before the client's own key) put the copy back, the epoch freed the block, and the replay opened the document again for a new block: the first was never closed (and its `Own`, keyed by an address the epoch hands out again, could be found for another block); THE FIX: Kind.reopen and Kind.close count a plain kind's open and close in Pardes.outside, by the registry's PA_PLAIN, on every side alike whether the kind's code runs there or not (a client without the library counts as the session does), so confirm's one question lets such a unit go with the copy; dump.plainHere, a client's own open of a plain kind's pane at its join and no step of the session's, puts the count back to the session's as dumped; Term.Outside's and Pardes.outside's docs say so; RUN (TEST FIRST): replica.zig "a picker's preview opens and closes a plain kind's state in the pane it lands in, no pane opened or closed: ..." (a plain test kind `Owned` noting each state it opens and letting it go at its close, as the pdf addon's `Own`; files `.own`): a session at notes.txt in a work tree with paper.own, a client joined in its own view running the kind, idle with its copy taken ahead while the session types `SPC f f p` (the preview through the kind in notes.txt's pane), then a key of the client's own on top and the session's own key first (a rollback), the client's key, Esc; asks the digests equal at each end and no state left noted after both cores end: fails on M2 (8959b031dc33) at the last check (expected 0, found 1), passes now; the soak with the pdf addon (`zig build replicas -Dplatform=tui -- --clients 5 --rtt 30,80,207`, every addon the build has): diverged 0, unequal 0, quiet checks 508/0 474/0 665/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak, the pdf panes the session opened 8, 6 and 5; a user could hit it as a client of a session whose picker previewed a PDF (a far client in a pair, a window joined to a terminal's session): a document leaked in the client at each rollback over such a preview, and pages drawn from another document's state where an address came back; NEW HOT PATHS: none per key or frame (a plain kind's open and close count one integer; a client lets its copy go at such a unit, as at a pane's open); GATES: core-test 1163/1337 (174 skipped: +1), its globals test (`nothing of a core is a process global`: the test kind's var in its test); no dump layout change (Pardes.outside was dumped and digested already; its values move at a plain kind's open and close, on every side alike); load 1.0 to 8.4 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Kind.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'core/Kind.zig') diff --git a/core/Kind.zig b/core/Kind.zig index 4841a55c..22a7ebe0 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -320,10 +320,16 @@ pub fn reopen(p: *Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool { if (p.kinds.byName(s.nameOf())) |k| { // Its code: its library loaded at the first pane of its kind. if (s.ops == null) s.ops = Addon.need(&p.kinds, p.tape, k, &cl.refused, p.opts.distrusted); - // Its block made afresh by this open. + // Its block made afresh by this open. And what a plain kind keeps + // beside it (a PDF's document), made in every core that runs it, is + // no rollback copy's: a write outside the copy (Pardes.outside), + // counted by the registry's word on every side alike, the kind's + // code here or not. A client that kept this step to replay over its + // copy would make that state again and never close the first. if (p.kinds.kinds[k].caps.plain) { if (s.plain) |b| if (b.len > 0) s.gpa.free(b); s.plain = &.{}; + p.outside.n +%= 1; } // Its tag's computed words (UX K'3): its words, then Del. var w: std.Io.Writer = .fixed(&s.tail.bytes); @@ -416,6 +422,11 @@ pub fn close(p: *Pardes, pane: *Pane) void { // own memory (its pictures) is left be, as the rollback brings the pane // back; the session's order closes it. const kept = s.plain != null and s.ops != null and s.ops.?.close != null and p.tape.authorityOnly("a kind's close"); + // What a plain kind keeps beside its block let go: outside the copy, as + // its open was (reopen). + if (p.kinds.byName(s.nameOf())) |k| if (p.kinds.kinds[k].caps.plain) { + p.outside.n +%= 1; + }; if (!kept) { var i: usize = 0; while (i < ready.items.len) if (ready.items[i].draw == p and ready.items[i].serial == pane.serial) ready.orderedRemove(i).drop() else { -- cgit v1.3 From 2dae98b564e677c24c5275070c413d05a85d12fc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 09:41:38 -0300 Subject: abi, Kind, pdf, fake: ABI 3.4, a kind's window holds the theme's search hit colours, `hit` and `hit_current` (Chrome's, read through p.chrome() as each pane of a kind is painted), and a PDF's search draws its hits in them, the current hit apart, where every hit was the literal amber #ffd54f (the colour line's leftover, themes DESIGN.md part F, L2e's row "PDF hits", B8's `PDF's ffd54f -> chrome.hit`: "current hit" had three colours, the body's, the rail's and the PDF's); THE ABI: pa_window gains `uint32_t hit, hit_current` at its end (24 to 32 bytes, the header's and Kind.zig's size checks), PA_ABI_MINOR 4; an addon reads them once `api->abi >= 0x30004`, so one built against 3.3 loads, opens and paints as before (the core refuses another major only, and reads nothing new of an addon), and one built against 3.4 under an older pardes is handed the amber its PDFs drew (abi/addon.zig's Window, filled by the glue); WHY THE WINDOW, NOT THE VIEW (pa_view, where fg, bg, sel and link are): a view's facts are a step's (`view` is on the tape, and a plain kind keeps them in its block: the pdf's Layout holds the whole pa_view), so two more colours there would grow the pdf's block, and an Upgrade's revival hands `load` the old block, whose size it would refuse, every open PDF a placeholder; the hits are drawn by paint alone, which writes nothing a step reads, and the window is made each paint; THE CORE: Kind.paint fills them, the theme colour's PA_RGB by Kind's one `rgb` (viewOf's, out of its function); THE PDF: paint hands its window to reconcile, and marksOf marks each hit of the page in `win.hit`, those of the current hit (`find.hit`, its quads) in `win.hit_current`, at the alpha they had; THE FAKE: paints `hits rrggbb rrggbb` on its fifth row (since 3.4), and is built once more with its head saying 3.3 (`fake_addon_old`, named fakeold); addons/fake/fake.out re-recorded (that row in each of its 11 frames, `hits 5e4923 917a53`, the addon test's theme; nothing else moved); docs/typ/reference.typ's paint says it; RUN (TEST FIRST): behaviour/addons.zig "addons: a kind's pane is painted with the theme's search hit colours, the current hit's apart (ABI 3.4), and a library whose head says 3.3 still loads, opens and paints": acme's `hits ffc790 a05200`, then neonotte84's `hits 4c301a e59d3c`, then fakeold listed `3.3 ... loaded` and its pane's `count 0`: with the header and the fake alone fails (the core's window `hits 000000 000000`), passes now; pdf.zig "a search's hits are marked in the theme's hit colours its window is painted with, the current hit in the current hit's (ABI 3.4)": a page's three quads, the second hit's two current: fails with the amber (expected 4c301a70, found ffd54f70), passes now; the ABI the addons say in /addons moves to 3.4 in five behaviour checks; a user saw every PDF hit amber in every theme and the current one no different; NEW HOT PATHS: per frame, per pane of a kind painted, two colours packed from the chrome (no allocation, no derivation: Chrome's resolved fields); none per key; GATES (the stack kysrwqpz, rqlxkzuq, this, Debug): core-test 1163/1338 (175 skipped: +1 skipped, the rerun test needs a terminal), shell-test 1379/1382 (3 skipped), pane-test 184/185, behaviour-test 288/288 (+1) and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 149 failed (3 skipped), term-test 17/17, kitty-test 45/45, addon-test 157/157 steps, 8/8 tests (fake.out, snake, pdf and their own tests); the soak with the pdf addon on this top found a second preview leak, pictures (the next change); the 40,000-seed dump fuzz crashed at join seed 8324 in draw.zig's Debug overlay (a General protection exception printing a string from a damaged dump), whose dumped session has no kind, no command pane and no window: these changes move none of its bytes (see the report); pdf-harness tui fails `KittyPdfBoundaryPageMissing` on M2 alike (8959b031dc33, run here), not this change's; no dump layout change (the window is made each paint); load 4.5 to 12.5 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- abi/addon.zig | 12 +++++++++--- abi/pardes_addon.h | 7 +++++-- addons/fake/fake.c | 13 ++++++++++++- addons/fake/fake.out | 22 +++++++++++----------- addons/pdf/pdf.zig | 41 +++++++++++++++++++++++++++++++---------- build/tests.zig | 8 +++++--- core/Kind.zig | 15 ++++++++------- docs/typ/reference.typ | 4 ++++ test/behaviour/addons.zig | 31 +++++++++++++++++++++++++++---- test/behaviour/addons_pdf.zig | 2 +- test/session.zig | 1 + 11 files changed, 114 insertions(+), 42 deletions(-) (limited to 'core/Kind.zig') diff --git a/abi/addon.zig b/abi/addon.zig index 53227fbb..dfbac270 100644 --- a/abi/addon.zig +++ b/abi/addon.zig @@ -37,9 +37,9 @@ pub const c = @import("pardes_addon"); const Allocator = std.mem.Allocator; /// The ABI this file speaks: a header of another needs it brought along. -pub const abi = 0x30003; +pub const abi = 0x30004; comptime { - if (c.PA_ABI != abi) @compileError("addon.zig speaks ABI 3.3 and the header another"); + if (c.PA_ABI != abi) @compileError("addon.zig speaks ABI 3.4 and the header another"); } /// A word the kind brings: `opens` a pane of it, else goes to the pane's @@ -160,6 +160,10 @@ pub const Window = struct { /// The view painted (View.id), and whether it shows pictures as glyph art. view: u8, glyphs: bool, + /// The theme's search hits and the current one (a pardes older than + /// ABI 3.4: the amber its PDFs drew them in). + hit: Color, + hit_current: Color, /// `text` (UTF-8) from column x of row y on, a character a cell, cut at /// the edge: column first, where the header's pa_put is row first. @@ -315,7 +319,9 @@ pub fn ops(comptime T: type) c.pa_ops { if (@hasDecl(T, "prefix")) t.*.prefix_len = write(T.prefix, s, &t.*.prefix, t.*.prefix.len); } fn paint(st: ?*anyopaque, w: [*c]const c.pa_window, out: [*c]c.pa_paint) callconv(.c) void { - T.paint(self(st) orelse return, .{ .cells = w.*.cells, .stride = w.*.stride, .cols = w.*.cols, .rows = w.*.rows, .cell_w = w.*.cell_w, .cell_h = w.*.cell_h, .focused = w.*.focused != 0, .view = w.*.view, .glyphs = w.*.glyphs != 0 }, .{ .out = out }); + const amber: Color = .rgb(0xff, 0xd5, 0x4f); + const hits = api.abi >= 0x30004; + T.paint(self(st) orelse return, .{ .cells = w.*.cells, .stride = w.*.stride, .cols = w.*.cols, .rows = w.*.rows, .cell_w = w.*.cell_w, .cell_h = w.*.cell_h, .focused = w.*.focused != 0, .view = w.*.view, .glyphs = w.*.glyphs != 0, .hit = if (hits) @fromBackingInt(w.*.hit) else amber, .hit_current = if (hits) @fromBackingInt(w.*.hit_current) else amber }, .{ .out = out }); } fn view(st: ?*anyopaque, v: [*c]const c.pa_view) callconv(.c) void { T.view(self(st) orelse return, @as(*const View, @ptrCast(v)).*); diff --git a/abi/pardes_addon.h b/abi/pardes_addon.h index d8257a0b..e467a239 100644 --- a/abi/pardes_addon.h +++ b/abi/pardes_addon.h @@ -37,7 +37,7 @@ /* Major in the high half: an addon of another major is refused. */ #define PA_ABI_MAJOR 3u -#define PA_ABI_MINOR 3u +#define PA_ABI_MINOR 4u #define PA_ABI ((PA_ABI_MAJOR << 16) | PA_ABI_MINOR) #define PA_OK 0 #define PA_RASTER_MAX (32u << 20) /* a placement's w*h*4 above this is dropped, said once */ @@ -83,6 +83,9 @@ typedef struct pa_window { * `view`: the id of the view painted (pa_view's), whose layout paint * draws; `glyphs`: it shows pictures as glyph art. */ uint8_t focused, view, glyphs, pad; + /* Since 3.4 (check api->abi): the theme's search hits, and the current + * one, as the body draws them (PA_RGB). */ + uint32_t hit, hit_current; } pa_window; typedef struct pa_rect { uint32_t x, y, w, h; } pa_rect; /* pixels */ @@ -390,7 +393,7 @@ typedef struct pa_ops { * copy of this header that disagrees does not compile. */ #if UINTPTR_MAX == 0xffffffffffffffffu _Static_assert(sizeof(pa_cell) == 20, "pa_cell"); -_Static_assert(sizeof(pa_window) == 24, "pa_window"); +_Static_assert(sizeof(pa_window) == 32, "pa_window"); _Static_assert(sizeof(pa_rect) == 16 && sizeof(pa_cells) == 8, "pa_rect"); _Static_assert(sizeof(pa_placement) == 80, "pa_placement"); _Static_assert(sizeof(pa_paint) == 48 && sizeof(pa_view) == 32 && sizeof(pa_tick) == 128, "pa_paint"); diff --git a/addons/fake/fake.c b/addons/fake/fake.c index b3f6b288..b5423317 100644 --- a/addons/fake/fake.c +++ b/addons/fake/fake.c @@ -6,7 +6,8 @@ * * A pane of it counts: keys and clicks and ticks and words each add to a * count it paints, dumps and answers `where` with; `:N` sets it. It paints - * which view it is painted for and that view's size as `view` told it. */ + * which view it is painted for and that view's size as `view` told it, + * and the theme's hit colours its window has (since 3.4). */ #include "pardes_addon.h" /* The loader's tests build it wrong on purpose: another ABI, no export, @@ -60,6 +61,10 @@ static void view(void *st, const pa_view *v) { f->cols[v->id - 1] = v->cols, f->rows[v->id - 1] = v->rows; } +static void hex(char *out, uint32_t rgb) { + for (int i = 0; i < 6; i++) out[i] = "0123456789abcdef"[rgb >> (20 - 4 * i) & 0xf]; +} + static void num(char *out, unsigned n) { char t[12]; int k = 0; @@ -84,6 +89,12 @@ static void paint(void *st, const pa_window *w, pa_paint *out) { if (w->glyphs) memcpy(v + strlen(v), " glyphs", 8); pa_put(w, 3, 0, v, PA_DEFAULT, PA_DEFAULT, 0); } + if (api->abi >= 0x30004u) { + char h[] = "hits rrggbb rrggbb"; + hex(h + 5, w->hit); + hex(h + 12, w->hit_current); + pa_put(w, 4, 0, h, PA_DEFAULT, PA_DEFAULT, 0); + } if (f && out->cap > 0 && w->rows > 2) { pa_placement *pl = &out->placements[out->n++]; *pl = (pa_placement){.rgba = f->pixels, .w = 2, .h = 2, .src = {0, 0, 2, 2}, .dst = {0, 2, 2, 1}, .key = f->count}; diff --git a/addons/fake/fake.out b/addons/fake/fake.out index 8f92d24e..ef4c200b 100644 --- a/addons/fake/fake.out +++ b/addons/fake/fake.out @@ -6,7 +6,7 @@ tag fake petscii:on palette:commodore ascii:on | | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 4b3cd99b86ea3486 @@ -16,7 +16,7 @@ tag fake petscii:on palette:commodore ascii:on |kb | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key fdcaab9076ad067e @@ -26,7 +26,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 71e39225f0cec2a5 @@ -36,7 +36,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 54740e23065232cf @@ -46,7 +46,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -56,7 +56,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -66,7 +66,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 2 58x7 -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -77,7 +77,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 2 68x13 -| +|hits 5e4923 917a53 | | | @@ -93,7 +93,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -103,7 +103,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 @@ -113,7 +113,7 @@ tag fake petscii:on palette:commodore ascii:on |m3 | |view 1 58x7 glyphs -| +|hits 5e4923 917a53 | | placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig index 7ee3400a..a401c979 100644 --- a/addons/pdf/pdf.zig +++ b/addons/pdf/pdf.zig @@ -405,7 +405,7 @@ pub const Pdf = extern struct { // white tinted is the theme's paper const paper: u32 = if (st.tint == .disabled) 0xffffff else if (pixels(st, st.active)) |a| @backingInt(a.v.bg) else 0xffffff; o.blank = .{ @truncate(paper >> 16), @truncate(paper >> 8), @truncate(paper), 255 }; - reconcile(st, o, l, sp, win.view); + reconcile(st, o, l, sp, win); const vh = @min(@as(u32, win.rows) * win.cell_h, l.vh); const first, const count = visible(st, l, sp); for (first..first + count) |p| { @@ -1377,9 +1377,10 @@ fn rasterOf(st: *const Pdf, o: *Own, p: usize, q: Request) [2]u32 { // ---- highlights ---- -/// Page `p`'s highlights in view `l`, as painted: the pointer's, the -/// search's, the selection's. -fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark) []Mark { +/// Page `p`'s highlights in view `l`, as painted in `win`: the pointer's, +/// the search's (in the theme's hit colours, the current hit apart), the +/// selection's. +fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark, win: addon.Window) []Mark { const f = struct { fn mark(q: Quad, rgb: u32, a: u8, kind: c_int) Mark { return .{ .quad = q, .rgba = .{ @truncate(rgb >> 16), @truncate(rgb >> 8), @truncate(rgb), a }, .kind = kind }; @@ -1393,7 +1394,7 @@ fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark) []Mar if (st.find.hits_page == p) { const hits = hitsOf(st, o); for (hits[0..@min(hits.len, out.len - n)]) |h| { - out[n] = f.mark(h.quad, 0xffd54f, 0x70, m.PARDES_PDF_HIGHLIGHT_SEARCH); + out[n] = f.mark(h.quad, @backingInt(if (h.hit == st.find.hit) win.hit_current else win.hit), 0x70, m.PARDES_PDF_HIGHLIGHT_SEARCH); n += 1; } } @@ -1528,10 +1529,11 @@ fn repaint(o: *Own, s: *Slot, now: []const Mark) bool { return keepMarks(&s.shown, now); } -/// What view `id`'s window shows (and the page past it) made so, as it is -/// painted: pages gone dropped, highlights moved repainted, the rest asked -/// of the lanes as draws. -fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, id: u8) void { +/// What view `win.view`'s window shows (and the page past it) made so, as +/// it is painted: pages gone dropped, highlights moved repainted, the rest +/// asked of the lanes as draws. +fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, win: addon.Window) void { + const id = win.view; const first, var n = visible(st, l, sp); if (n > 0 and first + n < st.pages and !st.go.fling) n += 1; // the page ahead, at rest for (&o.s) |*s| if (s.view == id and (s.page < first or s.page >= first + n)) { @@ -1556,7 +1558,7 @@ fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, id: u8 const same = s.rgba.len > 0 and std.meta.eql(s.is.req, q); const wh = if (same) [2]u32{ s.is.w, s.is.h } else rasterOf(st, o, p, q); const y, const bh = bandOf(st, l, sp, p, wh[0], wh[1]); - const marks = marksOf(st, o, l, p, &now.at); + const marks = marksOf(st, o, l, p, &now.at, win); if (same and s.is.tint == st.tint and s.is.ink == @backingInt(l.v.fg) and s.is.paper == @backingInt(l.v.bg) and s.is.band_y <= y and s.is.band_y + s.is.band_h >= y + bh) { if (now.eq(s.shown, marks) or repaint(o, s, marks)) continue; } @@ -1860,3 +1862,22 @@ test "every pointer the bridge's structs hand back is read through addon.cSlice: }; } } + +test "a search's hits are marked in the theme's hit colours its window is painted with, the current hit in the current hit's (ABI 3.4)" { + var st: Pdf = .{}; + st.find.query[0] = 'x'; + st.find.len = 1; + st.find.hits_page = 0; + st.find.hit = 1; + // The page's hits as its search found them: the second, in two quads, current. + const q = std.mem.zeroes(Quad); + var quads = [_]m.pardes_pdf_search_quad{ .{ .quad = q, .hit = 0 }, .{ .quad = q, .hit = 1 }, .{ .quad = q, .hit = 1 } }; + var o: Own = .{ .hits = &quads, .hits_of = .{ .page = 0, .query = st.find.query } }; + var cells: [1]c.pa_cell = undefined; + const win: addon.Window = .{ .cells = &cells, .stride = 1, .cols = 1, .rows = 1, .cell_w = 8, .cell_h = 16, .focused = false, .view = 1, .glyphs = false, .hit = .rgb(0x4c, 0x30, 0x1a), .hit_current = .rgb(0xe5, 0x9d, 0x3c) }; + var out: [8]Mark = undefined; + const marks = marksOf(&st, &o, &st.views[0], 0, &out, win); + try std.testing.expectEqual(@as(usize, 3), marks.len); + try std.testing.expectEqual([4]u8{ 0x4c, 0x30, 0x1a, 0x70 }, marks[0].rgba); + for (marks[1..]) |mk| try std.testing.expectEqual([4]u8{ 0xe5, 0x9d, 0x3c, 0x70 }, mk.rgba); +} diff --git a/build/tests.zig b/build/tests.zig index c35857f7..05bdc2b6 100644 --- a/build/tests.zig +++ b/build/tests.zig @@ -111,18 +111,20 @@ pub fn add(b: *std.Build, c: struct { const session_options = b.addOptions(); session_options.addOptionPath("lspmock", c.lspmock.getEmittedBin()); var fake_addon_lib: ?*std.Build.Step.Compile = null; - // The fake addon (addons/fake/fake.c) and three copies of it built - // wrong, which the loader must refuse (test/behaviour/addons.zig). + // The fake addon (addons/fake/fake.c), copies of it built wrong, which + // the loader must refuse, and one whose head says ABI 3.3, which it + // takes (test/behaviour/addons.zig). for ([_]struct { []const u8, []const u8 }{ .{ "fake_addon", "-DFAKE_PLAIN" }, .{ "fake_addon_abi", "-DFAKE_ABI=0x20002" }, .{ "fake_addon_no_export", "-DFAKE_NO_EXPORT" }, .{ "fake_addon_core_word", "-DFAKE_WORD=\"Save\"" }, .{ "fake_addon_no_dump", "-DFAKE_NO_DUMP" }, + .{ "fake_addon_old", "-DFAKE_ABI=0x30003" }, }) |variant| { const lib = b.addLibrary(.{ .name = variant[0], .linkage = .dynamic, .root_module = b.createModule(.{ .target = c.target, .optimize = c.optimize, .link_libc = true }) }); lib.root_module.addIncludePath(b.path("abi")); - const name_flag = if (std.mem.eql(u8, variant[0], "fake_addon_abi")) "-DFAKE_NAME=\"fakeabi\"" else if (std.mem.eql(u8, variant[0], "fake_addon_core_word")) "-DFAKE_NAME=\"fakeword\"" else "-DFAKE_PLAIN"; + const name_flag = if (std.mem.eql(u8, variant[0], "fake_addon_abi")) "-DFAKE_NAME=\"fakeabi\"" else if (std.mem.eql(u8, variant[0], "fake_addon_core_word")) "-DFAKE_NAME=\"fakeword\"" else if (std.mem.eql(u8, variant[0], "fake_addon_old")) "-DFAKE_NAME=\"fakeold\"" else "-DFAKE_PLAIN"; // The header is the whole contract: it compiles clean under every warning. lib.root_module.addCSourceFile(.{ .file = b.path("addons/fake/fake.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror", "-Wno-override-init", variant[1], name_flag } }); session_options.addOptionPath(variant[0], lib.getEmittedBin()); diff --git a/core/Kind.zig b/core/Kind.zig index 22a7ebe0..9316c502 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -39,7 +39,7 @@ pub const abi: u32 = c.PA_ABI; // records the core reads are the ones addons are built to. comptime { if (@sizeOf(usize) == 8) for (.{ - .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, + .{ c.pa_cell, 20 }, .{ c.pa_window, 32 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, .{ c.pa_placement, 80 }, .{ c.pa_paint, 48 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 }, .{ c.pa_api, 128 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 }, .{ c.pa_ops, 208 }, .{ c.pa_view, 32 }, .{ c.pa_tick, 128 }, @@ -529,7 +529,8 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator, var gpu: GpuPaint = .{ .arena = arena, .frame = frame }; var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len, .gpu = GpuPaint.emit, .gpu_ctx = &gpu }); const px = p.view().cell_pixels; - const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images) }); + const chrome = p.chrome(); + const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images), .hit = rgb(chrome.hit), .hit_current = rgb(chrome.hit_current) }); var cl: Call = .{ .p = null, .id = id, .slot = slot, .quiet = true, .core = p }; const prev = cl.begin("paint"); const before = if (checked) usedHash(slot) else {}; @@ -803,11 +804,6 @@ pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view { // derived, so a client joined from a dump has none. const notices = pardes.Messages.bands(p, pane, tag_rows, r).span(); const th = p.theme(); - const rgb = struct { - fn f(x: [3]u8) u32 { - return @as(u32, x[0]) << 16 | @as(u32, x[1]) << 8 | x[2]; - } - }.f; const policy = rasterPolicy(v.frontend.windowed); return .{ .cols = r.w -| pardes.config.GUTTER, @@ -827,6 +823,11 @@ pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view { }; } +/// A theme's colour as the header's PA_RGB. +fn rgb(x: [3]u8) u32 { + return @as(u32, x[0]) << 16 | @as(u32, x[1]) << 8 | x[2]; +} + /// Whether pane `id` has the keyboard in some view (its window focused). fn focusedAnywhere(p: *const Pardes, id: usize) bool { for (&p.views) |*v| if (v.*) |*vw| if (vw.active == id and vw.window_focused) return true; diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 126330fa..2b0f31c0 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -1171,6 +1171,10 @@ of it is laid out by `view` and drawn by `paint`. and a click say the view they came from. `paint` is called once a frame in each view, `win->view` the one, and changes nothing (a Debug build checks the kind's memory across it); a picture over 32 MiB is dropped. + Since ABI 3.4 the window holds the theme's search hit colours, + `win->hit` and the current hit's `win->hit_current` (`PA_RGB`), which an + addon reads once `api->abi >= 0x30004`: a PDF's search draws its hits + in them, as the body draws a file's. - Every call returns within 2 ms; what takes longer goes on a job. A Debug pardes says a call over 16 ms once (`pdf: search took 118 ms, over 16 ms`) and `--addon-test` fails on it. diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index 0b0555c2..88c477ea 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -37,7 +37,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com defer unload(&s, "fake"); // ` `. const listed = try s.read("/addons"); - try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 3.3 0 /")); + try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 3.4 0 /")); var fields = std.mem.tokenizeScalar(u8, listed[0..std.mem.indexOfScalar(u8, listed, '\n').?], ' '); for (0..5) |_| _ = fields.next(); try std.testing.expectEqual(@as(usize, 64), fields.next().?.len); @@ -51,7 +51,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com // A pane of it open, it stays; closed, it goes. try s.write("/ctl", "Fake\n"); const pane = try paneOf(&s, "fake"); - try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 3.3 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 3.4 1 /")); try std.testing.expect(try s.refused("/ctl", "Addon unload fake\n") != 0); try std.testing.expect(has(s.said, "1 fake pane is open")); try s.write(s.at("/pane/{d}/ctl", .{pane}), "Del\n"); @@ -68,7 +68,7 @@ test "addons: a library of another ABI, one with no pardes_addon, and one whose try std.testing.expect(std.mem.startsWith(u8, listed, "fakeabi 1 2.2 0 /")); try std.testing.expect(has(listed, " refused: wants abi 2, this pardes speaks 3\n")); try std.testing.expect(has(listed, " refused: it has no pardes_addon\n")); - try std.testing.expect(has(listed, "\nfakeword 1 3.3 0 /")); + try std.testing.expect(has(listed, "\nfakeword 1 3.4 0 /")); try std.testing.expect(has(listed, " refused: word Save is the core's\n")); // A file that is no library at all: listed with what the loader said. var tmp = std.testing.tmpDir(.{}); @@ -120,7 +120,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the defer s.deinit(); try load(&s, Session.image_addon); const listed = try s.read("/addons"); - try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 3.3 0 /") and has(listed, " loaded\n")); + try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 3.4 0 /") and has(listed, " loaded\n")); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var buf: [4096]u8 = undefined; @@ -530,3 +530,26 @@ test "addons: Enter on a picture in a picker opens its kind's pane, never its by try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{image})) and has(screen, "\"src\":[0,0,2,1]")); try std.testing.expect(!has(try s.screen(), "1 P6")); } + +test "addons: a kind's pane is painted with the theme's search hit colours, the current hit's apart (ABI 3.4), and a library whose head says 3.3 still loads, opens and paints" { + { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try load(&s, fake.ok); + defer unload(&s, "fake"); + try s.write("/ctl", "Theme acme\n"); + try s.write("/ctl", "Fake\n"); + // acme's: its hit ground, and its amber held for its page's ink. + try std.testing.expect(has(try s.screen(), "hits ffc790 a05200")); + try s.write("/ctl", "Theme neonotte84\n"); + try std.testing.expect(has(try s.screen(), "hits 4c301a e59d3c")); + } + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try load(&s, fake.old); + defer unload(&s, "fakeold"); + const listed = try s.read("/addons"); + try std.testing.expect(std.mem.startsWith(u8, listed, "fakeold 1 3.3 0 /") and has(listed, " loaded\n")); + try s.write("/ctl", "Fake\n"); + try std.testing.expect(has(try s.screen(), "count 0")); +} diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig index 7df5d5ee..c59b4a93 100644 --- a/test/behaviour/addons_pdf.zig +++ b/test/behaviour/addons_pdf.zig @@ -38,7 +38,7 @@ test "addons: a PDF is the pdf addon's pane, its pages pictures, its page in its s.graphics(); const n = try s.lookFile("docs/design.pdf"); try std.testing.expect(has(try s.read("/index"), " pdf ")); - try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 3.3 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 3.4 1 /")); const pages = (try s.pdfPage(n))[1]; try std.testing.expectEqual(@as(u32, 16), pages); // Its first page, a picture over its body. diff --git a/test/session.zig b/test/session.zig index 9285c13b..91cca3e5 100644 --- a/test/session.zig +++ b/test/session.zig @@ -23,6 +23,7 @@ pub const Session = struct { pub const no_export = o.fake_addon_no_export; pub const core_word = o.fake_addon_core_word; pub const no_dump = o.fake_addon_no_dump; + pub const old = o.fake_addon_old; }; core: *anyopaque, -- cgit v1.3 From f11b123a8f4c38b6582c03d2acf84143ed1e7fd3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 10:35:42 -0300 Subject: Kind: a picture drawn for a pane that shows no kind's slot when it lands is dropped there, never kept in `ready` for a paint that never comes (the soak with the pdf addon on this stack's top, after kysrwqpz: `allocator leaks detected` at seed 1 rtt 30, two draws of the pdf addon's, their inputs (api.draw's copy), their KindJobs and their pixels (KindJob.run's arena), and `ready`'s own buffer, all from Kind.paint's draws landed by Kind.landDraw); THE CAUSE: a draw is a frame's, run on a worker and landed on the loop later (landDraw), which kept it for the pane's next paint unless the pane had closed or its serial moved; a picker's preview (Pick.showKind) is a kind's slot over a pane that stays: Esc, the next row or ⏎ closes the slot (Kind.close drops the draws then in `ready`), and a draw still on its worker lands after it on a pane that is its own text again; no paint of a kind ever takes it (deliver runs for a kind's pane alone) and the pane's own close passes it by (Kind.close returns at once for a pane with no slot), so it stayed until the process ended, a page's pixels a draw (megabytes) in a long session for every preview closed under a draw; THE FIX: landDraw drops a draw whose pane has no kind's slot (`pane.addon == null`), as one whose pane closed; a draw of an earlier slot landing on a later one is dropped at its paint as before (Slot.drawn_from, gen, ops); RUN (TEST FIRST): Kind.zig "a picture drawn for a pane that shows no kind's slot when it lands (a picker's preview closed meanwhile) is dropped, never kept for a paint that never comes": a draw landed on a text pane: kept in `ready` on the base (expected 0, found 1), dropped now; the soak with the pdf addon: diverged 0, unequal 0, quiet checks 566/0 481/0 674/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak, the pdf panes the session opened 6, 7 and 7 (the same stack without this change: the leak at seed 1 rtt 30); a user hit it with every picker over PDFs moved or closed while a page drew (the session's own frontend draws on workers too): memory held to the session's end; NEW HOT PATHS: none (one field read as a draw lands); GATES: core-test 1164/1339 (175 skipped: +1); load 2.9 to 9.8 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Kind.zig | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'core/Kind.zig') diff --git a/core/Kind.zig b/core/Kind.zig index 9316c502..c8420c8a 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -1310,8 +1310,11 @@ var drawn: u32 = 0; /// its own. pub fn landDraw(p: *Pardes, j: *host_io.KindJob) void { if (j.draw != p) return j.drop(); - // Its pane closed meanwhile: no paint of it would ever take it. - if (if (p.panes[j.pane]) |pane| pane.serial != j.serial else true) return j.drop(); + // Its pane closed meanwhile, or showing no kind now (a picker's preview + // closed, the pane its own text again): no paint of it would ever take + // it, nor would the pane's close (Kind.close: a slot's draws). + const pane = p.panes[j.pane] orelse return j.drop(); + if (pane.serial != j.serial or pane.addon == null) return j.drop(); ready.append(heap, j) catch return j.drop(); p.needs_frame = true; } @@ -1427,3 +1430,18 @@ const GpuPaint = struct { return 0; } }; + +test "a picture drawn for a pane that shows no kind's slot when it lands (a picker's preview closed meanwhile) is dropped, never kept for a paint that never comes" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + _ = try p.setTestFile("the notes\n"); + const id = p.view().active; + try std.testing.expect(p.panes[id].?.addon == null); + // A draw of the preview's, back from its worker after Esc gave the pane + // its own text again. + const j = try heap.create(host_io.KindJob); + j.* = .{ .gpa = heap, .pane = @intCast(id), .serial = p.panes[id].?.serial, .token = c.PA_DRAWN | 1, .gen = 0, .ops = &test_kind.ops, .in = try heap.dupe(u8, "draw"), .arena = .init(heap), .draw = p }; + Addon.holdJob(j.ops, true); + landDraw(p, j); + try std.testing.expectEqual(@as(usize, 0), ready.items.len); +} -- cgit v1.3