summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/dump.zig')
-rw-r--r--src/dump.zig56
1 files changed, 31 insertions, 25 deletions
diff --git a/src/dump.zig b/src/dump.zig
index 08736c84..52002697 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -925,9 +925,11 @@ const SlotRecord = struct {
/// What decides its next calls (Kind.step): a replica joining keeps
/// them, its Shadow calling where the authority's kind does.
next_tick: u64 = 0,
- view: u64 = 0,
+ views: [views.max]u64 = @splat(0),
focused: bool = false,
told: []const u8 = "",
+ /// A placeholder's why (its file not here).
+ refused: []const u8 = "",
/// What a step reads of it that its kind's open made (Kind.reopen) or
/// a call set: its tag's default words and what it has selected. A
/// replica's load opens no kind; without them its tag wrapped another
@@ -938,7 +940,7 @@ const SlotRecord = struct {
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, .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, .view = s.view, .focused = s.focused, .told = s.told.slice(), .tail = s.tail.slice(), .selection = s.selection };
+ var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .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, .told = s.told.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection };
var owned: ?[]u8 = null;
defer if (owned) |o| s.gpa.free(o);
if (s.ops != null) {
@@ -951,22 +953,17 @@ pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer)
try w.writeAll(bytes);
}
-/// The kind's record of a slot's state (`s.gpa`'s), or null for none: a
-/// dump of at most 1 MiB, then as many bytes as it asked for.
+/// The kind's record of a slot's state (`s.gpa`'s), or null for none: at
+/// most PA_RECORD_MAX bytes.
pub fn slotRecord(s: *Kind.Slot) !?[]u8 {
const f = (s.ops orelse return null).dump orelse return null;
- var cap: usize = 1 << 20;
- while (true) {
- const buf = try s.gpa.alloc(u8, cap);
- const n = Kind.dumpCall(s, f, buf);
- if (n == 0) {
- s.gpa.free(buf);
- return null;
- }
- if (n <= cap) return s.gpa.realloc(buf, n) catch buf[0..n];
+ const buf = try s.gpa.alloc(u8, Kind.c.PA_RECORD_MAX);
+ const n = Kind.dumpCall(s, f, buf);
+ if (n == 0 or n > buf.len) {
s.gpa.free(buf);
- cap = n;
+ return null;
}
+ return s.gpa.realloc(buf, n) catch buf[0..n];
}
/// The pane back from its record, a placeholder holding it until its
@@ -975,12 +972,13 @@ 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, .art = r.art, .live = r.live, .next_tick = r.next_tick, .view = r.view, .focused = r.focused };
+ out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .art = r.art, .live = r.live, .next_tick = r.next_tick, .views = r.views, .focused = r.focused };
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);
out.where_text.set(r.where);
out.told.set(r.told);
+ out.refused.set(r.refused);
out.tail.set(r.tail);
out.values.set(r.values);
out.selection = try gpa.dupe(u8, r.selection);
@@ -992,9 +990,12 @@ pub fn slotFree(s: *Kind.Slot, gpa: std.mem.Allocator) void {
s.free();
}
-/// A loaded pane of a kind opened by its kind, if this core has it, else
-/// a placeholder saying what it waits for. One with no record reopens from
-/// its file, its place and its words.
+/// A loaded pane of a kind opened by its kind from its file as a Look
+/// reads it, then given its record, if this core has the kind; else, or
+/// refused (its file not here, its record not taken), a placeholder saying
+/// what it waits for, its record kept. One with no record reopens at its
+/// place with its words. A placeholder comes back at the next Look or
+/// watch of its path, or the load of its kind.
pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void {
const k = p.kinds.byName(s.nameOf()) orelse {
s.live = false;
@@ -1002,14 +1003,19 @@ pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void {
};
s.ops = p.kinds.ops[k];
s.gen = p.kinds.kinds[k].gen;
- const bytes: ?[]u8 = if (s.record == null and s.path.len > 0) filesystem.read(p, s.path) catch null else null;
+ // A replica has no code to read it for: the authority's outcome is taped.
+ const bytes: ?[]u8 = if (s.ops != null and s.path.len > 0) filesystem.read(p, s.path) catch null else null;
defer if (bytes) |b| p.gpa.free(b);
- const kept = .{ s.next_tick, s.view, s.focused };
- _ = Kind.reopen(p, id, s, bytes);
- // A replica's Shadow is the authority's pane as it is: it ticks when
- // that one does, not because it was loaded (a kind opened here ticks
- // to lay itself out).
- if (s.ops == null) s.next_tick, s.view, s.focused = kept;
+ const kept = .{ s.next_tick, s.views, s.focused };
+ if (!Kind.reopen(p, id, s, bytes)) {
+ s.ops = null;
+ s.live = false;
+ } else if (s.ops == null) {
+ // A replica's Shadow is the authority's pane as it is: it ticks
+ // when that one does, not because it was loaded (a kind opened
+ // here ticks to lay itself out).
+ s.next_tick, s.views, s.focused = kept;
+ }
}
/// A PDF pane of a dump from before the pdf addon: a pane of the addon's