Skip to content

Commit de0071e

Browse files
committed
Fix id_retain_autoreleased test on x86
1 parent cd3b8ea commit de0071e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

objc2/tests/id_retain_autoreleased.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@ fn retain_count(obj: &Object) -> usize {
1212
fn create_data(bytes: &[u8]) -> Id<Object, Shared> {
1313
let bytes_ptr = bytes.as_ptr() as *const c_void;
1414
unsafe {
15-
// All code between the `msg_send!` and the `retain_autoreleased` must
16-
// be able to be optimized away for this to work.
15+
// let obj: *mut Object = msg_send![
16+
// class!(NSMutableData),
17+
// dataWithBytes: bytes_ptr,
18+
// length: bytes.len(),
19+
// ];
20+
//
21+
// On x86 (and perhaps others), dataWithBytes does not tail call
22+
// `autorelease` and hence the return address points into that instead
23+
// of our code, making the fast autorelease scheme fail.
24+
//
25+
// So instead, we call `autorelease` manually here.
26+
let obj: *mut Object = msg_send![class!(NSMutableData), alloc];
1727
let obj: *mut Object = msg_send![
18-
class!(NSData),
19-
dataWithBytes: bytes_ptr,
28+
obj,
29+
initWithBytes: bytes_ptr,
2030
length: bytes.len(),
2131
];
32+
let obj: *mut Object = msg_send![obj, autorelease];
33+
// All code between the `msg_send!` and the `retain_autoreleased` must
34+
// be able to be optimized away for this to work.
2235
Id::retain_autoreleased(obj).unwrap()
2336
}
2437
}

0 commit comments

Comments
 (0)