Minor bugfix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6395 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-03-28 14:29:37 +00:00
parent 0ed86abd4f
commit 126f4a14dc
2 changed files with 69 additions and 50 deletions

View file

@ -1,3 +1,8 @@
2000-03-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSDictionary.m: Fix to avoid crash on being asked to init
with contents of a nil dictionary.
2000-03-28 Richard Frith-Macdonald <rfm@gnu.org> 2000-03-28 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/gnustep/base/NSRunLoop.h: Added event type for exceptional * Headers/gnustep/base/NSRunLoop.h: Added event type for exceptional

View file

@ -329,43 +329,47 @@ static SEL appSel = @selector(appendString:);
- (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy - (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy
{ {
unsigned c = [other count]; unsigned c = [other count];
id os[c];
id ks[c];
id k;
NSEnumerator *e = [other keyEnumerator];
unsigned i = 0;
IMP nxtObj = [e methodForSelector: nxtSel];
IMP otherObj = [other methodForSelector: objSel];
if (shouldCopy) if (c > 0)
{ {
NSZone *z = [self zone]; id os[c];
id ks[c];
id k;
NSEnumerator *e = [other keyEnumerator];
unsigned i = 0;
IMP nxtObj = [e methodForSelector: nxtSel];
IMP otherObj = [other methodForSelector: objSel];
while ((k = (*nxtObj)(e, nxtSel)) != nil) if (shouldCopy)
{ {
ks[i] = k; NSZone *z = [self zone];
os[i] = [(*otherObj)(other, objSel, k) copyWithZone: z];
i++; while ((k = (*nxtObj)(e, nxtSel)) != nil)
} {
self = [self initWithObjects: os forKeys: ks count: i]; ks[i] = k;
os[i] = [(*otherObj)(other, objSel, k) copyWithZone: z];
i++;
}
self = [self initWithObjects: os forKeys: ks count: i];
#if !GS_WITH_GC #if !GS_WITH_GC
while (i > 0) while (i > 0)
{ {
[os[--i] release]; [os[--i] release];
} }
#endif #endif
return self;
}
else
{
while ((k = (*nxtObj)(e, nxtSel)) != nil)
{
ks[i] = k;
os[i] = (*otherObj)(other, objSel, k);
i++;
} }
return [self initWithObjects: os forKeys: ks count: c]; else
{
while ((k = (*nxtObj)(e, nxtSel)) != nil)
{
ks[i] = k;
os[i] = (*otherObj)(other, objSel, k);
i++;
}
self = [self initWithObjects: os forKeys: ks count: c];
}
} }
return self;
} }
- (id) initWithContentsOfFile: (NSString*)path - (id) initWithContentsOfFile: (NSString*)path
@ -418,24 +422,31 @@ static SEL appSel = @selector(appendString:);
- (BOOL) isEqualToDictionary: (NSDictionary*)other - (BOOL) isEqualToDictionary: (NSDictionary*)other
{ {
unsigned count;
if (other == self) if (other == self)
return YES;
if ([self count] == [other count])
{ {
NSEnumerator *e = [self keyEnumerator]; return YES;
IMP nxtObj = [e methodForSelector: nxtSel]; }
IMP myObj = [self methodForSelector: objSel]; count = [self count];
IMP otherObj = [other methodForSelector: objSel]; if (count == [other count])
id k; {
if (count > 0)
while ((k = (*nxtObj)(e, @selector(nextObject))) != nil)
{ {
id o1 = (*myObj)(self, objSel, k); NSEnumerator *e = [self keyEnumerator];
id o2 = (*otherObj)(other, objSel, k); IMP nxtObj = [e methodForSelector: nxtSel];
IMP myObj = [self methodForSelector: objSel];
IMP otherObj = [other methodForSelector: objSel];
id k;
if ([o1 isEqual: o2] == NO) while ((k = (*nxtObj)(e, @selector(nextObject))) != nil)
return NO; {
id o1 = (*myObj)(self, objSel, k);
id o2 = (*otherObj)(other, objSel, k);
if ([o1 isEqual: o2] == NO)
return NO;
}
} }
return YES; return YES;
} }
@ -944,7 +955,7 @@ static NSString *indentStrings[] = {
{ {
unsigned c = [keyArray count]; unsigned c = [keyArray count];
if (c) if (c > 0)
{ {
id keys[c]; id keys[c];
IMP remObj = [self methodForSelector: remSel]; IMP remObj = [self methodForSelector: remSel];
@ -959,13 +970,16 @@ static NSString *indentStrings[] = {
- (void) addEntriesFromDictionary: (NSDictionary*)other - (void) addEntriesFromDictionary: (NSDictionary*)other
{ {
id k; if (other != nil)
NSEnumerator *e = [other keyEnumerator]; {
IMP nxtObj = [e methodForSelector: nxtSel]; id k;
IMP setObj = [self methodForSelector: setSel]; NSEnumerator *e = [other keyEnumerator];
IMP nxtObj = [e methodForSelector: nxtSel];
IMP setObj = [self methodForSelector: setSel];
while ((k = (*nxtObj)(e, nxtSel)) != nil) while ((k = (*nxtObj)(e, nxtSel)) != nil)
(*setObj)(self, setSel, [other objectForKey: k], k); (*setObj)(self, setSel, [other objectForKey: k], k);
}
} }
- (void) setDictionary: (NSDictionary*)otherDictionary - (void) setDictionary: (NSDictionary*)otherDictionary