1
1
use std:: marker:: PhantomFn ;
2
2
use std:: mem;
3
3
4
- use runtime:: { Class , Method , Object , Sel , Super , self } ;
5
- use { encode, Encode } ;
4
+ use runtime:: { Class , Object , Sel , Super , self } ;
6
5
7
6
/*
8
7
The Sized bound on Message is unfortunate; ideally, objc objects would not be
@@ -126,85 +125,12 @@ message_args_impl!(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J);
126
125
message_args_impl ! ( a: A , b: B , c: C , d: D , e: E , f: F , g: G , h: H , i: I , j: J , k: K ) ;
127
126
message_args_impl ! ( a: A , b: B , c: C , d: D , e: E , f: F , g: G , h: H , i: I , j: J , k: K , l: L ) ;
128
127
129
- #[ allow( dead_code) ]
130
- fn verify_message_arguments ( types : & [ & str ] , method : & Method ) -> Result < ( ) , String > {
131
- let count = 2 + types. len ( ) ;
132
- let expected_count = method. arguments_count ( ) ;
133
- if count != expected_count {
134
- return Err ( format ! ( "Method {:?} accepts {} arguments, but {} were given" ,
135
- method. name( ) , expected_count, count) ) ;
136
- }
137
-
138
- let expected_types = ( 2 ..expected_count) . map ( |i| method. argument_type ( i) ) ;
139
- for ( & arg, expected) in types. iter ( ) . zip ( expected_types) {
140
- let expected = match expected {
141
- Some ( s) => s,
142
- None => return Err ( format ! ( "Method {:?} doesn't expect argument with type code {}" ,
143
- method. name( ) , arg) ) ,
144
- } ;
145
- if arg != & * expected {
146
- return Err ( format ! ( "Method {:?} expected argument with type code {} but was given {}" ,
147
- method. name( ) , & * expected, arg) ) ;
148
- }
149
- }
150
-
151
- Ok ( ( ) )
152
- }
153
-
154
- #[ allow( dead_code) ]
155
- fn verify_message_signature < A , R > ( cls : & Class , sel : Sel ) -> Result < ( ) , String >
156
- where A : MessageArguments , R : Encode {
157
- let method = match cls. instance_method ( sel) {
158
- Some ( method) => method,
159
- None => return Err ( format ! ( "Method {:?} not found on class {:?}" ,
160
- sel, cls) ) ,
161
- } ;
162
-
163
- let ret = encode :: < R > ( ) ;
164
- let expected_ret = method. return_type ( ) ;
165
- // Allow encoding "oneway void" (Vv) as "void" (v)
166
- if & * expected_ret != ret && !( & * expected_ret == "Vv" && ret == "v" ) {
167
- return Err ( format ! ( "Return type code {} does not match expected {} for method {:?} on class {:?}" ,
168
- ret, & * expected_ret, sel, cls) ) ;
169
- }
170
-
171
- // I don't think either of these can happen, but just to be safe...
172
- let accepts_self_arg = match method. argument_type ( 0 ) {
173
- Some ( s) => & * s == "@" ,
174
- None => false ,
175
- } ;
176
- if !accepts_self_arg {
177
- return Err ( format ! ( "Method {:?} of class {:?} doesn't accept an argument for self" ,
178
- sel, cls) ) ;
179
- }
180
- let accepts_cmd_arg = match method. argument_type ( 1 ) {
181
- Some ( s) => & * s == ":" ,
182
- None => false ,
183
- } ;
184
- if !accepts_cmd_arg {
185
- return Err ( format ! ( "Method {:?} of class {:?} doesn't accept an argument for the selector" ,
186
- sel, cls) ) ;
187
- }
188
-
189
- Ok ( ( ) )
190
- }
191
-
192
- #[ cfg( any( ndebug, not( feature = "verify_message_encode" ) ) ) ]
193
- pub unsafe fn send_message < T , A , R > ( obj : & T , sel : Sel , args : A ) -> R
194
- where T : ToMessage , A : MessageArguments {
195
- args. send ( obj, sel)
196
- }
197
-
198
128
/**
199
129
Sends a message to an object with selector `sel` and arguments `args`.
200
130
This function will choose the correct version of `objc_msgSend` based on the
201
131
return type. For more information, see Apple's documenation:
202
132
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html#//apple_ref/doc/uid/TP40001418-CH1g-88778
203
133
204
- When the verify_message_encode feature is defined, at runtime in debug
205
- builds this function will verify that the encoding of the return type
206
- matches the encoding of the method.
207
-
208
134
# Example
209
135
``` no_run
210
136
# #[macro_use] extern crate objc;
@@ -222,39 +148,16 @@ let _: () = send_message(&dict, sel!(setObject:forKey:), (obj, key));
222
148
# }
223
149
```
224
150
*/
225
- #[ cfg( all( not( ndebug) , feature = "verify_message_encode" ) ) ]
226
151
pub unsafe fn send_message < T , A , R > ( obj : & T , sel : Sel , args : A ) -> R
227
- where T : ToMessage , A : MessageArguments , R : Encode {
228
- let cls = if obj. is_nil ( ) {
229
- panic ! ( "Messaging {:?} to nil" , sel)
230
- } else {
231
- ( * obj. as_id_ptr ( ) ) . class ( )
232
- } ;
233
- match verify_message_signature :: < A , R > ( cls, sel) {
234
- Err ( s) => panic ! ( "Verify message failed: {}" , s) ,
235
- Ok ( _) => args. send ( obj, sel) ,
236
- }
237
- }
238
-
239
- #[ cfg( any( ndebug, not( feature = "verify_message_encode" ) ) ) ]
240
- pub unsafe fn send_super_message < T , A , R > (
241
- obj : & T , superclass : & Class , sel : Sel , args : A ) -> R
242
152
where T : ToMessage , A : MessageArguments {
243
- args. send_super ( obj, superclass , sel)
153
+ args. send ( obj, sel)
244
154
}
245
155
246
156
/// Sends a message to the superclass of an instance of a class.
247
- #[ cfg( all( not( ndebug) , feature = "verify_message_encode" ) ) ]
248
157
pub unsafe fn send_super_message < T , A , R > (
249
158
obj : & T , superclass : & Class , sel : Sel , args : A ) -> R
250
- where T : ToMessage , A : MessageArguments , R : Encode {
251
- if obj. is_nil ( ) {
252
- panic ! ( "Messaging {:?} to nil" , sel) ;
253
- }
254
- match verify_message_signature :: < A , R > ( superclass, sel) {
255
- Err ( s) => panic ! ( "Verify message failed: {}" , s) ,
256
- Ok ( _) => args. send_super ( obj, superclass, sel) ,
257
- }
159
+ where T : ToMessage , A : MessageArguments {
160
+ args. send_super ( obj, superclass, sel)
258
161
}
259
162
260
163
#[ cfg( test) ]
0 commit comments