summaryrefslogtreecommitdiff
path: root/src/terminal.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/terminal.zig')
-rw-r--r--src/terminal.zig28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/terminal.zig b/src/terminal.zig
index fcb284a0..aedc007f 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -143,6 +143,11 @@ pub const MarkedHandler = if (enabled) struct {
} else void;
pub const State = struct {
+ /// What the emulator and this struct are allocated with: the core's,
+ /// but on a screen-state replica the C heap (`emulator_gpa`), outside
+ /// its rollback epoch: written by deltas while a copy is held, no part
+ /// of it is ever a copy's to save or put back.
+ gpa: std.mem.Allocator,
vt: VtSlot,
stream: StreamSlot,
/// The emulator's answers to its program (DSR, DA, kitty graphics, ...)
@@ -281,7 +286,7 @@ pub const State = struct {
.kitty_image_storage_limit = if (images_enabled) TerminalImages.storage_limit else 0,
});
defer decoded.deinit(gpa);
- out.* = .{ .vt = decoded.toOwned(), .stream = undefined };
+ out.* = .{ .gpa = gpa, .vt = decoded.toOwned(), .stream = undefined };
if (comptime images_enabled) inline for (.{ .primary, .alternate }) |key| {
if (out.vt.screens.get(key)) |screen| screen.kitty_images.image_limits = .allWithTempDir(tempDir());
};
@@ -582,6 +587,9 @@ pub fn takeMarks(state: *State, bytes: []const u8) void {
m.finished = if (seq == std.math.maxInt(u32)) null else .{ .seq = seq, .status = if (status == std.math.minInt(i32)) null else status };
}
+/// A screen-state replica's emulators' allocator (`State.gpa`).
+pub const emulator_gpa = std.heap.c_allocator;
+
/// A replica's speculation leaves an emulator be: it is the authority's
/// (docs/next-daemon.md, phase 5), so the input waits for its order.
fn authorityOnly() bool {
@@ -629,7 +637,8 @@ pub fn resizeGrid(pane: *Pane, gpa: std.mem.Allocator, cols: u16, rows: u16) voi
// A replica's emulator is sized by its authority: the next delta says.
if (pardes.tape.screenReplica()) return;
state.changes +%= 1;
- state.vt.resize(gpa, .{ .cols = cols, .rows = rows }) catch {};
+ _ = gpa;
+ state.vt.resize(state.gpa, .{ .cols = cols, .rows = rows }) catch {};
}
/// DECSET 2004: the program wants its pastes bracketed.
@@ -829,8 +838,9 @@ pub fn deinitEmulator(pane: *Pane, gpa: std.mem.Allocator) void {
const state = pane.terminal orelse return;
if (comptime images_enabled) state.images.deinit(gpa);
state.stream.deinit();
- state.vt.deinit(gpa);
- gpa.destroy(state);
+ const own = state.gpa;
+ state.vt.deinit(own);
+ own.destroy(state);
pane.terminal = null;
}
@@ -841,9 +851,11 @@ pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
const pane = try createDoc(gpa, cols, rows);
errdefer gpa.destroy(pane);
if (comptime !enabled) return pane;
- const state = try gpa.create(State);
- errdefer gpa.destroy(state);
- state.vt = try ghostty_vt.Terminal.init(terminalIo(), gpa, .{
+ const own = if (pardes.tape.screenReplica()) emulator_gpa else gpa;
+ const state = try own.create(State);
+ errdefer own.destroy(state);
+ state.gpa = own;
+ state.vt = try ghostty_vt.Terminal.init(terminalIo(), own, .{
.cols = cols,
.rows = rows,
.max_scrollback_bytes = 16 * 1024 * 1024,
@@ -856,7 +868,7 @@ pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
// it could send itself: it runs as the user, under pardes.
.kitty_image_loading_limits = if (images_enabled) .allWithTempDir(tempDir()) else if (@FieldType(ghostty_vt.Terminal.Options, "kitty_image_loading_limits") == void) {} else .direct,
});
- state.stream = .init(.{ .handler = .{ .inner = state.vt.vtHandler() }, .allocator = gpa });
+ state.stream = .init(.{ .handler = .{ .inner = state.vt.vtHandler() }, .allocator = own });
state.reply_len = 0;
state.changes = 0;
state.read = false;