diff --git a/Headers/gnustep/base/NSObject.h b/Headers/gnustep/base/NSObject.h index 4c0f8e572..0608fefc2 100644 --- a/Headers/gnustep/base/NSObject.h +++ b/Headers/gnustep/base/NSObject.h @@ -189,4 +189,36 @@ extern NSRecursiveLock *gnustep_global_lock; inModes: (NSArray*)modes; @end +/* + * RETAIN(), RELEASE(), and AUTORELEASE() are placeholders for the + * (possible) future day when we have garbage collecting. + */ +#define RETAIN(object) [object retain] +#define RELEASE(object) [object release] +#define AUTORELEASE(object) [object autorelease] + +/* + * ASSIGN(object,value) assignes the value to the object with + * appropriate retain and release operations. + */ +#define ASSIGN(object,value) ({\ +if (value != object) \ + if (value) \ + { \ + [value retain]; \ + if (object) \ + { \ + [object release]; \ + } \ + object = value; \ + } \ +}) + +/* + * DESTROY() is a release operation which also sets the object to be + * a nil pointer for tidyness - we can't accidentally use a DESTROYED + * object later. + */ +#define DESTROY(object) ([object release], object = nil) + #endif /* __NSObject_h_GNUSTEP_BASE_INCLUDE */ diff --git a/Source/NSHost.m b/Source/NSHost.m index 20953a4a1..0585c04e9 100644 --- a/Source/NSHost.m +++ b/Source/NSHost.m @@ -250,11 +250,38 @@ static NSMutableDictionary *_hostCache = nil; } #endif +/* + * The OpenStep spec says that [-hash] must be the same for any two + * objects that [-isEqual:] returns YES for. We have a problem in + * that [-isEqualToHost:] is specified to return YES if any name or + * address part of two hosts is the same. That means we can't + * reasonably calculate a hash since two hosts with radically + * different ivar contents may be 'equal'. The best I can think of + * is for all hosts to hash to the same value - which makes it very + * inefficient to store them in a set, dictionary, map or hash table. + */ +- (unsigned) hash +{ + return 1; +} + +- (BOOL) isEqual: (id)other +{ + if (other == self) + return YES; + if ([other isKindOfClass: [NSHost class]]) + return [self isEqualToHost: (NSHost*)other]; + return NO; +} + - (BOOL)isEqualToHost:(NSHost *)aHost { NSArray* a; int i; + if (aHost == self) + return YES; + a = [aHost addresses]; for (i = 0; i < [a count]; i++) if ([addresses containsObject:[a objectAtIndex:i]])