mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
([NSObject -autorelease], [NSObject -release]):
Add double_release checking. ([NSObject +enableDoubleReleaseCheck:]): New method. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@529 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e3689458b8
commit
973b8f6472
1 changed files with 27 additions and 0 deletions
|
@ -49,6 +49,10 @@ static coll_cache_ptr retain_counts = NULL;
|
|||
/* The Class responsible for handling autorelease's */
|
||||
static id autorelease_class = nil;
|
||||
|
||||
/* When this is `YES', every call to release/autorelease, checks to make sure
|
||||
isn't being set up to release itself too many times. */
|
||||
static BOOL double_release_check_enabled = NO;
|
||||
|
||||
BOOL NSShouldRetainWithZone(NSObject *anObject, NSZone *requestedZone)
|
||||
{
|
||||
if (!requestedZone || [anObject zone] == requestedZone)
|
||||
|
@ -282,6 +286,15 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
|
|||
|
||||
- autorelease
|
||||
{
|
||||
if (double_release_check_enabled)
|
||||
{
|
||||
unsigned release_count;
|
||||
unsigned retain_count = [self retainCount];
|
||||
release_count = [autorelease_class autoreleaseCountForObject:self];
|
||||
if (release_count > retain_count)
|
||||
[self error:"Autorelease would release object too many times."];
|
||||
}
|
||||
|
||||
[autorelease_class addObject:self];
|
||||
return self;
|
||||
}
|
||||
|
@ -352,6 +365,15 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
|
|||
|
||||
- (oneway void) release
|
||||
{
|
||||
if (double_release_check_enabled)
|
||||
{
|
||||
unsigned release_count;
|
||||
unsigned retain_count = [self retainCount];
|
||||
release_count = [autorelease_class autoreleaseCountForObject:self];
|
||||
if (release_count > retain_count)
|
||||
[self error:"Release would release object too many times."];
|
||||
}
|
||||
|
||||
if (NSDecrementExtraRefCountWasZero(self))
|
||||
[self dealloc];
|
||||
return;
|
||||
|
@ -545,6 +567,11 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
|
|||
return autorelease_class;
|
||||
}
|
||||
|
||||
+ (void) enableDoubleReleaseCheck: (BOOL)enable
|
||||
{
|
||||
double_release_check_enabled = enable;
|
||||
}
|
||||
|
||||
- (int)compare:anotherObject;
|
||||
{
|
||||
if ([self isEqual:anotherObject])
|
||||
|
|
Loading…
Reference in a new issue