-
Notifications
You must be signed in to change notification settings - Fork 64
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
macOS: Use objc2
crates
#188
Conversation
pub fn activate_cocoa_multithreading() { | ||
unsafe { | ||
let thread: *mut Object = msg_send![class!(NSThread), new]; | ||
let _: () = msg_send![thread, start]; | ||
} | ||
let thread = NSThread::new(); | ||
unsafe { thread.start() }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example of yet another improvement: This function was previously leaking, as the NSThread
wasn't released at the end of the scope. objc2
instead handles this kind of memory management for you automatically.
These replace the `objc` family of crates, and provide a bunch of improvements on top of it. Improvements relevant for `rfd`: - No longer need to call `msg_send!`, (almost) all methods have automatically generated bindings in `objc2-foundation`. - `MainThreadMarker`, allows marking explicitly the functions that must run on the main thread. - Blocks in `block2` have correct memory management, you no longer need to call `mem::forget`. - AppKit bindings are provided in `objc2-app-kit`, you no longer need to define `NSApplication`, `NSAlertStyle` and such manually. To do this change, I had to change how `AsModal` works, as it was previously relying on the fact that `NSAlert` and `NSSavePanel` just so happened to have mostly compatible methods; now we ensure statically that the correct method is called.
macos-latest is now macos-14, which runs on aarch64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thank you!
These replace the
objc
family of crates, and provide a bunch of improvements on top of it.Improvements relevant for
rfd
:msg_send!
, (almost) all methods have automatically generated bindings inobjc2-foundation
.MainThreadMarker
, allows marking explicitly the functions that must run on the main thread.block2
have correct memory management, you no longer need to callmem::forget
.objc2-app-kit
, you no longer need to defineNSApplication
,NSAlertStyle
and such manually.To do this change, I had to change how
AsModal
works, as it was previously relying on the fact thatNSAlert
andNSSavePanel
just so happened to have mostly compatible methods; now we ensure statically that the correct method is called.Please do ask if there's anything about either the crates or the code here that's unclear!