@@ -11,13 +11,26 @@ fn retain_count(obj: &Object) -> usize {
11
11
fn create_data ( bytes : & [ u8 ] ) -> Id < Object , Shared > {
12
12
let bytes_ptr = bytes. as_ptr ( ) as * const c_void ;
13
13
unsafe {
14
- // All code between the `msg_send!` and the `retain_autoreleased` must
15
- // be able to be optimized away for this to work.
14
+ // let obj: *mut Object = msg_send![
15
+ // class!(NSMutableData),
16
+ // dataWithBytes: bytes_ptr,
17
+ // length: bytes.len(),
18
+ // ];
19
+ //
20
+ // On x86 (and perhaps others), dataWithBytes does not tail call
21
+ // `autorelease` and hence the return address points into that instead
22
+ // of our code, making the fast autorelease scheme fail.
23
+ //
24
+ // So instead, we call `autorelease` manually here.
25
+ let obj: * mut Object = msg_send ! [ class!( NSMutableData ) , alloc] ;
16
26
let obj: * mut Object = msg_send ! [
17
- class! ( NSData ) ,
18
- dataWithBytes : bytes_ptr,
27
+ obj ,
28
+ initWithBytes : bytes_ptr,
19
29
length: bytes. len( ) ,
20
30
] ;
31
+ let obj: * mut Object = msg_send ! [ obj, autorelease] ;
32
+ // All code between the `msg_send!` and the `retain_autoreleased` must
33
+ // be able to be optimized away for this to work.
21
34
Id :: retain_autoreleased ( obj) . unwrap ( )
22
35
}
23
36
}
0 commit comments