Skip to content

Commit 2434641

Browse files
committed
Add note about instance variable layouts being unused
1 parent 045c53f commit 2434641

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

crates/objc2/src/declare/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ impl ClassBuilder {
419419

420420
let c_name = CString::new(name).unwrap();
421421
let encoding = CString::new(encoding.to_string()).unwrap();
422+
423+
// Note: The Objective-C runtime contains functionality to do stuff
424+
// with "instance variable layouts", but we don't have to touch any of
425+
// that, it was only used in the garbage-collecting runtime.
422426
let success = Bool::from_raw(unsafe {
423427
ffi::class_addIvar(
424428
self.as_mut_ptr(),

crates/objc2/src/runtime/mod.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -713,17 +713,6 @@ impl AnyClass {
713713
}
714714
}
715715

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-
727716
#[allow(unused)]
728717
#[doc(alias = "class_getClassVariable")]
729718
fn class_variable(&self, name: &str) -> Option<&Ivar> {
@@ -798,7 +787,6 @@ impl AnyClass {
798787
// fn properties(&self) -> Malloc<[&Property]>;
799788
// unsafe fn replace_method(&self, name: Sel, imp: Imp, types: &str) -> Imp;
800789
// unsafe fn replace_property(&self, name: &str, attributes: &[ffi::objc_property_attribute_t]);
801-
// unsafe fn set_ivar_layout(&mut self, layout: &[u8]);
802790
// fn method_imp(&self, name: Sel) -> Imp; // + _stret
803791

804792
// fn get_version(&self) -> u32;
@@ -1285,7 +1273,7 @@ mod tests {
12851273
use super::*;
12861274
use crate::runtime::MessageReceiver;
12871275
use crate::test_utils;
1288-
use crate::{msg_send, sel};
1276+
use crate::{class, msg_send, sel};
12891277

12901278
#[test]
12911279
fn test_selector() {
@@ -1576,4 +1564,22 @@ mod tests {
15761564
assert_eq!(size_of::<Ivar>(), 0);
15771565
assert_eq!(size_of::<Method>(), 0);
15781566
}
1567+
1568+
fn get_ivar_layout(cls: &AnyClass) -> *const u8 {
1569+
let cls: *const AnyClass = cls;
1570+
unsafe { ffi::class_getIvarLayout(cls.cast()) }
1571+
}
1572+
1573+
#[test]
1574+
#[cfg_attr(
1575+
feature = "gnustep-1-7",
1576+
ignore = "ivar layout is still used on GNUStep"
1577+
)]
1578+
fn test_layout_does_not_matter_any_longer() {
1579+
assert!(get_ivar_layout(class!(NSObject)).is_null());
1580+
assert!(get_ivar_layout(class!(NSArray)).is_null());
1581+
assert!(get_ivar_layout(class!(NSException)).is_null());
1582+
assert!(get_ivar_layout(class!(NSNumber)).is_null());
1583+
assert!(get_ivar_layout(class!(NSString)).is_null());
1584+
}
15791585
}

0 commit comments

Comments
 (0)