Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: don't copy App and apprt.App #5509

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jcollie
Copy link
Collaborator

@jcollie jcollie commented Feb 1, 2025

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.

@mitchellh
Copy link
Contributor

I'm not against it but again... why now? Is this change for change sake or is there a motivating thing you're working on?

@jcollie
Copy link
Collaborator Author

jcollie commented Feb 3, 2025

I'm not against it but again... why now? Is this change for change sake or is there a motivating thing you're working on?

Yeah, as I was working on some of the changes needed to get the GTK apprt structs to use DerivedConfigs instead of using the "raw" config this made some things easier. Plus it's more consistent with how the other GTK structs are handled (Window, Tab, Surface).

src/main_ghostty.zig Outdated Show resolved Hide resolved
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.
@jcollie jcollie changed the title core: con't copy App and apprt.App core: don't copy App and apprt.App Feb 5, 2025
Copy link
Collaborator

@gabydd gabydd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little thing. Also i agree having app be a stable pointer would have been useful for me at some point(though it's also not that bad to have to allocate a couple objects for callbacks) but is there a reason that CoreApp needs a stable pointer?

src/apprt/embedded.zig Show resolved Hide resolved
@jcollie
Copy link
Collaborator Author

jcollie commented Feb 5, 2025

is there a reason that CoreApp needs a stable pointer

I don't have a particular use case or need at this time but made the change now for consistency's sake.

Copy link
Collaborator

@gabydd gabydd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the churn on this part

try core_app.init(global.alloc);
errdefer {
core_app.deinit();
global.alloc.destroy(core_app);
Copy link
Collaborator

@gabydd gabydd Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the error defer has to be above the init so if the init fails then it will be destroyed. The ordering will still be correct as the second errdefer runs first see this as an example

const std = @import("std");

fn fail() !void {
    return error.Fail;
}
pub fn main() !void {
    errdefer std.debug.print("prints second\n", .{});
    errdefer std.debug.print("prints first\n", .{});
    try fail();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants