mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix a bug in the new autorelease pool implementation when pools are destroyed in the wrong order.
Test cast by Chris Armstrong! git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35105 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f857c2928f
commit
121673c6d3
2 changed files with 57 additions and 0 deletions
|
@ -400,6 +400,14 @@ pop_pool_from_cache (struct autorelease_thread_vars *tv)
|
|||
}
|
||||
- (void) emptyPool
|
||||
{
|
||||
struct autorelease_thread_vars *tv = ARP_THREAD_VARS;
|
||||
while (_child)
|
||||
{
|
||||
NSAutoreleasePool *pool = _child;
|
||||
_child = pool->_child;
|
||||
push_pool_to_cache(tv, pool);
|
||||
}
|
||||
tv->current_pool = self;
|
||||
objc_autoreleasePoolPop(_released);
|
||||
}
|
||||
/**
|
||||
|
|
49
Tests/base/NSAutoreleasePool/autorelease_eh.m
Normal file
49
Tests/base/NSAutoreleasePool/autorelease_eh.m
Normal file
|
@ -0,0 +1,49 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Foundation/NSException.h>
|
||||
@interface TestClass : NSObject
|
||||
- (void)runTest;
|
||||
- (void)exceptionThrowingMethod;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TestClass
|
||||
- (void)runTest
|
||||
{
|
||||
int c = 0;
|
||||
for (int i=0; i < 10; i++)
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
|
||||
@try
|
||||
{
|
||||
[self exceptionThrowingMethod];
|
||||
}
|
||||
@catch (NSException *e)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
PASS(c == 10, "Caught the correct number of exceptions without breaking the autorelease pool\n");
|
||||
}
|
||||
- (void)exceptionThrowingMethod
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
[@"Hello" stringByAppendingString: @" something to create a autoreleased object"];
|
||||
NSLog(@"Throwing an exception");
|
||||
@throw [NSException exceptionWithName: @"MyFunException" reason: @"it was always meant to happen" userInfo: [NSDictionary dictionary]];
|
||||
[pool release]; // Obviously this doesn't get run, but the [NSAutorelease new] at the top causes the problem
|
||||
}
|
||||
@end
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
TestClass *testClass = [[TestClass new] autorelease];
|
||||
[testClass runTest];
|
||||
[pool release];
|
||||
PASS(1, "Destroying pools in the wrong order didn't break anything...");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in a new issue