mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-21 14:55:20 +00:00
core: con't copy App and apprt.App
Besides avoiding copying, this allows consumers to choose to allocate these structs on the stack or to allocate on the heap. It also gives the apprt.App a stable pointer sooner in the process.
This commit is contained in:
committed by
Mitchell Hashimoto
parent
070e017b1b
commit
c6f23bbb32
@@ -117,10 +117,11 @@ pub const App = struct {
|
||||
config: Config,
|
||||
|
||||
pub fn init(
|
||||
self: *App,
|
||||
core_app: *CoreApp,
|
||||
config: *const Config,
|
||||
opts: Options,
|
||||
) !App {
|
||||
) !void {
|
||||
// We have to clone the config.
|
||||
const alloc = core_app.alloc;
|
||||
var config_clone = try config.clone(alloc);
|
||||
@@ -129,7 +130,7 @@ pub const App = struct {
|
||||
var keymap = try input.Keymap.init();
|
||||
errdefer keymap.deinit();
|
||||
|
||||
return .{
|
||||
self.* = .{
|
||||
.core_app = core_app,
|
||||
.config = config_clone,
|
||||
.opts = opts,
|
||||
@@ -1316,13 +1317,16 @@ pub const CAPI = struct {
|
||||
opts: *const apprt.runtime.App.Options,
|
||||
config: *const Config,
|
||||
) !*App {
|
||||
var core_app = try CoreApp.create(global.alloc);
|
||||
errdefer core_app.destroy();
|
||||
var core_app = try global.alloc.create(CoreApp);
|
||||
errdefer {
|
||||
core_app.deinit();
|
||||
global.alloc.destroy(core_app);
|
||||
}
|
||||
|
||||
// Create our runtime app
|
||||
var app = try global.alloc.create(App);
|
||||
errdefer global.alloc.destroy(app);
|
||||
app.* = try .init(core_app, config, opts.*);
|
||||
try app.init(core_app, config, opts.*);
|
||||
errdefer app.terminate();
|
||||
|
||||
return app;
|
||||
@@ -1345,7 +1349,8 @@ pub const CAPI = struct {
|
||||
const core_app = v.core_app;
|
||||
v.terminate();
|
||||
global.alloc.destroy(v);
|
||||
core_app.destroy();
|
||||
core_app.deinit();
|
||||
global.alloc.destroy(core_app);
|
||||
}
|
||||
|
||||
/// Update the focused state of the app.
|
||||
|
||||
Reference in New Issue
Block a user