@@ -300,6 +300,7 @@ impl UnwindSafe for Ivar {}
300
300
impl RefUnwindSafe for Ivar { }
301
301
302
302
impl Ivar {
303
+ #[ inline]
303
304
pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_ivar {
304
305
let ptr: * const Self = self ;
305
306
ptr. cast ( )
@@ -381,18 +382,21 @@ impl UnwindSafe for Method {}
381
382
impl RefUnwindSafe for Method { }
382
383
383
384
impl Method {
385
+ #[ inline]
384
386
pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_method {
385
387
let ptr: * const Self = self ;
386
388
ptr. cast ( )
387
389
}
388
390
389
391
// Note: We don't take `&mut` here, since the operations on methods work
390
392
// atomically.
393
+ #[ inline]
391
394
pub ( crate ) fn as_mut_ptr ( & self ) -> * mut ffi:: objc_method {
392
395
self . as_ptr ( ) as _
393
396
}
394
397
395
398
/// Returns the name of self.
399
+ #[ inline]
396
400
#[ doc( alias = "method_getName" ) ]
397
401
pub fn name ( & self ) -> Sel {
398
402
unsafe { Sel :: from_ptr ( ffi:: method_getName ( self . as_ptr ( ) ) ) . unwrap ( ) }
@@ -446,6 +450,7 @@ impl Method {
446
450
}
447
451
448
452
/// Returns the number of arguments accepted by self.
453
+ #[ inline]
449
454
#[ doc( alias = "method_getNumberOfArguments" ) ]
450
455
pub fn arguments_count ( & self ) -> usize {
451
456
unsafe { ffi:: method_getNumberOfArguments ( self . as_ptr ( ) ) as usize }
@@ -483,7 +488,6 @@ impl Method {
483
488
///
484
489
/// A common mistake would be expecting e.g. a pointer to not be null,
485
490
/// where the null case was handled before.
486
- #[ inline]
487
491
#[ doc( alias = "method_setImplementation" ) ]
488
492
pub unsafe fn set_implementation ( & self , imp : Imp ) -> Imp {
489
493
// SAFETY: The new impl is not NULL, and the rest is upheld by the
@@ -574,6 +578,7 @@ impl RefUnwindSafe for AnyClass {}
574
578
// Note that Unpin is not applicable.
575
579
576
580
impl AnyClass {
581
+ #[ inline]
577
582
pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_class {
578
583
let ptr: * const Self = self ;
579
584
ptr. cast ( )
@@ -603,6 +608,7 @@ impl AnyClass {
603
608
}
604
609
605
610
/// Returns the total number of registered classes.
611
+ #[ inline]
606
612
#[ doc( alias = "objc_getClassList" ) ]
607
613
pub fn classes_count ( ) -> usize {
608
614
unsafe { ffi:: objc_getClassList ( ptr:: null_mut ( ) , 0 ) as usize }
@@ -713,17 +719,6 @@ impl AnyClass {
713
719
}
714
720
}
715
721
716
- #[ allow( unused) ]
717
- #[ doc( alias = "class_getIvarLayout" ) ]
718
- fn instance_variable_layout ( & self ) -> Option < & [ u8 ] > {
719
- let layout: * const c_char = unsafe { ffi:: class_getIvarLayout ( self . as_ptr ( ) ) . cast ( ) } ;
720
- if layout. is_null ( ) {
721
- None
722
- } else {
723
- Some ( unsafe { CStr :: from_ptr ( layout) } . to_bytes ( ) )
724
- }
725
- }
726
-
727
722
#[ allow( unused) ]
728
723
#[ doc( alias = "class_getClassVariable" ) ]
729
724
fn class_variable ( & self , name : & str ) -> Option < & Ivar > {
@@ -745,6 +740,7 @@ impl AnyClass {
745
740
}
746
741
747
742
/// Checks whether this class conforms to the specified protocol.
743
+ #[ inline]
748
744
#[ doc( alias = "class_conformsToProtocol" ) ]
749
745
pub fn conforms_to ( & self , proto : & AnyProtocol ) -> bool {
750
746
unsafe {
@@ -798,7 +794,6 @@ impl AnyClass {
798
794
// fn properties(&self) -> Malloc<[&Property]>;
799
795
// unsafe fn replace_method(&self, name: Sel, imp: Imp, types: &str) -> Imp;
800
796
// unsafe fn replace_property(&self, name: &str, attributes: &[ffi::objc_property_attribute_t]);
801
- // unsafe fn set_ivar_layout(&mut self, layout: &[u8]);
802
797
// fn method_imp(&self, name: Sel) -> Imp; // + _stret
803
798
804
799
// fn get_version(&self) -> u32;
@@ -873,6 +868,7 @@ impl RefUnwindSafe for AnyProtocol {}
873
868
// Note that Unpin is not applicable.
874
869
875
870
impl AnyProtocol {
871
+ #[ inline]
876
872
pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_protocol {
877
873
let ptr: * const Self = self ;
878
874
ptr. cast ( )
@@ -913,6 +909,7 @@ impl AnyProtocol {
913
909
}
914
910
915
911
/// Checks whether this protocol conforms to the specified protocol.
912
+ #[ inline]
916
913
#[ doc( alias = "protocol_conformsToProtocol" ) ]
917
914
pub fn conforms_to ( & self , proto : & AnyProtocol ) -> bool {
918
915
unsafe {
@@ -1057,16 +1054,20 @@ unsafe impl RefEncode for AnyObject {
1057
1054
unsafe impl Message for AnyObject { }
1058
1055
1059
1056
impl AnyObject {
1057
+ #[ inline]
1060
1058
pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_object {
1061
1059
let ptr: * const Self = self ;
1062
1060
ptr. cast ( )
1063
1061
}
1064
1062
1065
1063
/// Dynamically find the class of this object.
1064
+ #[ inline]
1066
1065
#[ doc( alias = "object_getClass" ) ]
1067
- pub fn class ( & self ) -> & AnyClass {
1066
+ pub fn class ( & self ) -> & ' static AnyClass {
1068
1067
let ptr: * const AnyClass = unsafe { ffi:: object_getClass ( self . as_ptr ( ) ) } . cast ( ) ;
1069
- // SAFETY: The class is not NULL because the object is not NULL.
1068
+ // SAFETY: The class is not NULL because the object is not NULL, and
1069
+ // it is safe as `'static` since classes are static, and it could be
1070
+ // retrieved via. `AnyClass::get(self.class().name())` anyhow.
1070
1071
unsafe { ptr. as_ref ( ) . unwrap_unchecked ( ) }
1071
1072
}
1072
1073
@@ -1285,7 +1286,7 @@ mod tests {
1285
1286
use super :: * ;
1286
1287
use crate :: runtime:: MessageReceiver ;
1287
1288
use crate :: test_utils;
1288
- use crate :: { msg_send, sel} ;
1289
+ use crate :: { class , msg_send, sel} ;
1289
1290
1290
1291
#[ test]
1291
1292
fn test_selector ( ) {
@@ -1576,4 +1577,22 @@ mod tests {
1576
1577
assert_eq ! ( size_of:: <Ivar >( ) , 0 ) ;
1577
1578
assert_eq ! ( size_of:: <Method >( ) , 0 ) ;
1578
1579
}
1580
+
1581
+ fn get_ivar_layout ( cls : & AnyClass ) -> * const u8 {
1582
+ let cls: * const AnyClass = cls;
1583
+ unsafe { ffi:: class_getIvarLayout ( cls. cast ( ) ) }
1584
+ }
1585
+
1586
+ #[ test]
1587
+ #[ cfg_attr(
1588
+ feature = "gnustep-1-7" ,
1589
+ ignore = "ivar layout is still used on GNUStep"
1590
+ ) ]
1591
+ fn test_layout_does_not_matter_any_longer ( ) {
1592
+ assert ! ( get_ivar_layout( class!( NSObject ) ) . is_null( ) ) ;
1593
+ assert ! ( get_ivar_layout( class!( NSArray ) ) . is_null( ) ) ;
1594
+ assert ! ( get_ivar_layout( class!( NSException ) ) . is_null( ) ) ;
1595
+ assert ! ( get_ivar_layout( class!( NSNumber ) ) . is_null( ) ) ;
1596
+ assert ! ( get_ivar_layout( class!( NSString ) ) . is_null( ) ) ;
1597
+ }
1579
1598
}
0 commit comments