diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2012-04-04 00:02:43 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2012-04-04 00:02:43 +0000 |
commit | 66a61fbc1c930c8e5c2655ba03d31197e04fe400 (patch) | |
tree | bb1e5938f71bfcf8e8f0092bd4924ef61aa8b5ce /Foundation | |
parent | 22eb588ba8eb86b3f3bf1367daf86cb55bd9a41a (diff) |
[Author: aharper]
Implement sel_isEqual
R=dmaclach
APPROVED=dmaclach
Diffstat (limited to 'Foundation')
-rw-r--r-- | Foundation/GTMObjC2Runtime.h | 1 | ||||
-rw-r--r-- | Foundation/GTMObjC2Runtime.m | 15 | ||||
-rw-r--r-- | Foundation/GTMObjC2RuntimeTest.m | 8 |
3 files changed, 19 insertions, 5 deletions
diff --git a/Foundation/GTMObjC2Runtime.h b/Foundation/GTMObjC2Runtime.h index da8c301..2ddde67 100644 --- a/Foundation/GTMObjC2Runtime.h +++ b/Foundation/GTMObjC2Runtime.h @@ -68,6 +68,7 @@ OBJC_EXPORT struct objc_method_description protocol_getMethodDescription(Protoco SEL aSel, BOOL isRequiredMethod, BOOL isInstanceMethod); +OBJC_EXPORT BOOL sel_isEqual(SEL lhs, SEL rhs); // If building for 10.4 but using the 10.5 SDK, don't include these. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 diff --git a/Foundation/GTMObjC2Runtime.m b/Foundation/GTMObjC2Runtime.m index 2eb5dc3..0b4614c 100644 --- a/Foundation/GTMObjC2Runtime.m +++ b/Foundation/GTMObjC2Runtime.m @@ -6,9 +6,9 @@ // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -73,7 +73,7 @@ Method *class_copyMethodList(Class cls, unsigned int *outCount) { while ( (mlist = class_nextMethodList(cls, &iterator)) ) { if (mlist->method_count == 0) continue; - methods = (Method *)realloc(methods, + methods = (Method *)realloc(methods, sizeof(Method) * (count + mlist->method_count + 1)); if (!methods) { //Memory alloc failed, so what can we do? @@ -107,7 +107,7 @@ IMP method_setImplementation(Method method, IMP imp) { // We intentionally don't test method for nil. // Leopard fails here, so should we. // I logged this as Radar: - // 5572981 method_setImplementation crashes if you pass nil for the + // 5572981 method_setImplementation crashes if you pass nil for the // method arg (arg 1) // because it seems odd that this API won't accept nil for method considering // all the other apis will accept nil args. @@ -121,7 +121,7 @@ IMP method_setImplementation(Method method, IMP imp) { if (imp) { oldImp = method->method_imp; method->method_imp = imp; - } + } return oldImp; } @@ -154,6 +154,11 @@ struct objc_method_description protocol_getMethodDescription(Protocol *p, return desc; } +BOOL sel_isEqual(SEL lhs, SEL rhs) { + // Apple (informally) promises this will work in the future: + // http://twitter.com/#!/gparker/status/2400099786 + return (lhs == rhs) ? YES : NO; +} #endif diff --git a/Foundation/GTMObjC2RuntimeTest.m b/Foundation/GTMObjC2RuntimeTest.m index 27a9aa1..2e6362c 100644 --- a/Foundation/GTMObjC2RuntimeTest.m +++ b/Foundation/GTMObjC2RuntimeTest.m @@ -434,4 +434,12 @@ AT_REQUIRED } +- (void)test_sel_isEqual { + STAssertTrue(sel_isEqual(@selector(kwyjibo), @selector(kwyjibo)), nil); + STAssertFalse(sel_isEqual(@selector(kwyjibo), @selector(dontHaveACow)), nil); + STAssertTrue(sel_isEqual(_cmd, @selector(test_sel_isEqual)), nil); + STAssertTrue(sel_isEqual(_cmd, _cmd), nil); + STAssertFalse(sel_isEqual(_cmd, @selector(kwyjibo)), nil); +} + @end |