From a43a15b4a011128d6395fb93c51b0218f8ddb8b7 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 1 Sep 2022 03:10:00 +0200 Subject: [PATCH] iOS: Fix a few instances of UB (#2428) * Fix iOS 32-bit * Fix a few invalid message sends on iOS --- src/platform_impl/ios/event_loop.rs | 3 ++- src/platform_impl/ios/ffi.rs | 2 +- src/platform_impl/ios/monitor.rs | 2 +- src/platform_impl/ios/view.rs | 2 +- src/platform_impl/ios/window.rs | 8 ++++---- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/platform_impl/ios/event_loop.rs b/src/platform_impl/ios/event_loop.rs index eeaf2e68..2bd2bdaf 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -7,6 +7,7 @@ use std::{ sync::mpsc::{self, Receiver, Sender}, }; +use objc::runtime::Object; use raw_window_handle::{RawDisplayHandle, UiKitDisplayHandle}; use crate::{ @@ -113,7 +114,7 @@ impl EventLoop { F: 'static + FnMut(Event<'_, T>, &RootEventLoopWindowTarget, &mut ControlFlow), { unsafe { - let application: *mut c_void = msg_send![class!(UIApplication), sharedApplication]; + let application: *mut Object = msg_send![class!(UIApplication), sharedApplication]; assert_eq!( application, ptr::null_mut(), diff --git a/src/platform_impl/ios/ffi.rs b/src/platform_impl/ios/ffi.rs index 7f560514..a81f0cca 100644 --- a/src/platform_impl/ios/ffi.rs +++ b/src/platform_impl/ios/ffi.rs @@ -374,7 +374,7 @@ pub trait NSStringRust: Sized { impl NSStringRust for id { unsafe fn initWithUTF8String_(self, c_string: *const c_char) -> id { - msg_send![self, initWithUTF8String: c_string as id] + msg_send![self, initWithUTF8String: c_string] } unsafe fn stringByAppendingString_(self, other: id) -> id { diff --git a/src/platform_impl/ios/monitor.rs b/src/platform_impl/ios/monitor.rs index 42516cb0..3505b8df 100644 --- a/src/platform_impl/ios/monitor.rs +++ b/src/platform_impl/ios/monitor.rs @@ -177,7 +177,7 @@ impl MonitorHandle { pub fn retained_new(uiscreen: id) -> MonitorHandle { unsafe { assert_main_thread!("`MonitorHandle` can only be cloned on the main thread on iOS"); - let _: () = msg_send![uiscreen, retain]; + let _: id = msg_send![uiscreen, retain]; } MonitorHandle { inner: Inner { uiscreen }, diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index b4cb4225..727b7152 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -262,7 +262,7 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { let scale_factor: CGFloat = msg_send![object, contentScaleFactor]; PhysicalPosition::from_logical::<(f64, f64), f64>( (logical_location.x as _, logical_location.y as _), - scale_factor, + scale_factor as f64, ) }; touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 0a4b81c2..3f5e64cf 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -411,8 +411,8 @@ impl Window { let frame = match window_attributes.inner_size { Some(dim) => { - let scale_factor = msg_send![screen, scale]; - let size = dim.to_logical::(scale_factor); + let scale_factor: CGFloat = msg_send![screen, scale]; + let size = dim.to_logical::(scale_factor as f64); CGRect { origin: screen_bounds.origin, size: CGSize { @@ -427,8 +427,8 @@ impl Window { let view = view::create_view(&window_attributes, &platform_attributes, frame); let gl_or_metal_backed = { - let view_class: id = msg_send![view, class]; - let layer_class: id = msg_send![view_class, layerClass]; + let view_class: *const Class = msg_send![view, class]; + let layer_class: *const Class = msg_send![view_class, layerClass]; let is_metal: BOOL = msg_send![layer_class, isSubclassOfClass: class!(CAMetalLayer)]; let is_gl: BOOL = msg_send![layer_class, isSubclassOfClass: class!(CAEAGLLayer)];