mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
3c5d666112
commit
b574c2546e
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 */
|
/* The Class responsible for handling autorelease's */
|
||||||
static id autorelease_class = nil;
|
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)
|
BOOL NSShouldRetainWithZone(NSObject *anObject, NSZone *requestedZone)
|
||||||
{
|
{
|
||||||
if (!requestedZone || [anObject zone] == requestedZone)
|
if (!requestedZone || [anObject zone] == requestedZone)
|
||||||
|
@ -282,6 +286,15 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
|
||||||
|
|
||||||
- autorelease
|
- 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];
|
[autorelease_class addObject:self];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -352,6 +365,15 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
|
||||||
|
|
||||||
- (oneway void) release
|
- (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))
|
if (NSDecrementExtraRefCountWasZero(self))
|
||||||
[self dealloc];
|
[self dealloc];
|
||||||
return;
|
return;
|
||||||
|
@ -545,6 +567,11 @@ BOOL NSDecrementExtraRefCountWasZero(id anObject)
|
||||||
return autorelease_class;
|
return autorelease_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (void) enableDoubleReleaseCheck: (BOOL)enable
|
||||||
|
{
|
||||||
|
double_release_check_enabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
- (int)compare:anotherObject;
|
- (int)compare:anotherObject;
|
||||||
{
|
{
|
||||||
if ([self isEqual:anotherObject])
|
if ([self isEqual:anotherObject])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue