diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Addon.zig | 10 | ||||
| -rw-r--r-- | src/Kind.zig | 6 | ||||
| -rw-r--r-- | src/dump.zig | 19 | ||||
| -rw-r--r-- | src/replica.zig | 14 |
4 files changed, 39 insertions, 10 deletions
diff --git a/src/Addon.zig b/src/Addon.zig index 16c38758..398ec415 100644 --- a/src/Addon.zig +++ b/src/Addon.zig @@ -343,7 +343,12 @@ fn listed(data: []const u8, path: []const u8, n: usize, why: *Why) Loaded { /// library loaded at the first pane of its kind, from the file the start /// listed it from (`listed`); null, and why, when it will not load. pub fn need(r: *Kind.Registry, k: u8, why: *Why) ?*const Kind.Ops { - if (r.ops[k] != null or tape.replaying()) return r.ops[k]; + if (r.ops[k] != null) return r.ops[k]; + // A client's: its own code for a plain kind, loaded at its first pane. + if (tape.replaying()) { + r.ops[k] = plainOps(&r.kinds[k]); + return r.ops[k]; + } const e = &r.kinds[k]; for (found[0..nfound], 0..) |*l, i| if (l.why.len == 0 and std.mem.eql(u8, &l.hash, &e.hash) and std.mem.eql(u8, l.path, e.path.slice())) { if (l.ops == 0) l.ops = loadListed(i, why) orelse return null; @@ -617,7 +622,8 @@ pub fn take(r: *Kind.Registry, l: Loaded, except: []const u8) ?[]const u8 { } e.why.set("loaded"); // A client's: its own code for a plain kind, or none (the session's). - r.ops[r.n] = if (tape.replaying()) plainOps(e) else @ptrFromInt(l.ops); + // A client's code for a plain kind is loaded at its first pane (`need`). + r.ops[r.n] = if (tape.replaying()) null else @ptrFromInt(l.ops); for (l.words) |w| { r.words[r.nwords] = .{ .kind = r.n, .arg = w.arg, .opens = w.opens }; r.words[r.nwords].name.set(w.name); diff --git a/src/Kind.zig b/src/Kind.zig index 47384227..374a2d81 100644 --- a/src/Kind.zig +++ b/src/Kind.zig @@ -138,7 +138,7 @@ pub const Slot = struct { // jobs' inputs, its file's hash, a placeholder's record), and what // a frame makes (the thumb, the pointer, whether one was drawn: a // view's, never a step's). - .local = .{ "ops", "st", "gpa", "arena", "plain", "opened", "reloads", "jobs", "tokens", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "shadow", "used" }, + .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "tokens", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "shadow", "used" }, }; /// Its kind's code here; null in a placeholder (`live` false: its kind /// not in the registry, its record kept for the day it comes) or a @@ -213,6 +213,9 @@ pub const Slot = struct { tail: Buf(160) = .{}, /// A replica's frame of it, as the authority painted it. shadow: ?*Shadow = null, + /// A client's join: its plain kind's file, until the pane is opened + /// from it (dump.plainHere). + file: ?[]u8 = null, /// Debug: the kind's allocations, which paint must leave as they are /// (the list the page allocator's: a region's first is slow in Debug). used: if (checked) std.ArrayList([]u8) else void = if (checked) .empty else {}, @@ -240,6 +243,7 @@ pub const Slot = struct { s.arena.deinit(); s.gpa.free(s.path); if (s.record) |r| s.gpa.free(r); + if (s.file) |f| s.gpa.free(f); s.* = undefined; } }; diff --git a/src/dump.zig b/src/dump.zig index 971a4d26..c5e2953b 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -263,11 +263,15 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 { pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![]u8 { slim_terminals = true; defer slim_terminals = false; + join_files = true; + defer join_files = false; return dumpWith(p, deferred); } /// `dumpJoin`'s and `dumpExit`'s: a terminal dumps its size, not its emulator. pub var slim_terminals = false; +/// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file). +var join_files = false; fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 { var d = try Session.init(p.gpa); @@ -782,6 +786,9 @@ const SlotRecord = struct { selection: []const u8 = "", /// A plain kind's block's hash (Kind.Slot.state). state: u64 = 0, + /// A client's join (`dumpJoin`): a plain kind's file, as the disk has + /// it now, which the client opens the pane from (plainHere). + file: ?[]const u8 = null, }; pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) !void { @@ -795,6 +802,15 @@ pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) owned = if (s.plain) |b| (if (b.len > 0) try s.gpa.dupe(u8, b) else null) else try slotRecord(@constCast(s)); r.record = owned; } + // Paid only at a client's join: the session keeps no file's bytes. + var file: ?[]u8 = null; + defer if (file) |f| s.gpa.free(f); + if (join_files and s.plain != null and s.ops != null) if (filesystem.localPath(s.path)) |path| { + const z = try s.gpa.dupeSentinel(u8, path, 0); + defer s.gpa.free(z); + file = filesystem.readHost(s.gpa, z, pardes.memory.limits.max_file_bytes) catch null; + r.file = file; + }; const bytes = try walk.save(SlotRecord, gpa, &r); defer gpa.free(bytes); try w.writeAll(bytes); @@ -830,6 +846,7 @@ pub fn slotRead(out: *Kind.Slot, gpa: std.mem.Allocator, bytes: []const u8) !voi out.values.set(r.values); out.selection = try gpa.dupe(u8, r.selection); if (r.record) |rec| out.record = try gpa.dupe(u8, rec); + if (r.file) |f| out.file = try gpa.dupe(u8, f); } pub fn slotFree(s: *Kind.Slot, gpa: std.mem.Allocator) void { @@ -883,7 +900,7 @@ pub fn plainHere(p: *Pardes, id: usize, old: *Kind.Slot, ops: *const Kind.Ops) ! s.path = try p.gpa.dupe(u8, old.path); s.selection = try p.gpa.dupe(u8, old.selection); const kept = .{ old.next_tick, old.views, old.focused, old.state }; - if (!Kind.reopen(p, id, s, null)) return error.KindRefused; + if (!Kind.reopen(p, id, s, old.file)) return error.KindRefused; // 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; diff --git a/src/replica.zig b/src/replica.zig index f84e61e8..b1b0514c 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -762,12 +762,14 @@ pub const Replica = struct { const c = try pardes.dump.load(epoch, o, bytes, null); // The chrome's colours are local, never dumped: the restored theme's. pardes.colors.finishThemeInitialization(c); - // It runs a plain kind's code of its own (Addon.plainOps), each pane - // of one opened here from its record; another's panes are Shadows. - for (c.kinds.kinds[0..c.kinds.n], c.kinds.ops[0..c.kinds.n]) |*e, *ops| ops.* = pardes.Addon.plainOps(e); - @memset(c.kinds.ops[c.kinds.n..], null); - for (c.panes, 0..) |pslot, at| if (pslot) |pane| if (pane.addon) |s| if (c.kinds.byName(s.nameOf())) |k| if (c.kinds.ops[k]) |ops| { - pane.addon = try pardes.dump.plainHere(c, at, s, ops); + // It runs a plain kind's code of its own (Addon.plainOps), loaded + // at its first pane, each opened here from its record; another's + // panes are Shadows. + c.kinds.ops = @splat(null); + for (c.panes, 0..) |pslot, at| if (pslot) |pane| if (pane.addon) |s| if (c.kinds.byName(s.nameOf())) |k| { + if (c.kinds.ops[k] == null) c.kinds.ops[k] = pardes.Addon.plainOps(&c.kinds.kinds[k]); + // Refused (its file not here): the line saying it does not run here. + if (c.kinds.ops[k]) |ops| pane.addon = pardes.dump.plainHere(c, at, s, ops) catch s; }; // What loading queued (a watch, a theme asked for) is the // authority's errand, done there already: the session was dumped |
