- Fix PNInstallation
This commit is contained in:
1 parent
1df32f64a7
commit
7752bf3e18
51 files changed
+14486
-12301
No files matched your search
Generated
+13
@@ -0,0 +1,13 @@
|
||||
// JRSwizzle.h semver:1.0
|
||||
// Copyright (c) 2007-2011 Jonathan 'Wolf' Rentzsch: http://rentzsch.com
|
||||
// Some rights reserved: http://opensource.org/licenses/MIT
|
||||
// https://github.com/rentzsch/jrswizzle
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSObject (JRSwizzle)
|
||||
|
||||
+ (BOOL)jr_swizzleMethod:(SEL)origSel_ withMethod:(SEL)altSel_ error:(NSError**)error_;
|
||||
+ (BOOL)jr_swizzleClassMethod:(SEL)origSel_ withClassMethod:(SEL)altSel_ error:(NSError**)error_;
|
||||
|
||||
@end
|
||||
Generated
+134
@@ -0,0 +1,134 @@
|
||||
// JRSwizzle.m semver:1.0
|
||||
// Copyright (c) 2007-2011 Jonathan 'Wolf' Rentzsch: http://rentzsch.com
|
||||
// Some rights reserved: http://opensource.org/licenses/MIT
|
||||
// https://github.com/rentzsch/jrswizzle
|
||||
|
||||
#import "JRSwizzle.h"
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#import <objc/runtime.h>
|
||||
#import <objc/message.h>
|
||||
#else
|
||||
#import <objc/objc-class.h>
|
||||
#endif
|
||||
|
||||
#define SetNSErrorFor(FUNC, ERROR_VAR, FORMAT,...) \
|
||||
if (ERROR_VAR) { \
|
||||
NSString *errStr = [NSString stringWithFormat:@"%s: " FORMAT,FUNC,##__VA_ARGS__]; \
|
||||
*ERROR_VAR = [NSError errorWithDomain:@"NSCocoaErrorDomain" \
|
||||
code:-1 \
|
||||
userInfo:[NSDictionary dictionaryWithObject:errStr forKey:NSLocalizedDescriptionKey]]; \
|
||||
}
|
||||
#define SetNSError(ERROR_VAR, FORMAT,...) SetNSErrorFor(__func__, ERROR_VAR, FORMAT, ##__VA_ARGS__)
|
||||
|
||||
#if OBJC_API_VERSION >= 2
|
||||
#define GetClass(obj) object_getClass(obj)
|
||||
#else
|
||||
#define GetClass(obj) (obj ? obj->isa : Nil)
|
||||
#endif
|
||||
|
||||
@implementation NSObject (JRSwizzle)
|
||||
|
||||
+ (BOOL)jr_swizzleMethod:(SEL)origSel_ withMethod:(SEL)altSel_ error:(NSError**)error_ {
|
||||
#if OBJC_API_VERSION >= 2
|
||||
Method origMethod = class_getInstanceMethod(self, origSel_);
|
||||
if (!origMethod) {
|
||||
#if TARGET_OS_IPHONE
|
||||
SetNSError(error_, @"original method %@ not found for class %@", NSStringFromSelector(origSel_), [self class]);
|
||||
#else
|
||||
SetNSError(error_, @"original method %@ not found for class %@", NSStringFromSelector(origSel_), [self className]);
|
||||
#endif
|
||||
return NO;
|
||||
}
|
||||
|
||||
Method altMethod = class_getInstanceMethod(self, altSel_);
|
||||
if (!altMethod) {
|
||||
#if TARGET_OS_IPHONE
|
||||
SetNSError(error_, @"alternate method %@ not found for class %@", NSStringFromSelector(altSel_), [self class]);
|
||||
#else
|
||||
SetNSError(error_, @"alternate method %@ not found for class %@", NSStringFromSelector(altSel_), [self className]);
|
||||
#endif
|
||||
return NO;
|
||||
}
|
||||
|
||||
class_addMethod(self,
|
||||
origSel_,
|
||||
class_getMethodImplementation(self, origSel_),
|
||||
method_getTypeEncoding(origMethod));
|
||||
class_addMethod(self,
|
||||
altSel_,
|
||||
class_getMethodImplementation(self, altSel_),
|
||||
method_getTypeEncoding(altMethod));
|
||||
|
||||
method_exchangeImplementations(class_getInstanceMethod(self, origSel_), class_getInstanceMethod(self, altSel_));
|
||||
return YES;
|
||||
#else
|
||||
// Scan for non-inherited methods.
|
||||
Method directOriginalMethod = NULL, directAlternateMethod = NULL;
|
||||
|
||||
void *iterator = NULL;
|
||||
struct objc_method_list *mlist = class_nextMethodList(self, &iterator);
|
||||
while (mlist) {
|
||||
int method_index = 0;
|
||||
for (; method_index < mlist->method_count; method_index++) {
|
||||
if (mlist->method_list[method_index].method_name == origSel_) {
|
||||
assert(!directOriginalMethod);
|
||||
directOriginalMethod = &mlist->method_list[method_index];
|
||||
}
|
||||
if (mlist->method_list[method_index].method_name == altSel_) {
|
||||
assert(!directAlternateMethod);
|
||||
directAlternateMethod = &mlist->method_list[method_index];
|
||||
}
|
||||
}
|
||||
mlist = class_nextMethodList(self, &iterator);
|
||||
}
|
||||
|
||||
// If either method is inherited, copy it up to the target class to make it non-inherited.
|
||||
if (!directOriginalMethod || !directAlternateMethod) {
|
||||
Method inheritedOriginalMethod = NULL, inheritedAlternateMethod = NULL;
|
||||
if (!directOriginalMethod) {
|
||||
inheritedOriginalMethod = class_getInstanceMethod(self, origSel_);
|
||||
if (!inheritedOriginalMethod) {
|
||||
SetNSError(error_, @"original method %@ not found for class %@", NSStringFromSelector(origSel_), [self className]);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
if (!directAlternateMethod) {
|
||||
inheritedAlternateMethod = class_getInstanceMethod(self, altSel_);
|
||||
if (!inheritedAlternateMethod) {
|
||||
SetNSError(error_, @"alternate method %@ not found for class %@", NSStringFromSelector(altSel_), [self className]);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
int hoisted_method_count = !directOriginalMethod && !directAlternateMethod ? 2 : 1;
|
||||
struct objc_method_list *hoisted_method_list = malloc(sizeof(struct objc_method_list) + (sizeof(struct objc_method)*(hoisted_method_count-1)));
|
||||
hoisted_method_list->obsolete = NULL; // soothe valgrind - apparently ObjC runtime accesses this value and it shows as uninitialized in valgrind
|
||||
hoisted_method_list->method_count = hoisted_method_count;
|
||||
Method hoisted_method = hoisted_method_list->method_list;
|
||||
|
||||
if (!directOriginalMethod) {
|
||||
bcopy(inheritedOriginalMethod, hoisted_method, sizeof(struct objc_method));
|
||||
directOriginalMethod = hoisted_method++;
|
||||
}
|
||||
if (!directAlternateMethod) {
|
||||
bcopy(inheritedAlternateMethod, hoisted_method, sizeof(struct objc_method));
|
||||
directAlternateMethod = hoisted_method;
|
||||
}
|
||||
class_addMethods(self, hoisted_method_list);
|
||||
}
|
||||
|
||||
// Swizzle.
|
||||
IMP temp = directOriginalMethod->method_imp;
|
||||
directOriginalMethod->method_imp = directAlternateMethod->method_imp;
|
||||
directAlternateMethod->method_imp = temp;
|
||||
|
||||
return YES;
|
||||
#endif
|
||||
}
|
||||
|
||||
+ (BOOL)jr_swizzleClassMethod:(SEL)origSel_ withClassMethod:(SEL)altSel_ error:(NSError**)error_ {
|
||||
return [GetClass((id)self) jr_swizzleMethod:origSel_ withMethod:altSel_ error:error_];
|
||||
}
|
||||
|
||||
@end
|
||||
Generated
+151
@@ -0,0 +1,151 @@
|
||||
# JRSwizzle
|
||||
|
||||
## Description
|
||||
|
||||
JRSwizzle is source code package that offers a single, easy, correct+consistent interface for exchanging Objective-C method implementations ("method swizzling") across many versions of Mac OS X, iOS, Objective-C and runtime architectures.
|
||||
|
||||
More succinctly: *JRSwizzle wants to be your one-stop-shop for all your method swizzling needs.*
|
||||
|
||||
## Download
|
||||
|
||||
$ cd /path/to/top/of/your/project
|
||||
$ git submodule add git://github.com/rentzsch/jrswizzle.git JRSwizzle
|
||||
$ git submodule init && git submodule update
|
||||
|
||||
# OPTIONAL: Execute the following commands if you want to explicitly peg
|
||||
# to a certain version. Otherwise `git submodule update` will keep you
|
||||
# current with HEAD.
|
||||
|
||||
$ cd JRSwizzle
|
||||
$ git checkout v1.0
|
||||
|
||||
## Reasons for Existence
|
||||
|
||||
* **Easy:** Just do this: `[SomeClass jr_swizzle:@selector(foo) withMethod:@selector(my_foo) error:&error];` Voila.
|
||||
* **Correct:** There's a subtle interaction between method swizzling and method inheritance. Following in Kevin Ballard's footsteps, this package Does The Right Thing.
|
||||
* **Compatible:** JRSwizzle should Just Work on any version of Mac OS X and iOS you care about. Here's the exhaustive compatibility list:
|
||||
* Mac OS X v10.3/ppc (Ballard implementation)
|
||||
* Mac OS X v10.4/ppc (Ballard implementation)
|
||||
* Mac OS X v10.4/i386 (Ballard implementation)
|
||||
* Mac OS X v10.5/ppc (method_exchangeImplementations+Ballard implementation)
|
||||
* Mac OS X v10.5/i386 (method_exchangeImplementations+Ballard implementation)
|
||||
* Mac OS X v10.5/ppc64 (method_exchangeImplementations+Ballard implementation)
|
||||
* Mac OS X v10.5/x86_64 (method_exchangeImplementations+Ballard implementation)
|
||||
* iOS 2.0+ (method_exchangeImplementations+Ballard implementation)
|
||||
* **Robust:** All parameters are checked and JRSwizzle returns an optional `NSError` with high-quality diagnostics.
|
||||
|
||||
## Support
|
||||
|
||||
Please use [JRSwizzle's GitHub Issues tab](https://github.com/rentzsch/jrswizzle/issues) to [file bugs or feature requests](https://github.com/rentzsch/jrswizzle/issues/new).
|
||||
|
||||
To contribute, please fork this project, make+commit your changes and then send me a pull request.
|
||||
|
||||
## Comparison
|
||||
|
||||
There's at least four swizzling implementations floating around. Here's a comparison chart to help you make sense of how they relate to each other and why JRSwizzle exists.
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Scenario</th>
|
||||
<th>Swizzle Technology</th>
|
||||
<th>Method Implementation</th>
|
||||
<th>Correct Behavior</th>
|
||||
<th>10.4</th>
|
||||
<th>64-bit</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>Classic</td>
|
||||
<td>Direct</td>
|
||||
<td>YES</td>
|
||||
<td>YES</td>
|
||||
<td>NO</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>Classic</td>
|
||||
<td>Inherited</td>
|
||||
<td>NO</td>
|
||||
<td>YES</td>
|
||||
<td>NO</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>Ballard</td>
|
||||
<td>Direct</td>
|
||||
<td>YES</td>
|
||||
<td>YES</td>
|
||||
<td>NO</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td>Ballard</td>
|
||||
<td>Inherited</td>
|
||||
<td>YES</td>
|
||||
<td>YES</td>
|
||||
<td>NO</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>5</td>
|
||||
<td>Apple</td>
|
||||
<td>Direct</td>
|
||||
<td>YES</td>
|
||||
<td>NO</td>
|
||||
<td>YES</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6</td>
|
||||
<td>Apple</td>
|
||||
<td>Inherited</td>
|
||||
<td>NO</td>
|
||||
<td>NO</td>
|
||||
<td>YES</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>7</td>
|
||||
<td>JRSwizzle</td>
|
||||
<td>Direct</td>
|
||||
<td>YES</td>
|
||||
<td>YES</td>
|
||||
<td>YES</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>8</td>
|
||||
<td>JRSwizzle</td>
|
||||
<td>Inherited</td>
|
||||
<td>YES</td>
|
||||
<td>YES</td>
|
||||
<td>YES</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
* *Classic* is the canonical `MethodSwizzle()` implementation as described in [CocoaDev's MethodSwizzling page](http://www.cocoadev.com/index.pl?MethodSwizzling).
|
||||
* *Ballard* is [Kevin Ballard's improved implementation](http://kevin.sb.org/2006/12/30/method-swizzling-reimplemented/) which solves the inherited method problem.
|
||||
* *Apple* is 10.5's new `method_exchangeImplementations` API.
|
||||
* *JRSwizzle* is this package.
|
||||
|
||||
## License
|
||||
|
||||
The source code is distributed under the nonviral [MIT License](http://opensource.org/licenses/mit-license.php). It's the simplest most permissive license available.
|
||||
|
||||
## Version History
|
||||
|
||||
* **v1.0:** Mar 2 2012
|
||||
|
||||
* [NEW] iOS Support. ([Anton Serebryakov](https://github.com/rentzsch/jrswizzle/commit/60ccb350a3577e55d00d3fdfee8b3c0390b8e852]))
|
||||
|
||||
* [NEW] Class method swizzling. ([outis](https://github.com/rentzsch/jrswizzle/pull/1))
|
||||
|
||||
* **v1.0d1:** May 31 2009
|
||||
|
||||
* [FIX] Soothe valgrind by nulling out `hoisted_method_list->obsolete`, which it apparently reads. ([Daniel Jalkut](http://github.com/rentzsch/jrswizzle/commit/2f677d063202b443ca7a1c46e8b67d67ea6fc88e))
|
||||
|
||||
* [FIX] Xcode 3.2 apparently now needs `ARCHS` set explicitly for 10.3 targets. ([rentzsch](http://github.com/rentzsch/jrswizzle/commit/4478faa40e4fdb322201da20f24d3996193ea48b))
|
||||
|
||||
* **v1.0d0:** Apr 09 2009
|
||||
|
||||
* Moved to github.
|
||||
|
||||
* **v1.0d0:** Dec 28 2007
|
||||
|
||||
* Under development.
|
||||
Reference in new issue
Block a user