diff options
Diffstat (limited to 'src/dump.zig')
| -rw-r--r-- | src/dump.zig | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/dump.zig b/src/dump.zig index d1662e24..3269cc59 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -780,16 +780,19 @@ const SlotRecord = struct { /// way and its yank took nothing. tail: []const u8 = "", selection: []const u8 = "", + /// A plain kind's block's hash (Kind.Slot.state). + state: u64 = 0, }; pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) !void { var place: [32]u8 = undefined; - var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .gen = s.gen, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .cancelled = s.cancelled, .prefix = s.prefix.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection }; + var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .gen = s.gen, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .cancelled = s.cancelled, .prefix = s.prefix.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection, .state = s.state }; var owned: ?[]u8 = null; defer if (owned) |o| s.gpa.free(o); if (s.ops != null) { r.where = Kind.where(@constCast(s), &place); - owned = try slotRecord(@constCast(s)); + // A plain kind's record is its block, as it is (Kind.Slot.plain). + 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; } const bytes = try walk.save(SlotRecord, gpa, &r); @@ -816,7 +819,7 @@ pub fn slotRead(out: *Kind.Slot, gpa: std.mem.Allocator, bytes: []const u8) !voi var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); const r = try walk.load(SlotRecord, arena.allocator(), bytes, null); - out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .gen = r.gen, .art = r.art, .live = r.live, .next_tick = r.next_tick, .views = r.views, .focused = r.focused, .cancelled = r.cancelled }; + out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .gen = r.gen, .art = r.art, .live = r.live, .next_tick = r.next_tick, .views = r.views, .focused = r.focused, .cancelled = r.cancelled, .state = r.state }; errdefer out.free(); @memcpy(out.name[0..@min(15, r.name.len)], r.name[0..@min(15, r.name.len)]); out.path = try gpa.dupe(u8, r.path); @@ -865,6 +868,34 @@ pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void { } } +/// A replica client's pane of a plain kind it has the code of (`ops`), +/// loaded as the session dumped it: a slot of its core's own memory (the +/// rollback epoch), opened here, its block the record's bytes, its state +/// the session's. The loaded one (the C heap's) is freed. +pub fn plainHere(p: *Pardes, id: usize, old: *Kind.Slot, ops: *const Kind.Ops) !*Kind.Slot { + const s = try p.gpa.create(Kind.Slot); + s.* = .{ .ops = ops, .live = true, .gpa = p.gpa, .arena = .init(p.gpa), .name = old.name, .version = old.version, .gen = old.gen, .art = old.art, .where_text = old.where_text, .values = old.values, .prefix = old.prefix, .tail = old.tail, .opened = old.opened, .cancelled = old.cancelled, .tokens = old.tokens }; + errdefer { + s.free(); + p.gpa.destroy(s); + } + 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; + // 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; + const record = old.record orelse return error.KindRefused; + if (block.len != record.len) return error.KindRefused; + @memcpy(block, record); + s.next_tick, s.views, s.focused, s.state = kept; + const gpa = old.gpa; + old.free(); + gpa.destroy(old); + return s; +} + /// A PDF pane of a dump from before the pdf addon: a pane of the addon's /// kind `pdf` on its file, at its page, its fit and tint given again as /// its words; a placeholder until the addon is loaded. |
