1
- use crate :: rc:: { Id , Ownership } ;
1
+ use crate :: rc:: { Allocated , Id , Ownership } ;
2
2
use crate :: runtime:: { Class , Sel } ;
3
3
use crate :: { Message , MessageArguments , MessageReceiver } ;
4
4
@@ -68,8 +68,8 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
68
68
}
69
69
}
70
70
71
- // `alloc`, should mark the return value as "allocated, not initialized" somehow
72
- impl < T : ?Sized + Message , O : Ownership > MsgSendId < & ' _ Class , Id < T , O > >
71
+ // `alloc`
72
+ impl < T : ?Sized + Message , O : Ownership > MsgSendId < & ' _ Class , Id < Allocated < T > , O > >
73
73
for RetainSemantics < false , true , false , false >
74
74
{
75
75
#[ inline]
@@ -78,26 +78,26 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
78
78
cls : & Class ,
79
79
sel : Sel ,
80
80
args : A ,
81
- ) -> Option < Id < T , O > > {
81
+ ) -> Option < Id < Allocated < T > , O > > {
82
82
// SAFETY: Checked by caller
83
83
let obj = unsafe { MessageReceiver :: send_message ( cls, sel, args) } ;
84
84
// SAFETY: The selector is `alloc`, so this has +1 retain count
85
- unsafe { Id :: new ( obj) }
85
+ unsafe { Id :: new_allocated ( obj) }
86
86
}
87
87
}
88
88
89
- // `init`, should mark the input value as "allocated, not initialized" somehow
90
- impl < T : ?Sized + Message , O : Ownership > MsgSendId < Option < Id < T , O > > , Id < T , O > >
89
+ // `init`
90
+ impl < T : ?Sized + Message , O : Ownership > MsgSendId < Option < Id < Allocated < T > , O > > , Id < T , O > >
91
91
for RetainSemantics < false , false , true , false >
92
92
{
93
93
#[ inline]
94
94
#[ track_caller]
95
95
unsafe fn send_message_id < A : MessageArguments > (
96
- obj : Option < Id < T , O > > ,
96
+ obj : Option < Id < Allocated < T > , O > > ,
97
97
sel : Sel ,
98
98
args : A ,
99
99
) -> Option < Id < T , O > > {
100
- let ptr = Id :: option_into_ptr ( obj) ;
100
+ let ptr = Id :: option_into_ptr ( obj. map ( |obj| unsafe { Id :: assume_init ( obj ) } ) ) ;
101
101
// SAFETY: `ptr` may be null here, but that's fine since the return
102
102
// is `*mut T`, which is one of the few types where messages to nil is
103
103
// allowed.
@@ -191,7 +191,7 @@ mod tests {
191
191
192
192
use core:: ptr;
193
193
194
- use crate :: rc:: { Owned , RcTestObject , Shared , ThreadTestData } ;
194
+ use crate :: rc:: { Allocated , Owned , RcTestObject , Shared , ThreadTestData } ;
195
195
use crate :: runtime:: Object ;
196
196
use crate :: { Encoding , RefEncode } ;
197
197
@@ -200,7 +200,7 @@ mod tests {
200
200
let mut expected = ThreadTestData :: current ( ) ;
201
201
let cls = RcTestObject :: class ( ) ;
202
202
203
- let obj: Id < RcTestObject , Shared > = unsafe { msg_send_id ! [ cls, alloc] . unwrap ( ) } ;
203
+ let obj: Id < Allocated < RcTestObject > , Shared > = unsafe { msg_send_id ! [ cls, alloc] . unwrap ( ) } ;
204
204
expected. alloc += 1 ;
205
205
expected. assert_current ( ) ;
206
206
@@ -230,7 +230,7 @@ mod tests {
230
230
let cls = RcTestObject :: class ( ) ;
231
231
232
232
let zone: * const _NSZone = ptr:: null ( ) ;
233
- let _obj: Id < RcTestObject , Owned > =
233
+ let _obj: Id < Allocated < RcTestObject > , Owned > =
234
234
unsafe { msg_send_id ! [ cls, allocWithZone: zone] . unwrap ( ) } ;
235
235
// `+[NSObject alloc]` delegates to `+[NSObject allocWithZone:]`, but
236
236
// `RcTestObject` only catches `alloc`.
@@ -243,14 +243,14 @@ mod tests {
243
243
let mut expected = ThreadTestData :: current ( ) ;
244
244
let cls = RcTestObject :: class ( ) ;
245
245
246
- let obj: Option < Id < RcTestObject , Shared > > = unsafe { msg_send_id ! [ cls, alloc] } ;
246
+ let obj: Option < Id < Allocated < RcTestObject > , Shared > > = unsafe { msg_send_id ! [ cls, alloc] } ;
247
247
expected. alloc += 1 ;
248
248
// Don't check allocation error
249
249
let _obj: Id < RcTestObject , Shared > = unsafe { msg_send_id ! [ obj, init] . unwrap ( ) } ;
250
250
expected. init += 1 ;
251
251
expected. assert_current ( ) ;
252
252
253
- let obj: Option < Id < RcTestObject , Shared > > = unsafe { msg_send_id ! [ cls, alloc] } ;
253
+ let obj: Option < Id < Allocated < RcTestObject > , Shared > > = unsafe { msg_send_id ! [ cls, alloc] } ;
254
254
expected. alloc += 1 ;
255
255
// Check allocation error before init
256
256
let obj = obj. unwrap ( ) ;
0 commit comments