mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-11 00:30:49 +00:00
Memory leak and other fixes from Frith-MacDonald.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2775 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7285b3e9a6
commit
a0993c655f
17 changed files with 11155 additions and 10927 deletions
10865
ChangeLog.1
Normal file
10865
ChangeLog.1
Normal file
File diff suppressed because it is too large
Load diff
|
@ -42,6 +42,7 @@
|
|||
|
||||
#ifndef STRICT_OPENSTEP
|
||||
+ valueFromString: (NSString *)string;
|
||||
- (BOOL) isEqualToValue: (NSValue*)other;
|
||||
#endif
|
||||
|
||||
// Accessing Data
|
||||
|
@ -56,7 +57,7 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface NSNumber : NSValue <NSCoding>
|
||||
@interface NSNumber : NSValue <NSCopying,NSCoding>
|
||||
|
||||
// Allocating and Initializing
|
||||
|
||||
|
|
|
@ -85,30 +85,6 @@ static Class NSMutableArray_concrete_class;
|
|||
return NSAllocateObject ([self _concreteClass], 0, z);
|
||||
}
|
||||
|
||||
/* This is the designated initializer for NSArray. */
|
||||
- initWithObjects: (id*)objects count: (unsigned)count
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (unsigned) count
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- objectAtIndex: (unsigned)index
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSArrayNonCore
|
||||
|
||||
+ array
|
||||
{
|
||||
return [[[self alloc] init]
|
||||
|
@ -134,6 +110,30 @@ static Class NSMutableArray_concrete_class;
|
|||
autorelease];
|
||||
}
|
||||
|
||||
/* This is the designated initializer for NSArray. */
|
||||
- initWithObjects: (id*)objects count: (unsigned)count
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (unsigned) count
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- objectAtIndex: (unsigned)index
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSArrayNonCore
|
||||
|
||||
- (NSArray*) arrayByAddingObject: anObject
|
||||
{
|
||||
id na;
|
||||
|
@ -622,12 +622,29 @@ static Class NSMutableArray_concrete_class;
|
|||
{
|
||||
/* a deep copy */
|
||||
unsigned count = [self count];
|
||||
id objects[count];
|
||||
id oldObjects[count];
|
||||
id newObjects[count];
|
||||
id newArray;
|
||||
unsigned i;
|
||||
BOOL needCopy = [self isKindOfClass: [NSMutableArray class]];
|
||||
|
||||
if (NSShouldRetainWithZone(self, zone) == NO)
|
||||
needCopy = YES;
|
||||
[self getObjects: oldObjects];
|
||||
for (i = 0; i < count; i++)
|
||||
objects[i] = [[self objectAtIndex:i] copyWithZone:zone];
|
||||
return [[[[self class] _concreteClass] allocWithZone:zone]
|
||||
initWithObjects:objects count:count];
|
||||
{
|
||||
newObjects[i] = [oldObjects[i] copyWithZone:zone];
|
||||
if (newObjects[i] != oldObjects[i])
|
||||
needCopy = YES;
|
||||
}
|
||||
if (needCopy)
|
||||
newArray = [[[[self class] _concreteClass] allocWithZone:zone]
|
||||
initWithObjects:newObjects count:count];
|
||||
else
|
||||
newArray = [self retain];
|
||||
for (i = 0; i < count; i++)
|
||||
[newObjects[i] release];
|
||||
return newArray;
|
||||
}
|
||||
|
||||
/* The NSMutableCopying Protocol */
|
||||
|
|
|
@ -77,6 +77,49 @@
|
|||
memcpy( value, &data, objc_sizeof_type([self objCType]) );
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)other
|
||||
{
|
||||
if ([other isKindOfClass: [self class]]) {
|
||||
return [self isEqualToValue: other];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isEqualToValue: (NSValue*)aValue
|
||||
{
|
||||
typedef _dt = data;
|
||||
if ([aValue isKindOfClass: [self class]]) {
|
||||
_dt val = [aValue TYPE_METHOD];
|
||||
#if TYPE_ORDER == 0
|
||||
return [data isEqual: val];
|
||||
#elif TYPE_ORDER == 1
|
||||
if (data.x == val.x && data.y == val.y)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
#elif TYPE_ORDER == 2
|
||||
if (data == val)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
#elif TYPE_ORDER == 3
|
||||
if (data.origin.x == val.origin.x &&
|
||||
data.origin.y == val.origin.y &&
|
||||
data.size.width == val.size.width &&
|
||||
data.size.height == val.size.height)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
#elif TYPE_ORDER == 4
|
||||
if (data.width == val.width && data.height == val.height)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
#endif
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
{
|
||||
typedef _dt = data;
|
||||
|
|
|
@ -24,9 +24,10 @@
|
|||
#include <config.h>
|
||||
#include <math.h>
|
||||
#include <objc/objc-api.h>
|
||||
#include <gnustep/base/NSDate.h>
|
||||
#include <gnustep/base/NSString.h>
|
||||
#include <gnustep/base/NSException.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
||||
#ifndef __WIN32__
|
||||
#include <time.h>
|
||||
|
@ -145,6 +146,27 @@ static id long_day[7] = {@"Sunday",
|
|||
return [d autorelease];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[super encodeWithCoder: aCoder];
|
||||
[aCoder encodeObject: calendar_format];
|
||||
[aCoder encodeObject: time_zone];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
self = [super initWithCoder: aCoder];
|
||||
calendar_format = [aCoder decodeObject];
|
||||
time_zone = [aCoder decodeObject];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[calendar_format release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// Initializing an NSCalendar Date
|
||||
- (id)initWithString:(NSString *)description
|
||||
{
|
||||
|
@ -972,7 +994,7 @@ static id long_day[7] = {@"Sunday",
|
|||
|
||||
- (void)setCalendarFormat:(NSString *)format
|
||||
{
|
||||
calendar_format = format;
|
||||
calendar_format = [format copyWithZone: [self zone]];
|
||||
}
|
||||
|
||||
// Getting and Setting Time Zones
|
||||
|
|
|
@ -304,6 +304,21 @@
|
|||
return [super isEqual: o];
|
||||
}
|
||||
|
||||
- (id) copy
|
||||
{
|
||||
return [self copyWithZone: NSDefaultMallocZone()];
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone*)zone
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, zone)) {
|
||||
return [self retain];
|
||||
}
|
||||
else {
|
||||
return NSCopyObject(self, 0, zone);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)descriptionWithLocale: (NSDictionary*)locale
|
||||
{
|
||||
return [NSString stringWithFormat:TYPE_FORMAT, data];
|
||||
|
|
|
@ -113,6 +113,11 @@
|
|||
memcpy( value, data, objc_sizeof_type([objctype cString]) );
|
||||
}
|
||||
|
||||
-(BOOL) isEqualToValue: (NSValue*)aValue
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
{
|
||||
return [objctype cString];
|
||||
|
|
|
@ -744,8 +744,12 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
if (NSShouldRetainWithZone(self, zone) &&
|
||||
[self isKindOfClass: [NSMutableData class]] == NO)
|
||||
return [self retain];
|
||||
else
|
||||
return [[NSDataMalloc allocWithZone: zone]
|
||||
initWithBytes: [self bytes] length: [self length]];
|
||||
}
|
||||
|
||||
- (id) mutableCopy
|
||||
|
@ -755,8 +759,8 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
|
||||
- (id) mutableCopyWithZone: (NSZone*)zone
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
return [[NSMutableDataMalloc allocWithZone: zone]
|
||||
initWithBytes: [self bytes] length: [self length]];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder:(NSCoder*)coder
|
||||
|
@ -1183,11 +1187,6 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
return [NSDataMalloc class];
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [self retain];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (bytes)
|
||||
|
@ -1311,12 +1310,6 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
return length;
|
||||
}
|
||||
|
||||
- (id) mutableCopyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [[NSMutableDataMalloc allocWithZone:zone] initWithBytes: bytes
|
||||
length: length];
|
||||
}
|
||||
|
||||
- (void*) relinquishAllocatedBytes
|
||||
{
|
||||
void *buf = bytes;
|
||||
|
@ -1552,11 +1545,6 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
return [NSMutableDataMalloc class];
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [[NSDataMalloc allocWithZone:zone] initWithBytes:bytes length:length];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (bytes)
|
||||
|
@ -1706,12 +1694,6 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
|
|||
return bytes;
|
||||
}
|
||||
|
||||
- (id) mutableCopyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [[NSMutableDataMalloc allocWithZone:zone] initWithBytes: bytes
|
||||
length: length];
|
||||
}
|
||||
|
||||
- (id) setCapacity: (unsigned int)size
|
||||
{
|
||||
if (size != capacity)
|
||||
|
|
|
@ -367,22 +367,41 @@ compareIt(id o1, id o2, void* context)
|
|||
- copyWithZone: (NSZone*)z
|
||||
{
|
||||
/* a deep copy */
|
||||
int count = [self count];
|
||||
id objects[count];
|
||||
NSObject *keys[count];
|
||||
id enumerator = [self keyEnumerator];
|
||||
unsigned count = [self count];
|
||||
id oldKeys[count];
|
||||
id newKeys[count];
|
||||
id oldObjects[count];
|
||||
id newObjects[count];
|
||||
id newDictionary;
|
||||
unsigned i;
|
||||
id key;
|
||||
int i;
|
||||
NSEnumerator *enumerator = [self keyEnumerator];
|
||||
BOOL needCopy = [self isKindOfClass: [NSMutableDictionary class]];
|
||||
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
needCopy = YES;
|
||||
for (i = 0; (key = [enumerator nextObject]); i++)
|
||||
{
|
||||
keys[i] = [key copyWithZone:z];
|
||||
objects[i] = [[self objectForKey:key] copyWithZone:z];
|
||||
oldKeys[i] = key;
|
||||
oldObjects[i] = [self objectForKey:key];
|
||||
newKeys[i] = [oldKeys[i] copyWithZone:z];
|
||||
newObjects[i] = [oldObjects[i] copyWithZone:z];
|
||||
if (oldKeys[i] != newKeys[i] || oldObjects[i] != newObjects[i])
|
||||
needCopy = YES;
|
||||
}
|
||||
return [[[[self class] _concreteClass] alloc]
|
||||
initWithObjects:objects
|
||||
forKeys:keys
|
||||
if (needCopy)
|
||||
newDictionary = [[[[self class] _concreteClass] alloc]
|
||||
initWithObjects:newObjects
|
||||
forKeys:newKeys
|
||||
count:count];
|
||||
else
|
||||
newDictionary = [self retain];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
[newKeys[i] release];
|
||||
[newObjects[i] release];
|
||||
}
|
||||
return newDictionary;
|
||||
}
|
||||
|
||||
- mutableCopyWithZone: (NSZone*)z
|
||||
|
|
|
@ -145,7 +145,8 @@
|
|||
char *r;
|
||||
|
||||
OBJC_MALLOC(r, char, _count+1);
|
||||
ustrtostr(r,_contents_chars, _count);
|
||||
if (_count > 0)
|
||||
ustrtostr(r,_contents_chars, _count);
|
||||
r[_count] = '\0';
|
||||
[[[MallocAddress alloc] initWithAddress:r] autorelease];
|
||||
return r;
|
||||
|
|
|
@ -224,22 +224,32 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
[super encodeWithCoder: aCoder];
|
||||
[aCoder encodeObject: [self address]];
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* GNUstep specific method for more efficient decoding. */
|
||||
+ (id) newWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
NSString *address = [aCoder decodeObject];
|
||||
return [NSHost hostWithAddress: address];
|
||||
}
|
||||
/* OpenStep method for decoding (not used) */
|
||||
#else
|
||||
/* OpenStep methods for decoding (not used) */
|
||||
- (id) awakeAfterUsingCoder: (NSCoder*)aCoder
|
||||
{
|
||||
return [NSHost hostWithAddress: [addresses objectAtIndex: 0]];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
NSString *address;
|
||||
|
||||
[super initWithCoder: aCoder];
|
||||
address = [aCoder decodeObject];
|
||||
[self dealloc];
|
||||
return [NSHost hostWithAddress: address];
|
||||
addresses = [NSArray arrayWithObject: address];
|
||||
[address release];
|
||||
return self;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (BOOL)isEqualToHost:(NSHost *)aHost
|
||||
{
|
||||
|
|
|
@ -260,6 +260,18 @@
|
|||
return self=[[NSUShortNumber alloc] initValue:&value withObjCType:NULL];
|
||||
}
|
||||
|
||||
- (id) copy
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone*)zone
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
{
|
||||
return [self descriptionWithLocale: nil];
|
||||
|
|
|
@ -557,7 +557,7 @@ handle_printf_atsign (FILE *stream,
|
|||
|
||||
- (id) init
|
||||
{
|
||||
[super init];
|
||||
self = [super init];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -1325,7 +1325,7 @@ if (mask & NSLiteralSearch)
|
|||
[aString getCharacters:s2];
|
||||
s2[s2len] = (unichar)0;
|
||||
end = s1len+1;
|
||||
if (s2len > s1len)
|
||||
if (s2len < s1len)
|
||||
end = s2len+1;
|
||||
|
||||
if (mask & NSCaseInsensitiveSearch)
|
||||
|
@ -1346,7 +1346,12 @@ if (mask & NSLiteralSearch)
|
|||
if (s1[i] > s2[i]) return NSOrderedDescending;
|
||||
}
|
||||
}
|
||||
return NSOrderedSame;
|
||||
if (s1len > s2len)
|
||||
return NSOrderedDescending;
|
||||
else if (s1len < s2len)
|
||||
return NSOrderedAscending;
|
||||
else
|
||||
return NSOrderedSame;
|
||||
} /* if NSLiteralSearch */
|
||||
else
|
||||
{
|
||||
|
@ -1362,9 +1367,9 @@ else
|
|||
while(myCount < end)
|
||||
{
|
||||
if(strCount>=[aString length])
|
||||
return NSOrderedAscending;
|
||||
if(myCount>=[self length])
|
||||
return NSOrderedDescending;
|
||||
if(myCount>=[self length])
|
||||
return NSOrderedAscending;
|
||||
myRange = [self rangeOfComposedCharacterSequenceAtIndex: myCount];
|
||||
myCount += myRange.length;
|
||||
strRange = [aString rangeOfComposedCharacterSequenceAtIndex: strCount];
|
||||
|
@ -1379,7 +1384,7 @@ else
|
|||
return result;
|
||||
} /* while */
|
||||
if(strCount<[aString length])
|
||||
return NSOrderedDescending;
|
||||
return NSOrderedAscending;
|
||||
return NSOrderedSame;
|
||||
} /* else */
|
||||
}
|
||||
|
@ -2590,7 +2595,12 @@ else
|
|||
|
||||
- copyWithZone: (NSZone*)zone
|
||||
{
|
||||
return [[[self class] allocWithZone:zone] initWithString:self];
|
||||
if ([self isKindOfClass: [NSMutableString class]] ||
|
||||
NSShouldRetainWithZone(self, zone) == NO)
|
||||
return [[[[self class] _concreteClass] allocWithZone:zone]
|
||||
initWithString:self];
|
||||
else
|
||||
return [self retain];
|
||||
}
|
||||
|
||||
/* xxx Temporarily put this NSObject-like implementation here, so
|
||||
|
|
|
@ -327,14 +327,25 @@ decode (const void *ptr)
|
|||
- (void)encodeWithCoder: aCoder
|
||||
{
|
||||
[super encodeWithCoder: aCoder];
|
||||
[aCoder encodeObject: name];
|
||||
if (self == localTimeZone)
|
||||
[aCoder encodeObject: @"NSLocalTimeZone"];
|
||||
else
|
||||
[aCoder encodeObject: name];
|
||||
}
|
||||
|
||||
- (id) awakeAfterUsingCoder: aCoder
|
||||
{
|
||||
if ([name isEqual: @"NSLocalTimeZone"]) {
|
||||
return localTimeZone;
|
||||
}
|
||||
return [NSTimeZone timeZoneWithName: name];
|
||||
}
|
||||
|
||||
- initWithDecoder: aDecoder
|
||||
{
|
||||
/* FIXME?: is this right? */
|
||||
self = [super initWithCoder: aDecoder];
|
||||
return (self = (id)[NSTimeZone timeZoneWithName: [aDecoder decodeObject]]);
|
||||
name = [aDecoder decodeObject];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSTimeZoneDetail*)timeZoneDetailForDate: (NSDate*)date
|
||||
|
|
|
@ -88,6 +88,11 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
return [self copyWithZone: NSDefaultMallocZone()];
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, zone))
|
||||
|
@ -203,6 +208,20 @@
|
|||
[self subclassResponsibility:_cmd];
|
||||
}
|
||||
|
||||
- (BOOL)isEqual: (id)other
|
||||
{
|
||||
if ([other isKindOfClass: [self class]]) {
|
||||
return [self isEqualToValue: other];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isEqualToValue: (NSValue*)other
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
|
|
|
@ -1439,8 +1439,10 @@ static NSMapTable *out_port_bag = NULL;
|
|||
sockaddr,
|
||||
sizeof (p->_remote_in_port_address));
|
||||
NSMapInsert (out_port_bag, (void*)p, (void*)p);
|
||||
/*
|
||||
NSLog(@"Out port changed from %@ to %@\n", od,
|
||||
[p description]);
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue