Skip to content

Make handles reference-counted#206

Closed
madsmtm wants to merge 4 commits intomadsmtm/merge-rawfrom
madsmtm/reference-count
Closed

Make handles reference-counted#206
madsmtm wants to merge 4 commits intomadsmtm/merge-rawfrom
madsmtm/reference-count

Conversation

@madsmtm
Copy link
Member

@madsmtm madsmtm commented Mar 1, 2026

Fixes #188.


unsafe { Self::new(ns_view, objc_retain, objc_release) }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Unsure whether we should be in the business of exposing target-specific helper methods like these?

We definitely shouldn't make the AppKitWindowHandle struct be #[cfg(target_os = "macos")], because it can technically also be used on Linux with GNUStep.

I also just now realized that this links libobjc, even if never used (which would be annoying for e.g. someone running Wayland on macOS). So if we wanted to do this, we might need to gate it behind a feature flag?

Comment on lines +82 to +85
// objc_retain
retain: unsafe extern "C-unwind" fn(ns_view: *mut c_void) -> *mut c_void,
// objc_release
release: unsafe extern "C-unwind" fn(ns_view: *mut c_void),
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to discuss advantages/disadvantages of storing function pointers directly vs. storing a &'static vtable like Waker does. I assume its done to keep the size of Waker down to 2 pointers? Is it worth the effort in our case?

I do find it kinda annoying that it'd introduce a new AppKitWindowHandleVTable type for most of the handles we have, but maybe that can be worked around by using tuples?

pub unsafe fn new(
    ns_view: NonNull<c_void>,
    vtable: &'static (
        // retain
        unsafe extern "C-unwind" fn(ns_view: *mut c_void) -> *mut c_void,
        // release
        unsafe extern "C-unwind" fn(ns_view: *mut c_void),
    ),
) -> Self { ... }

Comment on lines +146 to +148
// TODO: Should we store a function to get the surface pointer, or just the surface pointer
// itself? The user is required to always return the same pointer, so either option is valid.
get_surface: unsafe fn(info: *const ()) -> NonNull<c_void>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Unsure whether we should use a function to get the surface, or store the surface: NonNull<c_void> directly?

I'm leaning a bit towards storing the surface pointer directly to make it clear that it can't change, but I guess it depends on whether we want vtables to keep the size down?

@madsmtm
Copy link
Member Author

madsmtm commented Mar 7, 2026

We discussed this in the meeting today, and decided that the semantics should be "the entire window state is kept alive for the duration of the reference-count (not just the surface state)", which means we're probably going to go with #207 instead.

@madsmtm madsmtm closed this Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant