Retain/release fixes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19074 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-04-11 05:22:33 +00:00
parent 52548106c3
commit 01b40beefb
4 changed files with 46 additions and 17 deletions

View file

@ -1,3 +1,13 @@
2004-04-11 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSArchiver.h: New ivar in unarchiver.
* Source/NSUnarchiver.m: Simpler scheme to ensure that objects
persist until the end of unarchiving ... just store them in an
array.
* Source/NSNumber.m: Don't deallocate self in initialisers when
replacing with cached object ... use release instead in case
something else has retained us.
2004-04-09 Gregory John Casamento <greg_casamento@yahoo.com>
* Source/NSUnarchiver.m: Temporary rollback of previous fix.

View file

@ -31,7 +31,7 @@
#include <Foundation/NSCoder.h>
@class NSMutableDictionary, NSMutableData, NSData, NSString;
@class NSMutableArray, NSMutableDictionary, NSMutableData, NSData, NSString;
@interface NSArchiver : NSCoder
{
@ -163,6 +163,7 @@
unsigned version; /* Version of archiver used. */
NSZone *zone; /* Zone for allocating objs. */
NSMutableDictionary *objDict; /* Class information store. */
NSMutableArray *objSave;
}
/* Initializing an unarchiver */

View file

@ -635,7 +635,7 @@ static Class doubleNumberClass;
- (id) initWithBool: (BOOL)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value == NO)
{
self = boolN;
@ -649,7 +649,7 @@ static Class doubleNumberClass;
- (id) initWithChar: (signed char)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL && value >= -GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -662,7 +662,7 @@ static Class doubleNumberClass;
- (id) initWithDouble: (double)value
{
NSDeallocateObject(self);
RELEASE(self);
self = (NSNumber*)NSAllocateObject(doubleNumberClass, 0,
NSDefaultMallocZone());
self = [self initWithBytes: &value objCType: NULL];
@ -671,7 +671,7 @@ static Class doubleNumberClass;
- (id) initWithFloat: (float)value
{
NSDeallocateObject(self);
RELEASE(self);
self = (NSNumber*)NSAllocateObject(floatNumberClass, 0,
NSDefaultMallocZone());
self = [self initWithBytes: &value objCType: NULL];
@ -680,7 +680,7 @@ static Class doubleNumberClass;
- (id) initWithInt: (signed int)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL && value >= -GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -693,7 +693,7 @@ static Class doubleNumberClass;
- (id) initWithLong: (signed long)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL && value >= -GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -706,7 +706,7 @@ static Class doubleNumberClass;
- (id) initWithLongLong: (signed long long)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL && value >= -GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -719,7 +719,7 @@ static Class doubleNumberClass;
- (id) initWithShort: (signed short)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL && value >= -GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -732,7 +732,7 @@ static Class doubleNumberClass;
- (id) initWithUnsignedChar: (unsigned char)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -745,7 +745,7 @@ static Class doubleNumberClass;
- (id) initWithUnsignedInt: (unsigned int)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -758,7 +758,7 @@ static Class doubleNumberClass;
- (id) initWithUnsignedLong: (unsigned long)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -771,7 +771,7 @@ static Class doubleNumberClass;
- (id) initWithUnsignedLongLong: (unsigned long long)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -784,7 +784,7 @@ static Class doubleNumberClass;
- (id) initWithUnsignedShort: (unsigned short)value
{
NSDeallocateObject(self);
RELEASE(self);
if (value <= GS_SMALL)
{
return RETAIN(smallIntegers[value + GS_SMALL]);
@ -2524,8 +2524,7 @@ static Class doubleNumberClass;
case 'f': self = [self initWithFloat: data.f]; break;
case 'd': self = [self initWithDouble: data.d]; break;
default:
[self dealloc];
self = nil;
DESTROY(self);
NSLog(@"Attempt to decode number with unknown ObjC type");
}
return self;

View file

@ -49,6 +49,7 @@
#include "Foundation/NSData.h"
#include "Foundation/NSUtilities.h"
#include "Foundation/NSString.h"
#include "Foundation/NSArray.h"
static const char*
typeToName1(char type)
@ -391,6 +392,7 @@ static Class NSDataMallocClass;
- (void) dealloc
{
RELEASE(data);
RELEASE(objSave);
RELEASE(objDict);
if (clsMap)
{
@ -435,7 +437,13 @@ static Class NSDataMallocClass;
* encoded with.
*/
objDict = [[NSMutableDictionary allocWithZone: zone]
initWithCapacity: 200];
initWithCapacity: 200];
/*
* objSave is an array used purely to ensure that objects
* we decode persist until the end of the decoding.
*/
objSave = [[NSMutableArray allocWithZone: zone]
initWithCapacity: 200];
NS_DURING
{
@ -609,6 +617,16 @@ static Class NSDataMallocClass;
obj = rep;
GSIArraySetItemAtIndex(objMap, (GSIArrayItem)obj, xref);
}
/*
* The objMap does not retain objects, so in order to
* be sure that a decoded object is not deallocated by
* anything before it is needed (because it is decoded
* later as a cross reference) we store it in objSave.
*/
if (obj != nil)
{
[objSave addObject: obj];
}
}
}
*(id*)address = obj;
@ -1269,6 +1287,7 @@ static Class NSDataMallocClass;
}
[objDict removeAllObjects];
[objSave removeAllObjects];
}
- (void) deserializeHeaderAt: (unsigned*)pos