@@ -300,6 +300,7 @@ impl UnwindSafe for Ivar {}
300300impl RefUnwindSafe for Ivar { }
301301
302302impl Ivar {
303+ #[ inline]
303304 pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_ivar {
304305 let ptr: * const Self = self ;
305306 ptr. cast ( )
@@ -381,18 +382,21 @@ impl UnwindSafe for Method {}
381382impl RefUnwindSafe for Method { }
382383
383384impl Method {
385+ #[ inline]
384386 pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_method {
385387 let ptr: * const Self = self ;
386388 ptr. cast ( )
387389 }
388390
389391 // Note: We don't take `&mut` here, since the operations on methods work
390392 // atomically.
393+ #[ inline]
391394 pub ( crate ) fn as_mut_ptr ( & self ) -> * mut ffi:: objc_method {
392395 self . as_ptr ( ) as _
393396 }
394397
395398 /// Returns the name of self.
399+ #[ inline]
396400 #[ doc( alias = "method_getName" ) ]
397401 pub fn name ( & self ) -> Sel {
398402 unsafe { Sel :: from_ptr ( ffi:: method_getName ( self . as_ptr ( ) ) ) . unwrap ( ) }
@@ -446,6 +450,7 @@ impl Method {
446450 }
447451
448452 /// Returns the number of arguments accepted by self.
453+ #[ inline]
449454 #[ doc( alias = "method_getNumberOfArguments" ) ]
450455 pub fn arguments_count ( & self ) -> usize {
451456 unsafe { ffi:: method_getNumberOfArguments ( self . as_ptr ( ) ) as usize }
@@ -483,7 +488,6 @@ impl Method {
483488 ///
484489 /// A common mistake would be expecting e.g. a pointer to not be null,
485490 /// where the null case was handled before.
486- #[ inline]
487491 #[ doc( alias = "method_setImplementation" ) ]
488492 pub unsafe fn set_implementation ( & self , imp : Imp ) -> Imp {
489493 // SAFETY: The new impl is not NULL, and the rest is upheld by the
@@ -574,6 +578,7 @@ impl RefUnwindSafe for AnyClass {}
574578// Note that Unpin is not applicable.
575579
576580impl AnyClass {
581+ #[ inline]
577582 pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_class {
578583 let ptr: * const Self = self ;
579584 ptr. cast ( )
@@ -603,6 +608,7 @@ impl AnyClass {
603608 }
604609
605610 /// Returns the total number of registered classes.
611+ #[ inline]
606612 #[ doc( alias = "objc_getClassList" ) ]
607613 pub fn classes_count ( ) -> usize {
608614 unsafe { ffi:: objc_getClassList ( ptr:: null_mut ( ) , 0 ) as usize }
@@ -713,17 +719,6 @@ impl AnyClass {
713719 }
714720 }
715721
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-
727722 #[ allow( unused) ]
728723 #[ doc( alias = "class_getClassVariable" ) ]
729724 fn class_variable ( & self , name : & str ) -> Option < & Ivar > {
@@ -745,6 +740,7 @@ impl AnyClass {
745740 }
746741
747742 /// Checks whether this class conforms to the specified protocol.
743+ #[ inline]
748744 #[ doc( alias = "class_conformsToProtocol" ) ]
749745 pub fn conforms_to ( & self , proto : & AnyProtocol ) -> bool {
750746 unsafe {
@@ -798,7 +794,6 @@ impl AnyClass {
798794 // fn properties(&self) -> Malloc<[&Property]>;
799795 // unsafe fn replace_method(&self, name: Sel, imp: Imp, types: &str) -> Imp;
800796 // unsafe fn replace_property(&self, name: &str, attributes: &[ffi::objc_property_attribute_t]);
801- // unsafe fn set_ivar_layout(&mut self, layout: &[u8]);
802797 // fn method_imp(&self, name: Sel) -> Imp; // + _stret
803798
804799 // fn get_version(&self) -> u32;
@@ -873,6 +868,7 @@ impl RefUnwindSafe for AnyProtocol {}
873868// Note that Unpin is not applicable.
874869
875870impl AnyProtocol {
871+ #[ inline]
876872 pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_protocol {
877873 let ptr: * const Self = self ;
878874 ptr. cast ( )
@@ -913,6 +909,7 @@ impl AnyProtocol {
913909 }
914910
915911 /// Checks whether this protocol conforms to the specified protocol.
912+ #[ inline]
916913 #[ doc( alias = "protocol_conformsToProtocol" ) ]
917914 pub fn conforms_to ( & self , proto : & AnyProtocol ) -> bool {
918915 unsafe {
@@ -1057,16 +1054,20 @@ unsafe impl RefEncode for AnyObject {
10571054unsafe impl Message for AnyObject { }
10581055
10591056impl AnyObject {
1057+ #[ inline]
10601058 pub ( crate ) fn as_ptr ( & self ) -> * const ffi:: objc_object {
10611059 let ptr: * const Self = self ;
10621060 ptr. cast ( )
10631061 }
10641062
10651063 /// Dynamically find the class of this object.
1064+ #[ inline]
10661065 #[ doc( alias = "object_getClass" ) ]
1067- pub fn class ( & self ) -> & AnyClass {
1066+ pub fn class ( & self ) -> & ' static AnyClass {
10681067 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.
10701071 unsafe { ptr. as_ref ( ) . unwrap_unchecked ( ) }
10711072 }
10721073
@@ -1285,7 +1286,7 @@ mod tests {
12851286 use super :: * ;
12861287 use crate :: runtime:: MessageReceiver ;
12871288 use crate :: test_utils;
1288- use crate :: { msg_send, sel} ;
1289+ use crate :: { class , msg_send, sel} ;
12891290
12901291 #[ test]
12911292 fn test_selector ( ) {
@@ -1576,4 +1577,22 @@ mod tests {
15761577 assert_eq ! ( size_of:: <Ivar >( ) , 0 ) ;
15771578 assert_eq ! ( size_of:: <Method >( ) , 0 ) ;
15781579 }
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+ }
15791598}
0 commit comments