From 60dd9514c8676e79c625948b5e9d2c6d745e8e87 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 12:14:58 -0300 Subject: idioms #3, the allocator a function is handed: Handover.carries opens its dump with the caller's gpa, not the page allocator, and Client.follow and stepGlide lose the gpa they never used Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/9p_io.zig | 2 -- src/Handover.zig | 4 ++-- src/dump.zig | 2 +- src/gui/gui.zig | 19 +++++++++---------- src/main.zig | 2 +- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/9p_io.zig b/src/9p_io.zig index 72548d2a..10109bb8 100644 --- a/src/9p_io.zig +++ b/src/9p_io.zig @@ -2613,7 +2613,6 @@ pub const Client = struct { /// a time, until `record(ctx, bytes)` says done. An end of file or a /// dropped connection is Hangup. What `pardes --wait` blocks on. pub fn follow( - gpa: std.mem.Allocator, dial: []const u8, path: []const u8, first: []const u8, @@ -2625,7 +2624,6 @@ pub const Client = struct { var names: [max_depth][]const u8 = undefined; const n = try elements(path, &names); var remote: RemoteError = .{}; - _ = gpa; const s = try startSession(dial, path); defer endSession(s, false); const fid = try walkTo(s, names[0..n], &remote); diff --git a/src/Handover.zig b/src/Handover.zig index e9e0622b..ed52271f 100644 --- a/src/Handover.zig +++ b/src/Handover.zig @@ -223,10 +223,10 @@ fn dumpCarried(p: *Pardes, kind: Kind, at: usize, ids: []const usize, seq: u32) /// Whether `bytes` are a handover's dump (`dumpCarried`'s, or an older /// build's), not a session's. -pub fn carries(bytes: []const u8) bool { +pub fn carries(gpa: std.mem.Allocator, bytes: []const u8) bool { if (std.mem.startsWith(u8, bytes, carried_magic)) return true; if (!pardes.Db.isImage(bytes)) return false; - const r = pardes.Db.Read.open(std.heap.page_allocator, bytes, null) catch return false; + const r = pardes.Db.Read.open(gpa, bytes, null) catch return false; defer r.close(); return (walk.Get.member(r.root(), "carried") catch null) != null; } diff --git a/src/dump.zig b/src/dump.zig index 82b1410f..5c897479 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -483,7 +483,7 @@ pub fn restore(p: *Pardes, bytes: []const u8, from: []const u8) !*Pardes { pub fn initFromDump(gpa: std.mem.Allocator, opts: Options, bytes: []const u8) !*Pardes { pardes.tape.startFromEnv(); const taped = pardes.tape.enter(null, .{ .init_from_dump = .{ .opts = opts, .bytes = bytes } }); - const p = (if (Handover.carries(bytes)) carriedWindow(gpa, opts, bytes) else loadAndRevive(gpa, opts, bytes, null, null)) catch |err| { + const p = (if (Handover.carries(gpa, bytes)) carriedWindow(gpa, opts, bytes) else loadAndRevive(gpa, opts, bytes, null, null)) catch |err| { pardes.tape.leave(null, taped); return err; }; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 48a30b8d..3bb304f0 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -4422,7 +4422,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a wheelAt(&g, &in, .{ .y = 1, .integer_y = 1, .mods = .{ .shift = true } }, mc); try std.testing.expectEqualStrings("", try Sent.take(core, &sent)); try std.testing.expectEqual(@as(i32, -1), g.scroll_notch); - stepGlide(&g, core, gpa); + stepGlide(&g, core); try std.testing.expectEqualStrings("", try Sent.take(core, &sent)); resetScroll(&g); // Its sign-in screen: mouse off, alternate scroll on, so arrow keys. @@ -4443,8 +4443,7 @@ const Glide = pardes.glide.Glide; /// Feeds a wheel's notches to the core, and keeps what moved the view for /// the frame's glide (Glide.frame). -fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { - _ = gpa; +fn stepGlide(g: *Gui, core: *pardes.Pardes) void { const notch = g.scroll_notch; g.scroll_notch = 0; var wheeled: ?usize = null; @@ -4523,7 +4522,7 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe // One notch down: the core is a line on at once. g.scroll_notch = 1; const scrolled = core.panes[core.view().active].?.scroll(); - stepGlide(&g, core, gpa); + stepGlide(&g, core); try std.testing.expectEqual(scrolled + 1, core.panes[core.view().active].?.scroll()); _ = arena.reset(.retain_capacity); s = try core.render(arena.allocator()); @@ -4540,7 +4539,7 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe while (g.glide.moving()) : (frames += 1) { now += 7 * ms; core.advance(now); - stepGlide(&g, core, gpa); + stepGlide(&g, core); g.now_ns = now; glideFrame(&g, gpa, s); try std.testing.expect(g.glide.follow.offset <= 1e-4); @@ -4576,13 +4575,13 @@ test "a wheel's caret rides with its line, the text's own glide, never a spring g.scroll_pane = core.view().active; g.scroll_col = r.x + 10; g.scroll_row = r.y + r.h - 2; - stepGlide(&g, core, gpa); + stepGlide(&g, core); // The window has drawn the view once (Glide.frame finds a view that moved). g.now_ns = now; glideFrame(&g, gpa, s); const before: f32 = @floatFromInt(s.cursor.?.y); g.scroll_notch = 1; - stepGlide(&g, core, gpa); + stepGlide(&g, core); var frames: usize = 0; while (true) : (frames += 1) { now += 7 * std.time.ns_per_ms; @@ -4600,7 +4599,7 @@ test "a wheel's caret rides with its line, the text's own glide, never a spring // Always exactly with its line, the cell less the text's offset. try std.testing.expectApproxEqAbs(@as(f32, @floatFromInt(s.cursor.?.y)) - g.glide.follow.offset, caretRow(&g, s, now).?, 1e-3); if (!g.glide.moving()) break; - stepGlide(&g, core, gpa); + stepGlide(&g, core); if (frames > 200) return error.NeverSettled; } try std.testing.expectEqual(@as(f32, @floatFromInt(s.cursor.?.y)), caretRow(&g, s, now).?); @@ -4625,7 +4624,7 @@ const GlideRun = struct { while (next < script.len and script[next].frame == frame) : (next += 1) core.update(.{ .key = script[next].key }); now += std.time.ns_per_s / 60; core.advance(now); - stepGlide(g, core, gpa); + stepGlide(g, core); _ = arena.reset(.retain_capacity); const s = try core.render(arena.allocator()); g.now_ns = now; @@ -4788,7 +4787,7 @@ fn resetScroll(g: *Gui) void { } fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { - stepGlide(g, core, gpa); + stepGlide(g, core); const id = g.scroll_pane orelse return; const pane = core.panes[id] orelse { resetScroll(g); diff --git a/src/main.zig b/src/main.zig index 68542b3e..5cbfa7f4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -246,7 +246,7 @@ fn waitForDel(gpa: std.mem.Allocator, dial: []const u8, path: []const u8, known: } }; const w: Wait = .{ .gpa = gpa, .dial = dial, .serial = serial }; - ninep_io.Client.follow(gpa, dial, "/log", "follow new", &w, Wait.gone, Wait.deleted) catch std.process.exit(1); + ninep_io.Client.follow(dial, "/log", "follow new", &w, Wait.gone, Wait.deleted) catch std.process.exit(1); std.process.exit(0); } -- cgit v1.3