2011-02-26 13:10:49 +00:00
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
|
2011-02-26 21:42:20 +00:00
|
|
|
/* Declare the block copy functions ourself so that we don't depend on a
|
|
|
|
* specific header location.
|
|
|
|
*/
|
2011-02-26 13:10:49 +00:00
|
|
|
void *_Block_copy(void *);
|
|
|
|
void _Block_release(void *);
|
|
|
|
|
|
|
|
@interface GSBlock : NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSBlock
|
2011-02-26 21:42:20 +00:00
|
|
|
+ (void) load
|
2011-02-26 13:10:49 +00:00
|
|
|
{
|
2011-02-26 21:42:20 +00:00
|
|
|
unsigned int methodCount;
|
|
|
|
Method *m = NULL;
|
|
|
|
Method *methods = class_copyMethodList(self, &methodCount);
|
|
|
|
id blockClass = objc_lookUpClass("_NSBlock");
|
|
|
|
Protocol *nscopying = NULL;
|
|
|
|
|
|
|
|
/* If we don't have an _NSBlock class, we don't have blocks support in the
|
|
|
|
* runtime, so give up.
|
|
|
|
*/
|
|
|
|
if (nil == blockClass)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy all of the methods in this class onto the block-runtime-provided
|
|
|
|
* _NSBlock
|
|
|
|
*/
|
|
|
|
for (m = methods; NULL != *m; m++)
|
|
|
|
{
|
|
|
|
class_addMethod(blockClass, method_getName(*m),
|
|
|
|
method_getImplementation(*m), method_getTypeEncoding(*m));
|
|
|
|
}
|
|
|
|
nscopying = objc_getProtocol("NSCopying");
|
|
|
|
class_addProtocol(blockClass, nscopying);
|
2011-02-26 13:10:49 +00:00
|
|
|
}
|
2011-02-26 21:42:20 +00:00
|
|
|
|
|
|
|
- (id) copyWithZone: (NSZone*)aZone
|
2011-02-26 13:10:49 +00:00
|
|
|
{
|
2011-02-26 21:42:20 +00:00
|
|
|
return _Block_copy(self);
|
2011-02-26 13:10:49 +00:00
|
|
|
}
|
2011-02-26 21:42:20 +00:00
|
|
|
|
|
|
|
- (id) copy
|
2011-02-26 13:10:49 +00:00
|
|
|
{
|
2011-02-26 21:42:20 +00:00
|
|
|
return _Block_copy(self);
|
2011-02-26 13:10:49 +00:00
|
|
|
}
|
2011-02-26 21:42:20 +00:00
|
|
|
|
|
|
|
- (id) retain
|
2011-02-26 13:10:49 +00:00
|
|
|
{
|
2011-02-26 21:42:20 +00:00
|
|
|
return _Block_copy(self);
|
2011-02-26 13:10:49 +00:00
|
|
|
}
|
2011-02-26 21:42:20 +00:00
|
|
|
|
|
|
|
- (void) release
|
2011-02-26 13:10:49 +00:00
|
|
|
{
|
2011-02-26 21:42:20 +00:00
|
|
|
_Block_release(self);
|
2011-02-26 13:10:49 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|