Always specify function ABI

This commit is contained in:
Mads Marquart 2022-07-10 17:24:22 +02:00
parent db4f2c0720
commit 56f748910e
8 changed files with 30 additions and 30 deletions

View file

@ -360,7 +360,7 @@ pub(crate) fn register_view_class() -> *const Class {
let superclass = class!(NSView); let superclass = class!(NSView);
let mut decl = ClassDecl::new("RSTView", superclass).unwrap(); let mut decl = ClassDecl::new("RSTView", superclass).unwrap();
decl.add_method(sel!(isFlipped), enforce_normalcy as extern fn(&Object, _) -> BOOL); decl.add_method(sel!(isFlipped), enforce_normalcy as extern "C" fn(&Object, _) -> BOOL);
decl.add_ivar::<id>(BACKGROUND_COLOR); decl.add_ivar::<id>(BACKGROUND_COLOR);
@ -384,12 +384,12 @@ pub(crate) fn register_view_class_with_delegate<T: ViewDelegate>(instance: &T) -
decl.add_method( decl.add_method(
sel!(isFlipped), sel!(isFlipped),
enforce_normalcy as extern fn(&Object, _) -> BOOL enforce_normalcy as extern "C" fn(&Object, _) -> BOOL
); );
decl.add_method( decl.add_method(
sel!(draggingEntered:), sel!(draggingEntered:),
dragging_entered::<T> as extern fn (&mut Object, _, _) -> NSUInteger dragging_entered::<T> as extern "C" fn (&mut Object, _, _) -> NSUInteger
); );
}) })
} }
@ -401,7 +401,7 @@ to the Rust `ViewDelegate` implementation.
The methods we're setting up can range from simple to complex - take `isFlipped`: The methods we're setting up can range from simple to complex - take `isFlipped`:
``` rust ``` rust
extern fn is_flipped(_: &Object, _: Sel) -> BOOL { extern "C" fn is_flipped(_: &Object, _: Sel) -> BOOL {
return YES; return YES;
} }
``` ```
@ -409,7 +409,7 @@ extern fn is_flipped(_: &Object, _: Sel) -> BOOL {
Here, we just want to tell `NSView` to use top,left as the origin point, so we need to respond `YES` in this subclass method. Here, we just want to tell `NSView` to use top,left as the origin point, so we need to respond `YES` in this subclass method.
``` rust ``` rust
extern fn dragging_entered<T: ViewDelegate>(this: &mut Object, _: Sel, info: id) -> NSUInteger { extern "C" fn dragging_entered<T: ViewDelegate>(this: &mut Object, _: Sel, info: id) -> NSUInteger {
let view = utils::load::<T>(this, VIEW_DELEGATE_PTR); let view = utils::load::<T>(this, VIEW_DELEGATE_PTR);
view.dragging_entered(DragInfo { view.dragging_entered(DragInfo {
info: unsafe { Id::from_ptr(info) } info: unsafe { Id::from_ptr(info) }

View file

@ -49,15 +49,15 @@ macro_rules! method_decl_impl {
} }
); );
($($t:ident),*) => ( ($($t:ident),*) => (
method_decl_impl!(-T, R, extern fn(&T, Sel $(, $t)*) -> R, $($t),*); method_decl_impl!(-T, R, extern "C" fn(&T, Sel $(, $t)*) -> R, $($t),*);
method_decl_impl!(-T, R, extern fn(&mut T, Sel $(, $t)*) -> R, $($t),*); method_decl_impl!(-T, R, extern "C" fn(&mut T, Sel $(, $t)*) -> R, $($t),*);
); );
} }
method_decl_impl!(); method_decl_impl!();
method_decl_impl!(A); method_decl_impl!(A);
extern fn get_bundle_id(this: &Object, s: Sel, v: id) -> id { extern "C" fn get_bundle_id(this: &Object, s: Sel, v: id) -> id {
unsafe { unsafe {
let bundle = class!(NSBundle); let bundle = class!(NSBundle);
let main_bundle: id = msg_send![bundle, mainBundle]; let main_bundle: id = msg_send![bundle, mainBundle];
@ -95,6 +95,6 @@ unsafe fn swizzle_bundle_id<F>(bundle_id: &str, func: F) where F: MethodImplemen
pub fn set_bundle_id(bundle_id: &str) { pub fn set_bundle_id(bundle_id: &str) {
unsafe { unsafe {
swizzle_bundle_id(bundle_id, get_bundle_id as extern fn(&Object, _, _) -> id); swizzle_bundle_id(bundle_id, get_bundle_id as extern "C" fn(&Object, _, _) -> id);
} }
} }

View file

@ -30,7 +30,7 @@ pub(crate) fn register_image_view_class() -> *const Class {
let superclass = class!(NSImageView); let superclass = class!(NSImageView);
let decl = ClassDecl::new("RSTImageView", superclass).unwrap(); let decl = ClassDecl::new("RSTImageView", superclass).unwrap();
//decl.add_method(sel!(isFlipped), enforce_normalcy as extern fn(&Object, _) -> BOOL); //decl.add_method(sel!(isFlipped), enforce_normalcy as extern "C" fn(&Object, _) -> BOOL);
VIEW_CLASS = decl.register(); VIEW_CLASS = decl.register();
}); });

View file

@ -79,7 +79,7 @@ extern "C" fn menu_needs_update<T: ListViewDelegate>(this: &Object, _: Sel, menu
/// The other less obvious way is to subclass and override the `shouldSelectRow:` method; here, we /// The other less obvious way is to subclass and override the `shouldSelectRow:` method; here, we
/// simply assume things are selectable and call our delegate as if things were selected. This may /// simply assume things are selectable and call our delegate as if things were selected. This may
/// need to change in the future, but it works well enough for now. /// need to change in the future, but it works well enough for now.
extern fn select_row<T: ListViewDelegate>( extern "C" fn select_row<T: ListViewDelegate>(
this: &Object, this: &Object,
_: Sel, _: Sel,
_table_view: id, _table_view: id,

View file

@ -69,7 +69,7 @@ pub(crate) fn register_app_delegate_class<T: AppDelegate>() -> *const Class {
); );
/*decl.add_method( /*decl.add_method(
sel!(application:didDiscardSceneSessions:), sel!(application:didDiscardSceneSessions:),
did_discard_scene_sessions::<T> as extern fn(&Object, _, _, id) did_discard_scene_sessions::<T> as extern "C" fn(&Object, _, _, id)
);*/ );*/
DELEGATE_CLASS = decl.register(); DELEGATE_CLASS = decl.register();

View file

@ -10,7 +10,7 @@ use crate::view::{VIEW_DELEGATE_PTR, ViewDelegate};
use crate::utils::{load, as_bool}; use crate::utils::{load, as_bool};
/// Called when the view controller receives a `viewWillAppear:` message. /// Called when the view controller receives a `viewWillAppear:` message.
extern fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) { extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewWillAppear:animated]; let _: () = msg_send![super(this, class!(UIViewController)), viewWillAppear:animated];
} }
@ -20,7 +20,7 @@ extern fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL
} }
/// Called when the view controller receives a `viewDidAppear:` message. /// Called when the view controller receives a `viewDidAppear:` message.
extern fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) { extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewDidAppear:animated]; let _: () = msg_send![super(this, class!(UIViewController)), viewDidAppear:animated];
} }
@ -30,7 +30,7 @@ extern fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL)
} }
/// Called when the view controller receives a `viewWillDisappear:` message. /// Called when the view controller receives a `viewWillDisappear:` message.
extern fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) { extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewWillDisappear:animated]; let _: () = msg_send![super(this, class!(UIViewController)), viewWillDisappear:animated];
} }
@ -40,7 +40,7 @@ extern fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: B
} }
/// Called when the view controller receives a `viewDidDisappear:` message. /// Called when the view controller receives a `viewDidDisappear:` message.
extern fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) { extern "C" fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewDidDisappear:animated]; let _: () = msg_send![super(this, class!(UIViewController)), viewDidDisappear:animated];
} }
@ -60,10 +60,10 @@ pub(crate) fn register_view_controller_class<T: ViewDelegate + 'static>() -> *co
decl.add_ivar::<usize>(VIEW_DELEGATE_PTR); decl.add_ivar::<usize>(VIEW_DELEGATE_PTR);
decl.add_method(sel!(viewWillAppear:), will_appear::<T> as extern fn(&mut Object, _, BOOL)); decl.add_method(sel!(viewWillAppear:), will_appear::<T> as extern "C" fn(&mut Object, _, BOOL));
decl.add_method(sel!(viewDidAppear:), did_appear::<T> as extern fn(&mut Object, _, BOOL)); decl.add_method(sel!(viewDidAppear:), did_appear::<T> as extern "C" fn(&mut Object, _, BOOL));
decl.add_method(sel!(viewWillDisappear:), will_disappear::<T> as extern fn(&mut Object, _, BOOL)); decl.add_method(sel!(viewWillDisappear:), will_disappear::<T> as extern "C" fn(&mut Object, _, BOOL));
decl.add_method(sel!(viewDidDisappear:), did_disappear::<T> as extern fn(&mut Object, _, BOOL)); decl.add_method(sel!(viewDidDisappear:), did_disappear::<T> as extern "C" fn(&mut Object, _, BOOL));
VIEW_CLASS = decl.register(); VIEW_CLASS = decl.register();
}); });

View file

@ -11,7 +11,7 @@ use crate::view::{VIEW_DELEGATE_PTR, ViewDelegate};
use crate::utils::load; use crate::utils::load;
/// Called when the view controller receives a `viewWillAppear` message. /// Called when the view controller receives a `viewWillAppear` message.
extern fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel) { extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(NSViewController)), viewWillAppear]; let _: () = msg_send![super(this, class!(NSViewController)), viewWillAppear];
} }
@ -21,7 +21,7 @@ extern fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel) {
} }
/// Called when the view controller receives a `viewDidAppear` message. /// Called when the view controller receives a `viewDidAppear` message.
extern fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel) { extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(NSViewController)), viewDidAppear]; let _: () = msg_send![super(this, class!(NSViewController)), viewDidAppear];
} }
@ -31,7 +31,7 @@ extern fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel) {
} }
/// Called when the view controller receives a `viewWillDisappear` message. /// Called when the view controller receives a `viewWillDisappear` message.
extern fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel) { extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(NSViewController)), viewWillDisappear]; let _: () = msg_send![super(this, class!(NSViewController)), viewWillDisappear];
} }
@ -41,7 +41,7 @@ extern fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel) {
} }
/// Called when the view controller receives a `viewDidDisappear` message. /// Called when the view controller receives a `viewDidDisappear` message.
extern fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel) { extern "C" fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(NSViewController)), viewDidDisappear]; let _: () = msg_send![super(this, class!(NSViewController)), viewDidDisappear];
} }
@ -55,9 +55,9 @@ pub(crate) fn register_view_controller_class<T: ViewDelegate + 'static>(instance
load_or_register_class("NSViewController", instance.subclass_name(), |decl| unsafe { load_or_register_class("NSViewController", instance.subclass_name(), |decl| unsafe {
decl.add_ivar::<usize>(VIEW_DELEGATE_PTR); decl.add_ivar::<usize>(VIEW_DELEGATE_PTR);
decl.add_method(sel!(viewWillAppear), will_appear::<T> as extern fn(&mut Object, _)); decl.add_method(sel!(viewWillAppear), will_appear::<T> as extern "C" fn(&mut Object, _));
decl.add_method(sel!(viewDidAppear), did_appear::<T> as extern fn(&mut Object, _)); decl.add_method(sel!(viewDidAppear), did_appear::<T> as extern "C" fn(&mut Object, _));
decl.add_method(sel!(viewWillDisappear), will_disappear::<T> as extern fn(&mut Object, _)); decl.add_method(sel!(viewWillDisappear), will_disappear::<T> as extern "C" fn(&mut Object, _));
decl.add_method(sel!(viewDidDisappear), did_disappear::<T> as extern fn(&mut Object, _)); decl.add_method(sel!(viewDidDisappear), did_disappear::<T> as extern "C" fn(&mut Object, _));
}) })
} }

View file

@ -18,7 +18,7 @@ use objc::{class, msg_send, sel, sel_impl};
use crate::foundation::{id, nil, YES, NO}; use crate::foundation::{id, nil, YES, NO};
use crate::webview::traits::WebViewController; use crate::webview::traits::WebViewController;
extern fn download_delegate(this: &Object, _: Sel) -> id { extern "C" fn download_delegate(this: &Object, _: Sel) -> id {
println!("YO!"); println!("YO!");
unsafe { unsafe {
NSString::alloc(nil).init_str("") NSString::alloc(nil).init_str("")
@ -34,7 +34,7 @@ pub fn register_process_pool() -> *const Object {
let mut decl = ClassDecl::new("RSTWebViewProcessPool", superclass).unwrap(); let mut decl = ClassDecl::new("RSTWebViewProcessPool", superclass).unwrap();
//decl.add_ivar::<id>(DOWNLOAD_DELEGATE_PTR); //decl.add_ivar::<id>(DOWNLOAD_DELEGATE_PTR);
decl.add_method(sel!(_downloadDelegate), download_delegate as extern fn(&Object, _) -> id); decl.add_method(sel!(_downloadDelegate), download_delegate as extern "C" fn(&Object, _) -> id);
//PROCESS_POOL = decl.register(); //PROCESS_POOL = decl.register();
PROCESS_POOL = msg_send![decl.register(), new]; PROCESS_POOL = msg_send![decl.register(), new];