diff --git a/src/Surface.zig b/src/Surface.zig index 00dc9ce55..554c3b01c 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -426,51 +426,50 @@ pub fn init( }; // Start our IO implementation - var io_exec = try termio.Exec.init(alloc, .{ - .command = config.command, - .shell_integration = config.@"shell-integration", - .shell_integration_features = config.@"shell-integration-features", - .working_directory = config.@"working-directory", - .resources_dir = main.state.resources_dir, - .term = config.term, + // This separate block ({}) is important because our errdefers must + // be scoped here to be valid. + { + // Initialize our IO backend + var io_exec = try termio.Exec.init(alloc, .{ + .command = config.command, + .shell_integration = config.@"shell-integration", + .shell_integration_features = config.@"shell-integration-features", + .working_directory = config.@"working-directory", + .resources_dir = main.state.resources_dir, + .term = config.term, - // Get the cgroup if we're on linux and have the decl. I'd love - // to change this from a decl to a surface options struct because - // then we can do memory management better (don't need to retain - // the string around). - .linux_cgroup = if (comptime builtin.os.tag == .linux and - @hasDecl(apprt.runtime.Surface, "cgroup")) - rt_surface.cgroup() - else - Command.linux_cgroup_default, - }); - errdefer io_exec.deinit(); - var io_writer = try termio.Writer.initMailbox(alloc); - errdefer io_writer.deinit(alloc); - try termio.Termio.init(&self.io, alloc, .{ - .grid_size = grid_size, - .screen_size = screen_size, - .padding = padding, - .full_config = config, - .config = try termio.Termio.DerivedConfig.init(alloc, config), - .reader = .{ .exec = io_exec }, - .writer = io_writer, - .resources_dir = main.state.resources_dir, - .renderer_state = &self.renderer_state, - .renderer_wakeup = render_thread.wakeup, - .renderer_mailbox = render_thread.mailbox, - .surface_mailbox = .{ .surface = self, .app = app_mailbox }, + // Get the cgroup if we're on linux and have the decl. I'd love + // to change this from a decl to a surface options struct because + // then we can do memory management better (don't need to retain + // the string around). + .linux_cgroup = if (comptime builtin.os.tag == .linux and + @hasDecl(apprt.runtime.Surface, "cgroup")) + rt_surface.cgroup() + else + Command.linux_cgroup_default, + }); + errdefer io_exec.deinit(); - // Get the cgroup if we're on linux and have the decl. I'd love - // to change this from a decl to a surface options struct because - // then we can do memory management better (don't need to retain - // the string around). - .linux_cgroup = if (comptime builtin.os.tag == .linux and - @hasDecl(apprt.runtime.Surface, "cgroup")) - rt_surface.cgroup() - else - Command.linux_cgroup_default, - }); + // Initialize our IO writer + var io_writer = try termio.Writer.initMailbox(alloc); + errdefer io_writer.deinit(alloc); + + try termio.Termio.init(&self.io, alloc, .{ + .grid_size = grid_size, + .screen_size = screen_size, + .padding = padding, + .full_config = config, + .config = try termio.Termio.DerivedConfig.init(alloc, config), + .reader = .{ .exec = io_exec }, + .writer = io_writer, + .renderer_state = &self.renderer_state, + .renderer_wakeup = render_thread.wakeup, + .renderer_mailbox = render_thread.mailbox, + .surface_mailbox = .{ .surface = self, .app = app_mailbox }, + }); + } + // Outside the block, IO has now taken ownership of our temporary state + // so we can just defer this and not the subcomponents. errdefer self.io.deinit(); // Report initial cell size on surface creation diff --git a/src/termio/Options.zig b/src/termio/Options.zig index 7e97f7dfd..19de39756 100644 --- a/src/termio/Options.zig +++ b/src/termio/Options.zig @@ -32,9 +32,6 @@ reader: termio.Reader, /// If you're using termio.Thread this MUST be "mailbox". writer: termio.Writer, -/// The application resources directory. -resources_dir: ?[]const u8, - /// The render state. The IO implementation can modify anything here. The /// surface thread will setup the initial "terminal" pointer but the IO impl /// is free to change that if that is useful (i.e. doing some sort of dual @@ -50,7 +47,3 @@ renderer_mailbox: *renderer.Thread.Mailbox, /// The mailbox for sending the surface messages. surface_mailbox: apprt.surface.Mailbox, - -/// The cgroup to apply to the started termio process, if able by -/// the termio implementation. This only applies to Linux. -linux_cgroup: Command.LinuxCgroup = Command.linux_cgroup_default,