Skip to content

Commit 51139b9

Browse files
committed
Removed message verify.
1 parent 72c86e7 commit 51139b9

File tree

2 files changed

+4
-105
lines changed

2 files changed

+4
-105
lines changed

core/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ license = "MIT"
1212
name = "objc"
1313
path = "lib.rs"
1414

15-
[features]
16-
verify_message_encode = []
17-
default = ["verify_message_encode"]
18-
1915
[dependencies]
2016
libc = "0.1"
2117
malloc_buf = "0.0"

core/message.rs

+4-101
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::marker::PhantomFn;
22
use std::mem;
33

4-
use runtime::{Class, Method, Object, Sel, Super, self};
5-
use {encode, Encode};
4+
use runtime::{Class, Object, Sel, Super, self};
65

76
/*
87
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);
126125
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);
127126
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);
128127

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-
198128
/**
199129
Sends a message to an object with selector `sel` and arguments `args`.
200130
This function will choose the correct version of `objc_msgSend` based on the
201131
return type. For more information, see Apple's documenation:
202132
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html#//apple_ref/doc/uid/TP40001418-CH1g-88778
203133
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-
208134
# Example
209135
``` no_run
210136
# #[macro_use] extern crate objc;
@@ -222,39 +148,16 @@ let _: () = send_message(&dict, sel!(setObject:forKey:), (obj, key));
222148
# }
223149
```
224150
*/
225-
#[cfg(all(not(ndebug), feature = "verify_message_encode"))]
226151
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
242152
where T: ToMessage, A: MessageArguments {
243-
args.send_super(obj, superclass, sel)
153+
args.send(obj, sel)
244154
}
245155

246156
/// Sends a message to the superclass of an instance of a class.
247-
#[cfg(all(not(ndebug), feature = "verify_message_encode"))]
248157
pub unsafe fn send_super_message<T, A, R>(
249158
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)
258161
}
259162

260163
#[cfg(test)]

0 commit comments

Comments
 (0)