@@ -11,13 +11,26 @@ fn retain_count(obj: &Object) -> usize {
1111fn create_data ( bytes : & [ u8 ] ) -> Id < Object , Shared > {
1212 let bytes_ptr = bytes. as_ptr ( ) as * const c_void ;
1313 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] ;
1626 let obj: * mut Object = msg_send ! [
17- class! ( NSData ) ,
18- dataWithBytes : bytes_ptr,
27+ obj ,
28+ initWithBytes : bytes_ptr,
1929 length: bytes. len( ) ,
2030 ] ;
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.
2134 Id :: retain_autoreleased ( obj) . unwrap ( )
2235 }
2336}
0 commit comments