libs-base/Source/GSBlocks.m
theraven 9234b0af72 Fixed C99ism.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32381 72102866-910b-0410-8b05-ffd578937521
2011-02-26 19:23:26 +00:00

51 lines
1.1 KiB
Objective-C

#import <Foundation/NSObject.h>
// Declare the block copy functions ourself so that we don't depend on a
// specific header location.
void *_Block_copy(void *);
void _Block_release(void *);
@interface GSBlock : NSObject
@end
@implementation GSBlock
+ (void)load
{
unsigned int methodCount;
Method *m = methods = NULL;
Method *methods =
class_copyMethodList(self, &methodCount);
id blockClass = objc_lookUpClass("_NSBlock");
// 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));
}
Protocol *nscopying = objc_getProtocol("NSCopying");
class_addProtocol(blockClass, nscopying);
}
- (id)copyWithZone: (NSZone*)aZone
{
return Block_copy(self);
}
- (id)copy
{
return Block_copy(self);
}
- (id)retain
{
return Block_copy(self);
}
- (void)release
{
Block_release(self);
}
@end