mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Bugfix update
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2885 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8dde889542
commit
d987db52d2
6 changed files with 114 additions and 65 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
Thu Jul 30 16:00:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* src/include/NSSet.h: Corrected protocol conformance
|
||||
* src/NSSet.m: Added ([-encodeWithCoder:]), ([-initWithCoder:]).
|
||||
Fixed ([-copyWithZone:]) to remove memory and to simply retain where
|
||||
possible.
|
||||
Implemented ([-description]) and ([-descriptionWithLocale:]).
|
||||
* src/NSGCountedSet.m: Removed ([-initWithCapacity:]) and fixed
|
||||
enumerator.
|
||||
* src/include/NSDictionary.h: Added ([+dictionaryWithObject:forKey:])
|
||||
and corrected protocol conformance.
|
||||
* src/NSDictionary.m: Added ([+dictionaryWithObject:forKey:])
|
||||
|
||||
Wed Jul 29 15:00:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* src/Collection.m: Removed [-copy]
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
@class NSArray, NSString, NSEnumerator;
|
||||
|
||||
@interface NSDictionary : NSObject
|
||||
@interface NSDictionary : NSObject <NSCoding, NSCopying, NSMutableCopying>
|
||||
- initWithObjects: (id*)objects
|
||||
forKeys: (NSObject**)keys
|
||||
count: (unsigned)count;
|
||||
|
@ -38,12 +38,13 @@
|
|||
- (NSEnumerator*) objectEnumerator;
|
||||
@end
|
||||
|
||||
@interface NSDictionary (NonCore) <NSCopying, NSMutableCopying>
|
||||
@interface NSDictionary (NonCore)
|
||||
|
||||
+ allocWithZone: (NSZone*)zone;
|
||||
+ dictionary;
|
||||
+ dictionaryWithContentsOfFile:(NSString *)path;
|
||||
+ dictionaryWithDictionary: (NSDictionary*)aDict;
|
||||
+ dictionaryWithObject: (id)object forKey: (id)key;
|
||||
+ dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;
|
||||
+ dictionaryWithObjects: (id*)objects forKeys: (id*)keys
|
||||
count: (unsigned)count;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
@class NSArray, NSString, NSEnumerator, NSDictionary;
|
||||
|
||||
@interface NSSet : NSObject <NSCopying>
|
||||
@interface NSSet : NSObject <NSCoding, NSCopying, NSMutableCopying>
|
||||
|
||||
+ allocWithZone: (NSZone*)zone;
|
||||
+ set;
|
||||
|
@ -77,7 +77,7 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface NSCountedSet : NSMutableSet <NSCoding, NSCopying>
|
||||
@interface NSCountedSet : NSMutableSet
|
||||
|
||||
+ allocWithZone: (NSZone*)zone;
|
||||
- initWithCapacity: (unsigned)numItems;
|
||||
|
|
|
@ -111,6 +111,63 @@ static Class NSMutableDictionary_concrete_class;
|
|||
return nil;
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone*)z
|
||||
{
|
||||
/* a deep copy */
|
||||
unsigned count = [self count];
|
||||
id oldKeys[count];
|
||||
id newKeys[count];
|
||||
id oldObjects[count];
|
||||
id newObjects[count];
|
||||
id newDictionary;
|
||||
unsigned i;
|
||||
id key;
|
||||
NSEnumerator *enumerator = [self keyEnumerator];
|
||||
BOOL needCopy = [self isKindOfClass: [NSMutableDictionary class]];
|
||||
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
needCopy = YES;
|
||||
for (i = 0; (key = [enumerator nextObject]); i++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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
|
||||
{
|
||||
/* a shallow copy */
|
||||
return [[[[[self class] _mutableConcreteClass] _mutableConcreteClass] alloc]
|
||||
initWithDictionary:self];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSDictionaryNonCore
|
||||
|
@ -203,6 +260,12 @@ static Class NSMutableDictionary_concrete_class;
|
|||
autorelease];
|
||||
}
|
||||
|
||||
+ dictionaryWithObject: (id)object forKey: (id)key
|
||||
{
|
||||
return [[[self alloc] initWithObjects: &object forKeys: &key count: 1]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
/* Override superclass's designated initializer */
|
||||
- init
|
||||
{
|
||||
|
@ -365,53 +428,6 @@ compareIt(id o1, id o2, void* context)
|
|||
return [[self description] writeToFile:path atomically:useAuxiliaryFile];
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone*)z
|
||||
{
|
||||
/* a deep copy */
|
||||
unsigned count = [self count];
|
||||
id oldKeys[count];
|
||||
id newKeys[count];
|
||||
id oldObjects[count];
|
||||
id newObjects[count];
|
||||
id newDictionary;
|
||||
unsigned i;
|
||||
id key;
|
||||
NSEnumerator *enumerator = [self keyEnumerator];
|
||||
BOOL needCopy = [self isKindOfClass: [NSMutableDictionary class]];
|
||||
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
needCopy = YES;
|
||||
for (i = 0; (key = [enumerator nextObject]); i++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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
|
||||
{
|
||||
/* a shallow copy */
|
||||
return [[[[[self class] _mutableConcreteClass] _mutableConcreteClass] alloc]
|
||||
initWithDictionary:self];
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
{
|
||||
return [self descriptionWithLocale: nil];
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
[super init];
|
||||
bag = d;
|
||||
[bag retain];
|
||||
enum_state = 0;
|
||||
enum_state = [bag newEnumState];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
[bag freeEnumState: &enum_state];
|
||||
[bag release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -74,12 +75,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
- initWithCapacity: (unsigned)numItems
|
||||
{
|
||||
return [self initWithType:@encode(id)
|
||||
capacity:numItems];
|
||||
}
|
||||
|
||||
- (NSEnumerator*) objectEnumerator
|
||||
{
|
||||
return [[[NSGCountedSetEnumerator alloc] initWithCountedSet:self]
|
||||
|
|
|
@ -314,14 +314,12 @@ static Class NSMutableSet_concrete_class;
|
|||
|
||||
- (NSString*) description
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
return 0;
|
||||
return [self descriptionWithLocale: nil];
|
||||
}
|
||||
|
||||
- (NSString*) descriptionWithLocale: (NSDictionary*)ld;
|
||||
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
return nil;
|
||||
return [[self allObjects] descriptionWithLocale: locale];
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone*)z
|
||||
|
@ -331,13 +329,28 @@ static Class NSMutableSet_concrete_class;
|
|||
id objects[count];
|
||||
id enumerator = [self objectEnumerator];
|
||||
id o;
|
||||
NSSet *newSet;
|
||||
int i;
|
||||
BOOL needCopy = [self isKindOfClass: [NSMutableSet class]];
|
||||
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
needCopy = YES;
|
||||
|
||||
for (i = 0; (o = [enumerator nextObject]); i++)
|
||||
objects[i] = [o copyWithZone:z];
|
||||
return [[[[self class] _concreteClass] alloc]
|
||||
{
|
||||
objects[i] = [o copyWithZone:z];
|
||||
if (objects[i] != o)
|
||||
needCopy = YES;
|
||||
}
|
||||
if (needCopy)
|
||||
newSet = [[[[self class] _concreteClass] alloc]
|
||||
initWithObjects:objects
|
||||
count:count];
|
||||
else
|
||||
newSet = [self retain];
|
||||
for (i = 0; i < count; i++)
|
||||
[objects[i] release];
|
||||
return newSet;
|
||||
}
|
||||
|
||||
- mutableCopyWithZone: (NSZone*)z
|
||||
|
@ -347,6 +360,17 @@ static Class NSMutableSet_concrete_class;
|
|||
initWithSet:self];
|
||||
}
|
||||
|
||||
- initWithCoder: aCoder
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: aCoder
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSMutableSet
|
||||
|
|
Loading…
Reference in a new issue