From 7dbcaa13cc3bebd5470ce1ac3f5e112357564063 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 09:37:41 -0300 Subject: upgrade: the test that an Upgrade's outcome is said in every view: runtime/upgrade.zig:449 (`load`'s end) set "Upgrade: now ..." or "... it goes on as ..." at `p.view().active`, the live view at the dump, the one whose input came last before the Upgrade's step, not the one that asked (the pair round's `--with-pair --upgrade` ReleaseSafe to Debug 1 of 3: the message on pane 5, a pane of client f's view, which the session's /screen does not show); the unit test (two views, the second's keyboard on a New pane of its own and its input last, dumped and loaded as an upgrade loads it: each view's pane at its keyboard must say "Upgrade: now pardes ") fails at upgrade.zig:493 (logs/t7-upgrade-unfixed.log); and test/daemon.py's refused-upgrade row (two replica clients, the Upgrade written over 9P to the shell's pane) now waits for each client's own screen to say "Upgrade: the new build" Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/upgrade.zig | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'runtime') diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index f59117ee..2fa910aa 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -463,6 +463,40 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op } } +test "an upgrade's outcome is said in every view, at the pane its keyboard is on, whichever view's input came last" { + const gpa = std.testing.allocator; + const p = try pardes.Pardes.init(gpa, .{ .tty_only = true }); + defer p.deinit(); + _ = try p.setTestFile("before the upgrade\n"); + const asked = p.view().active; + // A second client's view, its keyboard on a pane of its own, the input + // that came last its own (as a client's keys before an Upgrade over 9P). + const k = p.openView() orelse return error.NoView; + p.toView(k); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "New")); + try std.testing.expect(p.view().active != asked); + const bytes = try pardes.dump.byteDump(p); + defer gpa.free(bytes); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pardes-upgrade-1.dump", .data = bytes }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + var text_buf: [4300]u8 = undefined; + var rec = try Record.decode(try std.fmt.bufPrint(&text_buf, "link -1\nstub -1\nold -1\nwindow 0\nexe /x/pardes\ndump {s}/pardes-upgrade-1.dump\n", .{dir})); + const q = try load(gpa, gpa, .{ .tty_only = true }, &rec); + defer q.deinit(); + try std.testing.expect(!rec.fresh); + var seen: usize = 0; + for (q.views) |v| if (v) |view| { + const pane = q.panes[view.active].?; + try std.testing.expect(std.mem.startsWith(u8, pane.msg[0..pane.msg_len], "Upgrade: now pardes ")); + seen += 1; + }; + try std.testing.expectEqual(@as(usize, 2), seen); + try std.testing.expect(q.views[0].?.active != q.views[k.index()].?.active); +} + test "an upgrade's record reads back as it was written, and refuses one cut short" { var rec: Record = .{ .link = 5, .stub = 7, .old = 9, .window = true, .exe = "/a b/pardes", .dump = "/home/u/.local/share/pardes/pardes.xitdb", .label = "upgrade-1", .state = .kept }; rec.addPty(3, 1234, 11); -- cgit v1.3 From e22d77e95959a5babdc3eb693d0da317c1fae1b5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 09:51:44 -0300 Subject: upgrade: an Upgrade's outcome is the session's news: `tellEveryView` says it at each open view's keyboard pane, a pane two views share once (the coordinator's ruling: every view that has a frontend reads it on its own screen), where `load` said it at the live view alone, the one whose input came last before the Upgrade's step; the test of the change before passes (Debug, 8/8 of the filter) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/upgrade.zig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 2fa910aa..e7b6553a 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -436,7 +436,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op // keep its blocks for as long as this session runs. if (rec.old >= 0) _ = libc.close(rec.old); rec.old = -1; - p.setMessage(.at(p.view().active), if (rec.refused.len > 0) + tellEveryView(p, if (rec.refused.len > 0) std.fmt.bufPrint(&buf, "Upgrade: the new build could not load this session ({s}); it goes on as {s}", .{ rec.refused[0..@min(rec.refused.len, 200)], version_line }) catch "Upgrade: the new build could not load this session; it goes on as before" else "Upgrade: now " ++ version_line); @@ -463,6 +463,18 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op } } +/// An Upgrade is the session's news, not the asking view's: said in every +/// view at the pane its keyboard is on (each client reads it on its own +/// screen), a pane two views are on once; the live view is only the one +/// whose input came last before the dump. +fn tellEveryView(p: *pardes.Pardes, text: []const u8) void { + var told: [pardes.MAX_PANES]bool = @splat(false); + for (p.views) |v| if (v) |view| if (!told[view.active]) { + told[view.active] = true; + p.setMessage(.at(view.active), text); + }; +} + test "an upgrade's outcome is said in every view, at the pane its keyboard is on, whichever view's input came last" { const gpa = std.testing.allocator; const p = try pardes.Pardes.init(gpa, .{ .tty_only = true }); -- cgit v1.3 From da4256d4bf8938d38daa1349e9b51f403bf7a937 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 16:34:45 -0300 Subject: messages: what a view kept for its client's return shows at its keyboard's pane waits for that client (the coordinator's rule for an Upgrade's outcome: kept for each view until its client is back and drawn, until its kept time for a view whose client never comes, as now for the session's own frontend): pair-10's rule "a message waits for someone to see it", which a session-wide `unattended = false` keeps for a pair's one client (dev/tui/tui.zig `Own.start`, `rec.state == .pair`), made per view for every client: `Messages.awaited(p, pane)`: a pane that the keyboard of a view kept for its client (views.away: an Upgrade's clients, a divergence's) is on, within the view's kept time (views.away_kept_ns); neither another view's key or click (`dismissMessage`) nor the unattended clock (`expireUnattended`) takes its message; the client back for its view (`rejoinView`) gets it in its join's dump; pair-10's line stays: deleted, the `--with-pair --upgrade` rows failed 3 of 3 at "brings the rest back" (a pair's session no build could load starts afresh with no view kept, its message on the unattended clock at once): that case has no view to hold it; what failed the merged gate (pardes-merge63, its row "each client's own screen saying the Upgrade's outcome" 3 of 3) was NOT a race but the test's first needle, `Upgrade: the new build`, which a message longer than its pane never shows (it shows its end: round 1's five kept runs, both clients, 0 head and 1 end each): pardes-merge63 stands on `ulztktwm` without `mntzqroy` (its needle `it goes on as`); on this tree (with `mntzqroy`) the row passed before this change 3 of 3 each way (dbg->rel, rel->dbg, a message trace in every process: every client back within 3 ms of the outcome, nothing between); the race this closes is a user's: a key in the session's own terminal, or a detached session's clock, before a client is back; TEST FIRST: runtime/upgrade.zig "an upgrade's outcome waits in each view kept for its client until that client is back for it: no other view's key and no clock take it" (two client views kept as an Upgrade keeps them, the dump loaded by `load`, MessageLinger 0: a key in the own view takes its pane's outcome and not theirs; unattended, a tick takes none; a client back has it and the next key takes it; the other's goes past its kept time): fails on the base at the first kept view (upgrade.zig:534), passes with it; the two upgrade tests share `upgradedForTest` (the dump and `load`) and `saysOutcome` Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Messages.zig | 21 ++++++++++++++++ runtime/upgrade.zig | 72 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 84 insertions(+), 9 deletions(-) (limited to 'runtime') diff --git a/core/Messages.zig b/core/Messages.zig index 46dab136..18b10ff8 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -192,6 +192,7 @@ pub fn expireUnattended(p: *Pardes) void { for (p.panes) |slot| { const pane = slot orelse continue; if (pane.msg_len == 0 and pane.msg_older_len == 0) continue; + if (awaited(p, pane)) continue; if (now - pane.msg_said_ms < p.settings.message_linger_ms) continue; pane.msg_len = 0; pane.msg_life = .{}; @@ -200,10 +201,30 @@ pub fn expireUnattended(p: *Pardes) void { } } +/// A message waits for someone to see it, and a view kept for its client's +/// return (views.away: an Upgrade's clients, a divergence's) is someone +/// on the way: what its keyboard's pane says (an Upgrade's outcome, +/// upgrade.zig `tellEveryView`) is that client's until it is back for its +/// view (Pardes.rejoinView: its join's dump has it) or the view's kept +/// time is up; no other view's input and no unattended clock take it. A +/// pair's one client is such a client; the session's own frontend is +/// none (its view is never away). A session no build could load starts +/// afresh with no view kept: a pair's is held attended for its client +/// instead (tui.zig `Own.start`). +fn awaited(p: *const Pardes, pane: *const Pane) bool { + if (p.views_away == 0) return false; + for (p.views, 0..) |slot, k| if (slot) |v| { + if (pardes.views.isAway(p, @intCast(k)) and p.panes[v.active] == pane and + p.clock.now_ns -| v.away_ns < pardes.views.away_kept_ns) return true; + }; + return false; +} + /// The key or click that used to clear the message row now starts each /// line's exit: it stays `message_linger_ms`, then goes. A line already /// on its way out keeps its own timing. pub fn dismissMessage(p: *Pardes, pane: *Pane) void { + if (awaited(p, pane)) return; if (pane.msg_len > 0 and dismissLine(p, &pane.msg_life)) { pane.msg_len = 0; pane.msg_life = .{}; diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 6cbaa750..67d16f84 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -497,6 +497,67 @@ test "an upgrade's outcome is said in every view, at the pane its keyboard is on p.toView(k); try std.testing.expect(p.executeBuiltinLine(p.view().active, "New")); try std.testing.expect(p.view().active != asked); + const q = try upgradedForTest(gpa, p); + defer q.deinit(); + var seen: usize = 0; + for (q.views, 0..) |v, i| if (v != null) { + try std.testing.expect(saysOutcome(q, i)); + seen += 1; + }; + try std.testing.expectEqual(@as(usize, 2), seen); + try std.testing.expect(q.views[0].?.active != q.views[k.index()].?.active); +} + +test "an upgrade's outcome waits in each view kept for its client until that client is back for it: no other view's key and no clock take it" { + const gpa = std.testing.allocator; + const p = try pardes.Pardes.init(gpa, .{ .tty_only = true }); + defer p.deinit(); + _ = try p.setTestFile("before the upgrade\n"); + // Two clients' views, each its keyboard on a pane of its own, kept for + // their clients as an Upgrade keeps them (Peers.refuseAll: away). + var kept: [2]pardes.Pardes.View.Id = undefined; + for (&kept) |*k| { + k.* = p.openView() orelse return error.NoView; + p.toView(k.*); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "New")); + } + p.toView(.at(0)); + for (kept) |k| p.awayView(k); + const q = try upgradedForTest(gpa, p); + defer q.deinit(); + // As the daemon's tests run (MessageLinger 0): a dismissal is at once. + q.settings.message_linger_ms = 0; + const key: pardes.Event = .{ .key = .{ .cp = 'j', .text = "j" } }; + // A key in the session's own view: its outcome goes, not theirs. + q.update(key); + try std.testing.expect(!saysOutcome(q, q.live)); + for (kept) |k| try std.testing.expect(saysOutcome(q, k.index())); + // Nobody attached: the clock takes nothing a kept view waits for. + q.unattended = true; + q.update(.tick); + for (kept) |k| try std.testing.expect(saysOutcome(q, k.index())); + q.unattended = false; + // A client back for its view has it (its join's dump); the next key, + // anyone's, takes it. + try std.testing.expect(q.rejoinView(kept[0])); + try std.testing.expect(saysOutcome(q, kept[0].index())); + q.update(key); + try std.testing.expect(!saysOutcome(q, kept[0].index())); + try std.testing.expect(saysOutcome(q, kept[1].index())); + // One never back: once its view's kept time is up, as anyone's. + q.advance(q.views[kept[1].index()].?.away_ns + pardes.views.away_kept_ns); + q.update(key); + try std.testing.expect(!saysOutcome(q, kept[1].index())); +} + +/// Whether view `k`'s keyboard pane says the Upgrade's outcome. +fn saysOutcome(q: *const pardes.Pardes, k: usize) bool { + const pane = q.panes[q.views[k].?.active].?; + return std.mem.startsWith(u8, pane.msg[0..pane.msg_len], "Upgrade: now pardes "); +} + +/// `p` dumped and loaded as an Upgrade's new process loads it (`load`). +fn upgradedForTest(gpa: std.mem.Allocator, p: *pardes.Pardes) !*pardes.Pardes { const bytes = try pardes.dump.byteDump(p); defer gpa.free(bytes); var tmp = std.testing.tmpDir(.{}); @@ -507,16 +568,9 @@ test "an upgrade's outcome is said in every view, at the pane its keyboard is on var text_buf: [4300]u8 = undefined; var rec = try Record.decode(try std.fmt.bufPrint(&text_buf, "link -1\nstub -1\nold -1\nwindow 0\nexe /x/pardes\ndump {s}/pardes-upgrade-1.dump\n", .{dir})); const q = try load(gpa, gpa, .{ .tty_only = true }, &rec); - defer q.deinit(); + errdefer q.deinit(); try std.testing.expect(!rec.fresh); - var seen: usize = 0; - for (q.views) |v| if (v) |view| { - const pane = q.panes[view.active].?; - try std.testing.expect(std.mem.startsWith(u8, pane.msg[0..pane.msg_len], "Upgrade: now pardes ")); - seen += 1; - }; - try std.testing.expectEqual(@as(usize, 2), seen); - try std.testing.expect(q.views[0].?.active != q.views[k.index()].?.active); + return q; } test "an upgrade's record reads back as it was written, and refuses one cut short" { -- cgit v1.3 From 2d54f7ff16f353ec8267133a9159591fbeca9f8d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 17:58:08 -0300 Subject: addons: a Zig addon's panic is pardes's panic, and a segmentation fault leaves a crash record: RUN on the base (a throwaway Debug build whose snake addon panics at its open, a tui session in a pty of its own, Snake sent over its 9P; .scratch kept/i5-addon-panic-throw): the session died with the trace on the terminal, NO CRASH RECORD, the terminal LEFT RAW (`-isig -icanon -iexten -echo -opost`, the alternate screen and the mouse modes still on: the shell after it took no line), `pardes new` exited 0, the daemon kept the shell ("shells no session holds"); the cause: a library kind is its own root, so its `@panic` ran std's handler, never runtime/main.zig's (replica.dying, vaxis.recover, crash.record); THE CHANGE: the ABI's pa_api gains `panic` (3.3, at its end, checked by api->size as `draw` is; an addon of 3.2 loads as ever, a 3.3 addon on an older pardes keeps std's handler), the core's entry (core/Kind.zig) `@panic`s with the addon's words ("an addon's panic: ...") so the host's root handler runs, and abi/addon.zig's `panic` is a handler that calls it, which every Zig addon's root names (`pub const panic = addon.panic;`: pdf, image, life, snake, snake_shader, test/liar, test/veil, and the example in addon.zig's head); runtime/main.zig `debug.handleSegfault` writes the crash record too (a fault in C code: MuPDF, stb, tree-sitter, an addon's library); RUN on the change (kept/i5-addon-panic-fixed): the record written ("panic: an addon's panic: addon panic: ... in addon snake, open"), the terminal put back (`isig icanon iexten echo`, the alternate screen and the mouse modes left), the daemon keeping the shell as before; NOT BUILT, the user's to rule: recovery (an addon's panic ending its pane and not the session); the behaviour tests read the addons' ABI as 3.3; addon-test Debug whole Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- abi/addon.zig | 23 +++++++++++++++++++---- abi/pardes_addon.h | 9 +++++++-- addons/image/image.zig | 1 + addons/life/life.zig | 1 + addons/pdf/pdf.zig | 1 + addons/snake/snake.zig | 1 + addons/snake_shader/snake_shader.zig | 1 + core/Kind.zig | 11 ++++++++++- runtime/main.zig | 3 +++ test/behaviour/addons.zig | 8 ++++---- test/behaviour/addons_pdf.zig | 2 +- test/liar.zig | 1 + test/veil.zig | 1 + 13 files changed, 51 insertions(+), 12 deletions(-) (limited to 'runtime') diff --git a/abi/addon.zig b/abi/addon.zig index 059e016d..53227fbb 100644 --- a/abi/addon.zig +++ b/abi/addon.zig @@ -20,9 +20,10 @@ //! //! and pardes's side (pa_api) as the functions below: `arena` and `heap` //! as Allocators, `seed`, `say`, `job`, `draw`, `cancel`, `look`, `text`, `exec`, -//! `select` and `found`. A body written is at most `body_max` bytes. +//! `select`, `found` and `panic`. A body written is at most `body_max` bytes. //! //! pub const pardes_addon = addon.ops(Snake); +//! pub const panic = addon.panic; //! comptime { //! addon.exportLib(&pardes_addon); //! } @@ -36,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 = 0x30002; +pub const abi = 0x30003; comptime { - if (c.PA_ABI != abi) @compileError("addon.zig speaks ABI 3.2 and the header another"); + if (c.PA_ABI != abi) @compileError("addon.zig speaks ABI 3.3 and the header another"); } /// A word the kind brings: `opens` a pane of it, else goes to the pane's @@ -51,6 +52,19 @@ pub const Head = struct { name: []const u8, version: u32, exts: [:0]const u8 = " /// pardes's side, kept from init: about the pane of the current call. pub var api: *const c.pa_api = undefined; +/// pardes's panic (pa_api.panic), from init, when its pardes has one. +var host_panic: ?*const fn ([*c]const u8, u32) callconv(.c) void = null; + +/// A library kind's panic handler (its root's `pub const panic = +/// addon.panic;`): pardes's own, so the panic ends the process as one of +/// pardes's does (its crash record, its terminal put back, its clients +/// told); std's where its pardes is older than ABI 3.3, or before init. +pub const panic = std.debug.FullPanic(struct { + fn call(msg: []const u8, ret_addr: ?usize) noreturn { + if (host_panic) |f| f(msg.ptr, @intCast(@min(msg.len, std.math.maxInt(u32)))); + std.debug.defaultPanic(msg, ret_addr); + } +}.call); /// The pane's arena: 16-aligned zeroed memory, all of it freed at the /// pane's close (a free frees nothing). @@ -91,7 +105,7 @@ pub fn job(in: []const u8) u32 { /// of the process that shows the pane, its answer to `jobDone` there alone /// (`token & drawn`), which keeps it for `paint` only. 0 when refused. pub fn draw(in: []const u8) u32 { - if (api.size < @sizeOf(c.pa_api)) return 0; + if (api.size < @offsetOf(c.pa_api, "draw") + @sizeOf(@TypeOf(api.draw))) return 0; return api.draw.?(in.ptr, @intCast(in.len)); } pub const drawn = c.PA_DRAWN; @@ -283,6 +297,7 @@ pub fn ops(comptime T: type) c.pa_ops { } fn init(a: [*c]const c.pa_api) callconv(.c) c_int { api = a; + if (a.*.size >= @offsetOf(c.pa_api, "panic") + @sizeOf(@TypeOf(a.*.panic))) host_panic = a.*.panic; return if (!@hasDecl(T, "init") or T.init()) c.PA_OK else 1; } fn open(path: [*c]const u8, bytes: [*c]const u8, len: u64) callconv(.c) ?*anyopaque { diff --git a/abi/pardes_addon.h b/abi/pardes_addon.h index 2f5c53de..d8257a0b 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 2u +#define PA_ABI_MINOR 3u #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 */ @@ -234,6 +234,11 @@ typedef struct pa_api { * PA_PLAIN kind's block, nor its token) `paint` alone reads; no other * call reads it, or anything made from it. 0: refused. */ uint32_t (*draw)(const void *in, uint32_t n); + /* Since 3.3 (check api->size): the addon panicked (a Zig addon's + * `pub const panic = addon.panic;`, a C addon's fatal error). pardes ends + * as at a panic of its own: its crash record written, its terminal put + * back, its clients told; it does not return. */ + void (*panic)(const char *msg, uint32_t n); } pa_api; /* A token of api->draw's. */ #define PA_DRAWN 0x80000000u @@ -390,7 +395,7 @@ _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"); _Static_assert(sizeof(pa_key) == 8 && sizeof(pa_mouse) == 16, "pa_key"); -_Static_assert(sizeof(pa_api) == 120 && sizeof(pa_out) == 16, "pa_api"); +_Static_assert(sizeof(pa_api) == 128 && sizeof(pa_out) == 16, "pa_api"); _Static_assert(sizeof(pa_word) == 32 && sizeof(pa_head) == 56, "pa_head"); _Static_assert(sizeof(pa_ops) == 208, "pa_ops"); #endif diff --git a/addons/image/image.zig b/addons/image/image.zig index 8e2cb32a..5b7976ac 100644 --- a/addons/image/image.zig +++ b/addons/image/image.zig @@ -128,6 +128,7 @@ pub const Image = extern struct { }; pub const pardes_addon = addon.ops(Image); +pub const panic = addon.panic; comptime { addon.exportLib(&pardes_addon); } diff --git a/addons/life/life.zig b/addons/life/life.zig index 254f248d..c49878cd 100644 --- a/addons/life/life.zig +++ b/addons/life/life.zig @@ -5,6 +5,7 @@ const std = @import("std"); const addon = @import("addon"); pub const pardes_addon = addon.ops(Life); +pub const panic = addon.panic; comptime { addon.exportLib(&pardes_addon); } diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig index 5694e8c8..e1539eae 100644 --- a/addons/pdf/pdf.zig +++ b/addons/pdf/pdf.zig @@ -35,6 +35,7 @@ const m = @import("pdf_bridge"); const c = addon.c; pub const pardes_addon = addon.ops(Pdf); +pub const panic = addon.panic; comptime { addon.exportLib(&pardes_addon); } diff --git a/addons/snake/snake.zig b/addons/snake/snake.zig index ef2283ac..9f2bdd4e 100644 --- a/addons/snake/snake.zig +++ b/addons/snake/snake.zig @@ -131,6 +131,7 @@ pub const Snake = extern struct { }; pub const pardes_addon = addon.ops(Snake); +pub const panic = addon.panic; comptime { addon.exportLib(&pardes_addon); } diff --git a/addons/snake_shader/snake_shader.zig b/addons/snake_shader/snake_shader.zig index 039e07b0..65e1dd44 100644 --- a/addons/snake_shader/snake_shader.zig +++ b/addons/snake_shader/snake_shader.zig @@ -372,6 +372,7 @@ pub const Snake = extern struct { }; pub const pardes_addon = addon.ops(Snake); +pub const panic = addon.panic; comptime { addon.exportLib(&pardes_addon); } diff --git a/core/Kind.zig b/core/Kind.zig index 5d2dcdb0..764b6f06 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -41,7 +41,7 @@ comptime { if (@sizeOf(usize) == 8) for (.{ .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ 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, 120 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 }, + .{ 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 }, }) |r| if (@sizeOf(r[0]) != r[1]) @compileError(std.fmt.comptimePrint("{s} is {d} bytes, the header says {d}", .{ @typeName(r[0]), @sizeOf(r[0]), r[1] })); } @@ -1229,6 +1229,15 @@ pub const api: c.pa_api = .{ return token; } }.f, + .panic = struct { + /// An addon's panic is pardes's (its root's handler: the crash + /// record, the terminal, the clients): a call into it never returns. + fn f(msg: [*c]const u8, n: u32) callconv(.c) void { + var buf: [512]u8 = undefined; + const said = cSlice(msg, n); + @panic(std.fmt.bufPrint(&buf, "an addon's panic: {s}", .{said}) catch said); + } + }.f, .found = struct { /// Gathered in the call: the search's answer, or onto its +Search after. fn f(rows: [*c]const u8, n: u32) callconv(.c) void { diff --git a/runtime/main.zig b/runtime/main.zig index 5cdf5ee0..e428faa2 100644 --- a/runtime/main.zig +++ b/runtime/main.zig @@ -52,6 +52,9 @@ pub const debug = struct { pardes.replica.dying(); @import("vaxis").recover(); } + // A fault in C code (an addon's library, MuPDF, tree-sitter) leaves + // a record as a panic does. + @import("runtime").crash.record(name); return std.debug.defaultHandleSegfault(addr, name, opt_ctx); } }; diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index e36b088c..1b284f8d 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.2 0 /")); + try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 3.3 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.2 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 1 3.3 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.2 0 /")); + try std.testing.expect(has(listed, "\nfakeword 1 3.3 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.2 0 /") and has(listed, " loaded\n")); + try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 3.3 0 /") and has(listed, " loaded\n")); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var buf: [4096]u8 = undefined; diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig index 18fa503c..0c7982d1 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.2 1 /")); + try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "pdf 1 3.3 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/liar.zig b/test/liar.zig index f564614b..e7bc2763 100644 --- a/test/liar.zig +++ b/test/liar.zig @@ -32,6 +32,7 @@ pub const Liar = extern struct { }; pub const pardes_addon = addon.ops(Liar); +pub const panic = addon.panic; comptime { addon.exportLib(&pardes_addon); } diff --git a/test/veil.zig b/test/veil.zig index 0be5d218..ac51de1c 100644 --- a/test/veil.zig +++ b/test/veil.zig @@ -32,6 +32,7 @@ pub const Veil = extern struct { }; pub const pardes_addon = addon.ops(Veil); +pub const panic = addon.panic; comptime { addon.exportLib(&pardes_addon); } -- cgit v1.3