quakeforge/ruamoko/lib/AutoreleasePool.r
Bill Currie 75ec6bf244 Clean out some unnecessary types from the progs engine and clean up the mess.
This is a nasty commit, sorry, but 99% of the commit is interdependent.
2011-01-10 12:25:31 +09:00

61 lines
944 B
R

#include "AutoreleasePool.h"
#include "Array+Private.h"
#include "Array.h"
#include "Array+Private.h"
@static Array[] poolStack;
@implementation AutoreleasePool
- (id) init
{
if (!(self = [super init]))
return NIL;
if (!poolStack)
poolStack = [[Array alloc] initWithCapacity: 1];
[poolStack addObjectNoRetain: self];
array = [Array new];
return self;
}
+ (void) addObject: (id)anObject
{
if (!poolStack || [poolStack count])
[[AutoreleasePool alloc] init];
[[poolStack lastObject] addObject: anObject];
}
- (void) addObject: (id)anObject
{
[array addObjectNoRetain: anObject];
}
- (id) retain
{
[self error: "Don't send -retain to an autorelease pool."];
}
- (id) autorelease
{
[self error: "Don't send -autorelease to an autorelease pool."];
}
- (void) dealloc
{
[array release];
[poolStack removeObjectNoRelease: self];
[super dealloc];
}
@end
void
ARP_FreeAllPools (void)
{
[poolStack removeAllObjects];
}