Skip to content

Commit

Permalink
Enable deny(unsafe_op_in_unsafe_fn) in macOS backend
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 2, 2022
1 parent 1505015 commit 4e4c2ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/platform_impl/ios/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl AppState {
#[inline(never)]
#[cold]
unsafe fn init_guard(guard: &mut RefMut<'static, Option<AppState>>) {
let waker = EventLoopWaker::new(CFRunLoopGetMain());
let waker = EventLoopWaker::new(unsafe { CFRunLoopGetMain() });
**guard = Some(AppState {
app_state: Some(AppStateImpl::NotLaunched {
queued_windows: Vec::new(),
Expand Down
1 change: 0 additions & 1 deletion src/platform_impl/macos/appkit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![deny(unsafe_op_in_unsafe_fn)]
// Objective-C methods have different conventions, and it's much easier to
// understand if we just use the same names
#![allow(non_snake_case)]
Expand Down
3 changes: 1 addition & 2 deletions src/platform_impl/macos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(target_os = "macos")]
#![allow(clippy::let_unit_value)]
#![deny(unsafe_op_in_unsafe_fn)]

#[macro_use]
mod util;
Expand Down
24 changes: 13 additions & 11 deletions src/platform_impl/macos/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ unsafe fn control_flow_handler<F>(panic_info: *mut c_void, f: F)
where
F: FnOnce(Weak<PanicInfo>) + UnwindSafe,
{
let info_from_raw = Weak::from_raw(panic_info as *mut PanicInfo);
let info_from_raw = unsafe { Weak::from_raw(panic_info as *mut PanicInfo) };
// Asserting unwind safety on this type should be fine because `PanicInfo` is
// `RefUnwindSafe` and `Rc<T>` is `UnwindSafe` if `T` is `RefUnwindSafe`.
let panic_info = AssertUnwindSafe(Weak::clone(&info_from_raw));
Expand Down Expand Up @@ -195,7 +195,7 @@ struct RunLoop(CFRunLoopRef);

impl RunLoop {
unsafe fn get() -> Self {
RunLoop(CFRunLoopGetMain())
RunLoop(unsafe { CFRunLoopGetMain() })
}

unsafe fn add_observer(
Expand All @@ -205,15 +205,17 @@ impl RunLoop {
handler: CFRunLoopObserverCallBack,
context: *mut CFRunLoopObserverContext,
) {
let observer = CFRunLoopObserverCreate(
ptr::null_mut(),
flags,
ffi::TRUE, // Indicates we want this to run repeatedly
priority, // The lower the value, the sooner this will run
handler,
context,
);
CFRunLoopAddObserver(self.0, observer, kCFRunLoopCommonModes);
let observer = unsafe {
CFRunLoopObserverCreate(
ptr::null_mut(),
flags,
ffi::TRUE, // Indicates we want this to run repeatedly
priority, // The lower the value, the sooner this will run
handler,
context,
)
};
unsafe { CFRunLoopAddObserver(self.0, observer, kCFRunLoopCommonModes) };
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/platform_impl/macos/util/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ pub(crate) fn toggle_full_screen_async(

pub(crate) unsafe fn restore_display_mode_async(ns_screen: u32) {
Queue::main().exec_async(move || {
ffi::CGRestorePermanentDisplayConfiguration();
assert_eq!(ffi::CGDisplayRelease(ns_screen), ffi::kCGErrorSuccess);
unsafe { ffi::CGRestorePermanentDisplayConfiguration() };
assert_eq!(
unsafe { ffi::CGDisplayRelease(ns_screen) },
ffi::kCGErrorSuccess
);
});
}

Expand Down

0 comments on commit 4e4c2ea

Please sign in to comment.