From 24f59ea2a0dba16144370a75dfc6dbc277d39579 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 24 Jun 1999 19:30:29 +0000 Subject: [PATCH] Mostly tidying git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4465 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 49 + Headers/gnustep/base/GSIMap.h | 2 +- Headers/gnustep/base/NSNotification.h | 30 +- Source/Collection.m | 2 +- Source/NSArchiver.m | 8 +- Source/NSCalendarDate.m | 2 +- Source/NSCoder.m | 6 +- Source/NSConcreteValue.m | 2 - Source/NSConnection.m | 17 +- Source/NSData.m | 12 +- Source/NSDate.m | 9 +- Source/NSDictionary.m | 6 +- Source/NSDistributedNotificationCenter.m | 4 +- Source/NSGAttributedString.m | 2 +- Source/NSGCString.m | 3 +- Source/NSGCountedSet.m | 2 +- Source/NSGDictionary.m | 1 + Source/NSHost.m | 1 + Source/NSLock.m | 2 - Source/NSNotificationCenter.m | 1393 +++++++++++++--------- Source/NSNotificationQueue.m | 5 +- Source/NSNumber.m | 1 + Source/NSObjCRuntime.m | 1 + Source/NSObject.m | 8 + Source/NSPage.m | 4 + Source/NSPortNameServer.m | 4 +- Source/NSScanner.m | 2 +- Source/NSSerializer.m | 8 +- Source/NSString.m | 94 +- Source/NSTask.m | 5 +- Source/NSThread.m | 1 + Source/NSTimeZone.m | 2 +- Source/NSURL.m | 518 ++++---- Source/NSURLHandle.m | 163 +-- Source/NSUnarchiver.m | 10 +- Source/NSUserDefaults.m | 2 +- Source/NSZone.m | 7 +- Source/TcpPort.m | 6 +- Source/UnixFileHandle.m | 11 +- Source/propList.h | 2 +- Tools/gdnc.m | 3 + Tools/gdomap.c | 12 +- Tools/pldes.m | 1 - Tools/plparse.m | 1 - Tools/plser.m | 1 - Tools/sfparse.m | 1 - 46 files changed, 1406 insertions(+), 1020 deletions(-) diff --git a/ChangeLog b/ChangeLog index b19467c99..43ca53208 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,52 @@ +Thu Jun 24 20:30:00 1999 Richard Frith-Macdonald + + * Source/include/GSIMap.h: Tweaks to avoid compiler warnings. + * Source/include/NSNotification.h: ditto. + * Source/propList.h: ditto. + * Source/Collection.m: ditto. + * Source/TcpPort.m: ditto. + * Source/UnixFileHandle.m: ditto. + * Source/NSArchiver.m: ditto. + * Source/NSArchiver.m: ditto. + * Source/NSCalendarDate.m: ditto. + * Source/NSCoder.m: ditto. + * Source/NSConcreteValue.m: ditto. + * Source/NSConnection.m: ditto. + * Source/NSData.m: ditto. + * Source/NSDate.m: ditto. + * Source/NSDictionary.m: ditto. + * Source/NSDistributedNotificationCenter.m: ditto. + * Source/NSGAttributedString.m: ditto. + * Source/NSGCountedSet.m: ditto. + * Source/NSGCString.m: ditto. + * Source/NSGDictionary.m: ditto. + * Source/NSHost.m: ditto. + * Source/NSLock.m: ditto. + * Source/NSNotificationCenter.m: ditto. + * Source/NSNotificationQueue.m: ditto. + * Source/NSNumber.m: ditto. + * Source/NSObjCRuntime.m: ditto. + * Source/NSObject.m: ditto. + * Source/NSPage.m: ditto. + * Source/NSPortNameServer.m: ditto. + * Source/NSScanner.m: ditto. + * Source/NSSerializer.m: ditto. + * Source/NSString.m: ditto. + * Source/NSTask.m: ditto. + * Source/NSTimeZone.m: ditto. + * Source/NSThread.m: ditto. + * Source/NSUnarchiver.m: ditto. + * Source/NSURL.m: ditto. + * Source/NSURLHandle.m: ditto. + * Source/NSUserDefaults.m: ditto. + * Source/NSZone.m: ditto. + * Tools/gdomap.c: ditto. + * Tools/gdnc.m: ditto. + * Tools/plparse.m: ditto. + * Tools/sfparse.m: ditto. + * Tools/pldes.m: ditto. + * Tools/plser.m: ditto. + 1999-06-24 Adam Fedor * Source/include/GSIArray.h (GSIArrayRemoveLastItem): New function. diff --git a/Headers/gnustep/base/GSIMap.h b/Headers/gnustep/base/GSIMap.h index 3e6468e53..32e57da7b 100644 --- a/Headers/gnustep/base/GSIMap.h +++ b/Headers/gnustep/base/GSIMap.h @@ -741,7 +741,7 @@ GSIMapEmptyMap(GSIMapTable map) map->zone = 0; } -static INLINE GSIMapTable +static INLINE void GSIMapInitWithZoneAndCapacity(GSIMapTable map, NSZone *zone, size_t capacity) { map->zone = zone; diff --git a/Headers/gnustep/base/NSNotification.h b/Headers/gnustep/base/NSNotification.h index 4ab5b392e..140e32258 100644 --- a/Headers/gnustep/base/NSNotification.h +++ b/Headers/gnustep/base/NSNotification.h @@ -58,11 +58,7 @@ @interface NSNotificationCenter : NSObject { - void *wildcard; /* Observations matching anything. */ - NSMapTable *nameless; /* Observations matching objects. */ - void *named; /* Observations matching names. */ - NSMapTable *observers; /* Observations keyed by observer. */ - NSLock *_lock; + void *table; } + (NSNotificationCenter*) defaultCenter; @@ -86,4 +82,28 @@ @end +#ifndef NO_GNUSTEP +@interface NSNotification (GNUstep) +- (id) initWithName: (NSString*)name + object: (id)object + userInfo: (NSDictionary*)user_info; +@end + +@interface NSNotificationCenter (GNUstep) +/* + * Extensions for maximising posting performance - these options are + * NOT adjustable for the default notification center. + * + * You can disable locking in a multi-threaded program if you KNOW that only + * one thread will ever use the notification center. + * + * You can turn on 'immutability' if you KNOW that the posting of a + * notification will never result in an attempt to modify the center. + * In this case, the center can optimise delivery of notifications. + */ +- (BOOL) setImmutableInPost: (BOOL)flag; +- (BOOL) setLockingDisabled: (BOOL)flag; +@end +#endif + #endif /*__NSNotification_h_GNUSTEP_BASE_INCLUDE */ diff --git a/Source/Collection.m b/Source/Collection.m index 5396c2b6a..5fa21bc8d 100644 --- a/Source/Collection.m +++ b/Source/Collection.m @@ -537,7 +537,7 @@ been -shallowCopy'ed can cause major memory leakage. */ - copyAs: (id )aCollectionClass { - id newColl = [self emptyCopyAs:aCollectionClass]; + id newColl = [self emptyCopyAs: (Class)aCollectionClass]; id o; FOR_COLLECTION(self, o) diff --git a/Source/NSArchiver.m b/Source/NSArchiver.m index 49a9134b4..c95f330a0 100644 --- a/Source/NSArchiver.m +++ b/Source/NSArchiver.m @@ -26,9 +26,9 @@ /* * Setup for inline operation of pointer map tables. */ -#define GSI_MAP_RETAIN_KEY(X) X +#define GSI_MAP_RETAIN_KEY(X) #define GSI_MAP_RELEASE_KEY(X) -#define GSI_MAP_RETAIN_VAL(X) X +#define GSI_MAP_RETAIN_VAL(X) #define GSI_MAP_RELEASE_VAL(X) #define GSI_MAP_HASH(X) ((X).uint) #define GSI_MAP_EQUAL(X,Y) ((X).uint == (Y).uint) @@ -248,8 +248,6 @@ static SEL eValSel = @selector(encodeValueOfObjCType:at:); - (void) encodeValueOfObjCType: (const char*)type at: (const void*)buf { - uchar info; - switch (*type) { case _C_ID: @@ -884,8 +882,6 @@ static SEL eValSel = @selector(encodeValueOfObjCType:at:); - (void) resetArchiver { - char buf[strlen(PREFIX)+33]; - if (clsMap) { GSIMapCleanMap(clsMap); diff --git a/Source/NSCalendarDate.m b/Source/NSCalendarDate.m index e2eaa3581..001e37da6 100644 --- a/Source/NSCalendarDate.m +++ b/Source/NSCalendarDate.m @@ -751,7 +751,7 @@ BOOL mtag = NO, dtag = NO, ycent = NO; BOOL mname = NO, dname = NO; double s; - int yd = 0, md = 0, dd = 0, mnd = 0, sd = 0, dom = -1, dow = -1, doy = -1; + int yd = 0, md = 0, mnd = 0, sd = 0, dom = -1, dow = -1, doy = -1; int hd = 0, nhd; int i, j, k, z; diff --git a/Source/NSCoder.m b/Source/NSCoder.m index 6f8bf7eac..7ddfb00ed 100644 --- a/Source/NSCoder.m +++ b/Source/NSCoder.m @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -148,8 +149,8 @@ va_start(ap, types); while (*types) { - [self encodeValueOfObjCType:types - at:va_arg(ap, void*)]; + (*imp)(self, @selector(encodeValueOfObjCType:at:), types, + va_arg(ap, void*)); types = objc_skip_typespec(types); } va_end(ap); @@ -173,7 +174,6 @@ { unsigned count; const char *type = @encode(unsigned char); - int i; unsigned char *where; unsigned char *array; IMP imp = [self methodForSelector:@selector(decodeValueOfObjCType:at:)]; diff --git a/Source/NSConcreteValue.m b/Source/NSConcreteValue.m index 3eecf4444..2b0d83871 100644 --- a/Source/NSConcreteValue.m +++ b/Source/NSConcreteValue.m @@ -104,8 +104,6 @@ - (BOOL) isEqualToValue: (NSValue*)aValue { - const char* type; - if (fastClass(aValue) != fastClass(self)) return NO; if (strcmp(objctype, ((NSConcreteValue*)aValue)->objctype) != 0) diff --git a/Source/NSConnection.m b/Source/NSConnection.m index ec9eb5715..e319b677d 100644 --- a/Source/NSConnection.m +++ b/Source/NSConnection.m @@ -187,7 +187,7 @@ static unsigned local_object_counter = 0; @interface NSConnection (Private) - _superInit; - (void) handlePortMessage: (NSPortMessage*)msg; -+ setDebug: (int)val; ++ (void) setDebug: (int)val; @end #define proxiesHashGate refGate @@ -219,18 +219,6 @@ compare_ints (const void *k1, const void *k2) return !(k1 - k2); } -static int -type_get_number_of_arguments (const char *type) -{ - int i = 0; - while (*type) - { - type = objc_skip_argspec (type); - i += 1; - } - return i - 1; -} - /* class defaults */ static id default_receive_port_class; static id default_send_port_class; @@ -1124,7 +1112,7 @@ static int messages_received_count; return self; } -+ setDebug: (int)val ++ (void) setDebug: (int)val { debug_connection = val; } @@ -2040,7 +2028,6 @@ static int messages_received_count; { id op; id ip; - unsigned int i; id result; int seq_num = [self _newMsgNumber]; diff --git a/Source/NSData.m b/Source/NSData.m index 2fe2674ac..97e50dc04 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -1028,6 +1028,7 @@ failure: fromZone: (NSZone*)zone { [self subclassResponsibility: _cmd]; + return nil; } - (void) deserializeTypeTag: (unsigned char*)tag @@ -2261,8 +2262,6 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) - (id) initWithBytes: (const void*)aBuffer length: (unsigned)bufferSize { - struct shmid_ds buf; - shmid = -1; if (aBuffer && bufferSize) { @@ -2453,7 +2452,6 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) - (id) initWithCoder: (NSCoder*)aCoder { unsigned l; - void *b; [aCoder decodeValueOfObjCType: @encode(unsigned long) at: &l]; if (l) @@ -2929,8 +2927,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) - (id) initWithCapacity: (unsigned)bufferSize { - struct shmid_ds buf; - int e; + int e; shmid = shmget(IPC_PRIVATE, bufferSize, IPC_CREAT|VM_ACCESS); if (shmid == -1) /* Created memory? */ @@ -2992,9 +2989,8 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) { if (size != capacity) { - void *tmp; - struct shmid_ds buf; - int newid; + void *tmp; + int newid; newid = shmget(IPC_PRIVATE, size, IPC_CREAT|VM_ACCESS); if (newid == -1) /* Created memory? */ diff --git a/Source/NSDate.m b/Source/NSDate.m index 82c7f829c..748cd36f1 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -192,8 +192,8 @@ GSTimeNow() + (id) dateWithNaturalLanguageString: (NSString*)string { - [self dateWithNaturalLanguageString: string - locale: nil]; + return [self dateWithNaturalLanguageString: string + locale: nil]; } + (id) dateWithNaturalLanguageString: (NSString*)string @@ -222,7 +222,6 @@ GSTimeNow() int modYear = 0; int modDay = 0; int D, M, Y; - int modWeek; int h = 12; int m = 0; int s = 0; @@ -366,7 +365,6 @@ GSTimeNow() unsigned c = [ymw count]; NSString *yname = [ymw objectAtIndex: 0]; NSString *mname = c > 1 ? [ymw objectAtIndex: 1] : nil; - NSString *wname = c > 2 ? [ymw objectAtIndex: 2] : nil; NSArray *early = [locale objectForKey: NSEarlierTimeDesignations]; NSArray *later = [locale objectForKey: NSLaterTimeDesignations]; @@ -1242,10 +1240,11 @@ GSTimeNow() return self; } -- (id) allocWithZone: (NSZone*)z ++ (id) allocWithZone: (NSZone*)z { [NSException raise: NSInternalInconsistencyException format: @"Attempt to allocate fixed date"]; + return nil; } - (id) copyWithZone: (NSZone*)z diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index e0f56a3ef..f75e56055 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -166,11 +166,10 @@ static Class NSMutableDictionary_concrete_class; return [self count]; } -- initWithObjects: (NSArray*)objects forKeys: (NSArray*)keys +- (id) initWithObjects: (NSArray*)objects forKeys: (NSArray*)keys { int objectCount = [objects count]; id os[objectCount], ks[objectCount]; - int i; if (objectCount != [keys count]) { @@ -465,7 +464,7 @@ compareIt(id o1, id o2, void* context) return (int)[o1 performSelector: f->s withObject: o2]; } -- (NSArray*)keysSortedByValueUsingSelector: (SEL)comp +- (NSArray*) keysSortedByValueUsingSelector: (SEL)comp { struct foo info; id k; @@ -474,6 +473,7 @@ compareIt(id o1, id o2, void* context) info.s = comp; info.i = [self methodForSelector: @selector(objectForKey:)]; k = [[self allKeys] sortedArrayUsingFunction: compareIt context: &info]; + return k; } - (NSArray*) objectsForKeys: (NSArray*)keys notFoundMarker: (id)marker diff --git a/Source/NSDistributedNotificationCenter.m b/Source/NSDistributedNotificationCenter.m index b22325bad..b99195931 100644 --- a/Source/NSDistributedNotificationCenter.m +++ b/Source/NSDistributedNotificationCenter.m @@ -52,7 +52,7 @@ NSString *NSLocalNotificationCenterType = @interface NSDistributedNotificationCenter (Private) - (void) _connect; -- (id) _invalidated: (NSNotification*)notification; +- (void) _invalidated: (NSNotification*)notification; - (void) postNotificationName: (NSString*)name object: (NSString*)object userInfo: (NSData*)info @@ -369,7 +369,7 @@ NSLog(@"Connection to GDNC server established.\n"); } } -- (id) _invalidated: (NSNotification*)notification +- (void) _invalidated: (NSNotification*)notification { id connection = [notification object]; diff --git a/Source/NSGAttributedString.m b/Source/NSGAttributedString.m index e7fe616a9..cfeda8d2c 100644 --- a/Source/NSGAttributedString.m +++ b/Source/NSGAttributedString.m @@ -494,7 +494,7 @@ _attributesAtIndexEffectiveRange( - (void) replaceCharactersInRange: (NSRange)range withString: (NSString*)aString { - unsigned tmpLength, arrayIndex, arraySize, cnt, location, moveLocations; + unsigned tmpLength, arrayIndex, arraySize, cnt, moveLocations; NSRange effectiveRange; NSDictionary *attrs; unsigned afterRangeLoc; diff --git a/Source/NSGCString.m b/Source/NSGCString.m index f1a01cdf3..ca36d3f5a 100644 --- a/Source/NSGCString.m +++ b/Source/NSGCString.m @@ -929,7 +929,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self, return obj; } -- mutableCopyWithZone: (NSZone*)z +- (id) mutableCopyWithZone: (NSZone*)z { NSGMutableCString *obj; @@ -944,6 +944,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self, obj->_hash = _hash; } } + return obj; } - (void) deleteCharactersInRange: (NSRange)range diff --git a/Source/NSGCountedSet.m b/Source/NSGCountedSet.m index 48b52fc3f..ab44f8d7a 100644 --- a/Source/NSGCountedSet.m +++ b/Source/NSGCountedSet.m @@ -31,7 +31,7 @@ #include -#define GSI_MAP_RETAIN_VAL(X) X +#define GSI_MAP_RETAIN_VAL(X) #define GSI_MAP_RELEASE_VAL(X) #define GSI_MAP_KTYPES GSUNION_OBJ #define GSI_MAP_VTYPES GSUNION_INT diff --git a/Source/NSGDictionary.m b/Source/NSGDictionary.m index 96d58fd76..7d85db684 100644 --- a/Source/NSGDictionary.m +++ b/Source/NSGDictionary.m @@ -30,6 +30,7 @@ #include #include +#include #include /* diff --git a/Source/NSHost.m b/Source/NSHost.m index 5c311b5e2..f066d307f 100644 --- a/Source/NSHost.m +++ b/Source/NSHost.m @@ -39,6 +39,7 @@ #include #include #include +#include #endif /* __WIN32__ */ static NSLock *_hostCacheLock = nil; diff --git a/Source/NSLock.m b/Source/NSLock.m index 9c288871e..4ca138f51 100644 --- a/Source/NSLock.m +++ b/Source/NSLock.m @@ -199,8 +199,6 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException"; // Acquiring and release the lock - (void) lockWhenCondition: (int)value { - int result; - CHECK_RECURSIVE_CONDITION_LOCK (mutex); if (objc_mutex_lock (mutex) == -1) diff --git a/Source/NSNotificationCenter.m b/Source/NSNotificationCenter.m index 40ac9c960..dd0e93dfc 100644 --- a/Source/NSNotificationCenter.m +++ b/Source/NSNotificationCenter.m @@ -27,10 +27,13 @@ #include #include -#include -#include #include +#include +#include +typedef struct { + @defs(NSNotification) +} NotificationStruct; /* * Garbage collection considerations - @@ -44,132 +47,440 @@ * the garbage collector. */ +struct NCTbl; /* Notification Center Table structure */ /* * Observation structure - One of these objects is created for * each -addObserver... request. It holds the requested selector, - * name and object. Each struct is placed - * (1) in one LinkedList, as keyed by the NAME/OBJECT parameters - * (2) in an array, as keyed by the OBSERVER + * name and object. Each struct is placed in one LinkedList, + * as keyed by the NAME/OBJECT parameters. */ typedef struct Obs { - NSString *name; - id object; - id observer; - SEL selector; - IMP method; - struct Obs *next; - unsigned retained; + id observer; /* Object to receive message. */ + SEL selector; /* Method selector. */ + IMP method; /* Method implementation. */ + struct Obs *next; /* Next item in linked list. */ + int retained; /* Retain count for structure. */ + struct NCTbl *link; /* Pointer back to chunk table */ } Observation; #define ENDOBS ((Observation*)-1) -static void FreeObs(Observation *o) +static SEL hSel = @selector(hash); +static SEL eqSel = @selector(isEqualToString:); + +static unsigned (*cHash)(id, SEL); +static unsigned (*uHash)(id, SEL); +static BOOL (*cEqual)(id, SEL, id); +static BOOL (*uEqual)(id, SEL, id); + +static inline unsigned doHash(NSString* key) { - if (o->retained) - o->retained--; + if (key == nil) + { + return 0; + } + else if (((gsaddr)key) & 1) + { + return (unsigned)(gsaddr)key; + } else - NSZoneFree(NSDefaultMallocZone(), o); + { + Class c = fastClassOfInstance(key); + + if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString + || c == _fastCls._NXConstantString) + return (*cHash)(key, hSel); + if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString) + return (*uHash)(key, hSel); + return [key hash]; + } } -static void FreeList(Observation *list) +static inline BOOL doEqual(NSString* key1, NSString* key2) +{ + if (key1 == key2) + { + return YES; + } + else if ((((gsaddr)key1) & 1) || key1 == nil) + { + return NO; + } + else + { + Class c = fastClassOfInstance(key1); + + if (c == _fastCls._NSGString) + return (*uEqual)(key1, eqSel, key2); + else + return (*cEqual)(key1, eqSel, key2); + } +} + +/* + * Setup for inline operation on arrays of Observers. + */ +static void listFree(Observation *list); +static void obsRetain(Observation *o); +static void obsFree(Observation *o); + +#define GSI_ARRAY_TYPES 0 +#define GSI_ARRAY_EXTRA Observation* + +#define GSI_ARRAY_RELEASE(X) obsFree(X.ext) +#define GSI_ARRAY_RETAIN(X) obsRetain(X.ext) + +#include + +#define GSI_MAP_RETAIN_KEY(X) X +#define GSI_MAP_RELEASE_KEY(X) ((((gsaddr)X.obj) & 1) == 0 \ + ? RELEASE(X.obj) : X.obj) +#define GSI_MAP_HASH(X) doHash(X.obj) +#define GSI_MAP_EQUAL(X,Y) doEqual(X.obj, Y.obj) + +#define GSI_MAP_RETAIN_VAL(X) X +#define GSI_MAP_RELEASE_VAL(X) +#define GSI_MAP_KTYPES GSUNION_OBJ|GSUNION_INT +#define GSI_MAP_VTYPES GSUNION_PTR +#define GSI_MAP_VEXTRA Observation* +#define GSI_MAP_EXTRA 1 + +#include + +/* + * An NC table is used to keep track of memory allocated to store + * Observation structures. When an Observation is removed from the + * notification center, it's memory is returned to the free list of + * the chunk table, rather than being released to the general + * memory allocation system. This means that, once a large numbner + * of observers have been registered, memory usage will never shrink + * even if the observers are removed. On the other hand, the process + * of adding and removing observers is speeded up. + * + * As another minor aid to performance, we also maintain a cache of + * the map tables used to keep mappings of notification objects to + * lists of Observations. This lets us avoid the overhead of creating + * and destroying map tables when we are frequently adding and removing + * notification observations. + * + * Performance is however, not the primary reason for using this + * structure - it provides a neat way to ensure that observers pointed + * to by the Observation structures are not seen as being in use by + * the garbage collection mechanism. + */ +#define CHUNKSIZE 128 +#define CACHESIZE 16 +typedef struct NCTbl { + Observation *wildcard; /* Get ALL messages. */ + GSIMapTable nameless; /* Get messages for any name. */ + GSIMapTable named; /* Getting named messages only. */ + GSIArray array; /* Temp store during posting. */ + unsigned lockCount; /* Count recursive operations. */ + NSRecursiveLock *_lock; /* Lock out other threads. */ + IMP lImp; + IMP uImp; + BOOL lockingDisabled; + BOOL immutableInPost; + + Observation *freeList; + Observation **chunks; + unsigned numChunks; + GSIMapTable cache[CACHESIZE]; + short chunkIndex; + short cacheIndex; +} NCTable; + +#define TABLE ((NCTable*)table) +#define WILDCARD (TABLE->wildcard) +#define NAMELESS (TABLE->nameless) +#define NAMED (TABLE->named) +#define ARRAY (TABLE->array) +#define LOCKCOUNT (TABLE->lockCount) + +static Observation *obsNew(NCTable* t) +{ + Observation *obs; + + if (t->freeList == 0) + { + Observation *block; + + if (t->chunkIndex == CHUNKSIZE) + { + unsigned size; + + t->numChunks++; + size = t->numChunks * sizeof(Observation*); + t->chunks = (Observation**)NSZoneRealloc(NSDefaultMallocZone(), + t->chunks, size); + size = CHUNKSIZE * sizeof(Observation); +#if GS_WITH_GC + t->chunks[t->numChunks - 1] + = (Observation*)NSZoneMallocAtomic(NSDefaultMallocZone(), size); +#else + t->chunks[t->numChunks - 1] + = (Observation*)NSZoneMalloc(NSDefaultMallocZone(), size); +#endif + t->chunkIndex = 0; + } + block = t->chunks[t->numChunks - 1]; + t->freeList = &block[t->chunkIndex]; + t->chunkIndex++; + t->freeList->link = 0; + } + obs = t->freeList; + t->freeList = (Observation*)obs->link; + obs->link = (void*)t; + return obs; +} + +static GSIMapTable mapNew(NCTable *t) +{ + if (t->cacheIndex > 0) + return t->cache[--t->cacheIndex]; + else + { + GSIMapTable m; + + m = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIMapTable_t)); + GSIMapInitWithZoneAndCapacity(m, NSDefaultMallocZone(), 2); + return m; + } +} + +static void mapFree(NCTable *t, GSIMapTable m) +{ + if (t->cacheIndex < CACHESIZE) + t->cache[t->cacheIndex++] = m; + else + { + GSIMapEmptyMap(m); + NSZoneFree(NSDefaultMallocZone(), (void*)m); + } +} + +static void endNCTable(NCTable *t) +{ + unsigned i; + GSIMapNode n0; + Observation *l; + + /* + * free the temporary storage area for observations about to receive msgs. + */ + GSIArrayEmpty(t->array); + NSZoneFree(NSDefaultMallocZone(), (void*)t->array); + + /* + * Free observations without notification names or numbers. + */ + listFree(t->wildcard); + + /* + * Free lists of observations without notification names. + */ + n0 = t->nameless->firstNode; + while (n0 != 0) + { + l = (Observation*)n0->value.ptr; + n0 = n0->nextInMap; + listFree(l); + } + GSIMapEmptyMap(t->nameless); + NSZoneFree(NSDefaultMallocZone(), (void*)t->nameless); + + /* + * Free lists of observations keyed by name and observer. + */ + n0 = t->named->firstNode; + while (n0 != 0) + { + GSIMapTable m = (GSIMapTable)n0->value.ptr; + GSIMapNode n1 = m->firstNode; + + n0 = n0->nextInMap; + + while (n1 != 0) + { + l = (Observation*)n1->value.ptr; + n1 = n1->nextInMap; + listFree(l); + } + GSIMapEmptyMap(m); + NSZoneFree(NSDefaultMallocZone(), (void*)m); + } + GSIMapEmptyMap(t->named); + NSZoneFree(NSDefaultMallocZone(), (void*)t->named); + + for (i = 0; i < t->numChunks; i++) + NSZoneFree(NSDefaultMallocZone(), t->chunks[i]); + for (i = 0; i < t->cacheIndex; i++) + { + GSIMapEmptyMap(t->cache[i]); + NSZoneFree(NSDefaultMallocZone(), (void*)t->cache[i]); + } + NSZoneFree(NSDefaultMallocZone(), t->chunks); + NSZoneFree(NSDefaultMallocZone(), t); + + TEST_RELEASE(t->_lock); +} + +static NCTable *newNCTable() +{ + NCTable *t; + + t = (NCTable*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(NCTable)); + memset((void*)t, '\0', sizeof(NCTable)); + t->chunkIndex = CHUNKSIZE; + t->wildcard = ENDOBS; + + t->nameless = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIMapTable_t)); + GSIMapInitWithZoneAndCapacity(t->nameless, NSDefaultMallocZone(), 16); + + t->named = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIMapTable_t)); + GSIMapInitWithZoneAndCapacity(t->named, NSDefaultMallocZone(), 128); + + t->array = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIArray_t)); + GSIArrayInitWithZoneAndCapacity(t->array, NSDefaultMallocZone(), 16); + + return t; +} + +static inline void lockNCTable(NCTable* t) +{ + if (t->_lock != nil && t->lockingDisabled == NO) + (*t->lImp)(t->_lock, @selector(lock)); + t->lockCount++; +} + +static inline void unlockNCTable(NCTable* t) +{ + t->lockCount--; + if (t->_lock != nil && t->lockingDisabled == NO) + (*t->uImp)(t->_lock, @selector(unlock)); +} + +static void obsFree(Observation *o) +{ + NSCAssert(o->retained >= 0, NSInternalInconsistencyException); + if (o->retained-- == 0) + { + NCTable *t = o->link; + + o->link = (NCTable*)t->freeList; + t->freeList = o; + } +} + +static void listFree(Observation *list) { while (list != ENDOBS) { Observation *o = list; list = o->next; - FreeObs(o); + o->next = 0; + obsFree(o); } } -static void *RetainObs(Observation *o) +/* + * NB. We need to explicitly set the 'next' field of any observation + * we remove to be zero so that, if it currently exists in an array + * of observations being posted, the posting code can notice that it + * has been removed from its linked list. + */ +static Observation *listPurge(Observation *list, id observer) { - o->retained++; - return o; + Observation *tmp; + + while (list != ENDOBS && list->observer == observer) + { + tmp = list->next; + list->next = 0; + obsFree(list); + list = tmp; + } + if (list != ENDOBS) + { + tmp = list; + while (tmp->next != ENDOBS) + { + if (tmp->next->observer == observer) + { + Observation *next = tmp->next; + + tmp->next = next->next; + next->next = 0; + obsFree(next); + } + else + { + tmp = tmp->next; + } + } + } + return list; } -static unsigned oHash(void* t, Observation *o) -{ - unsigned hash; - - hash = (unsigned)(gsaddr)o->object ^ (unsigned)(gsaddr)o->selector; - if (o->name != nil) - hash ^= [o->name hash]; - return hash; -} - -static BOOL oIsEqual(void* t, Observation *o1, Observation* o2) -{ - if (o1->object != o2->object) - return NO; - if (o1->selector != o2->selector) - return NO; - if (o1->name != o2->name) - return [o1->name isEqual: o2->name]; - return YES; -} - -static void* oRetain(void* t, Observation *o) +static void obsRetain(Observation *o) { o->retained++; } -static void oRelease(void* t, Observation *o) -{ - if (o->retained) - o->retained--; - else - NSZoneFree(NSDefaultMallocZone(), o); -} - -const NSHashTableCallBacks ObsCallBacks = -{ - (NSHT_hash_func_t) oHash, - (NSHT_isEqual_func_t) oIsEqual, - (NSHT_retain_func_t) oRetain, - (NSHT_release_func_t) oRelease, - (NSHT_describe_func_t) 0 -}; - -const NSMapTableValueCallBacks ObsMapCallBacks = -{ - (NSMT_retain_func_t) oRetain, - (NSMT_release_func_t) oRelease, - (NSMT_describe_func_t) 0 -}; - /* - * Setup for inline operation on arrays of Observers. + * Utility function to remove all the observations from a particular + * map table node that match the specified observer. If the observer + * is nil, then all observations are removed. + * If the list of observations in the map node is emptied, the node is + * removed from the map. */ +static inline void +purgeMapNode(GSIMapTable map, GSIMapNode node, id observer) +{ + Observation *list = node->value.ext; -#define GSI_ARRAY_TYPES 0 -#define GSI_ARRAY_EXTRA Observation* + if (observer == 0) + { + listFree(list); + GSIMapRemoveKey(map, node->key); + } + else + { + Observation *start = list; -#define GSI_ARRAY_RELEASE(X) FreeObs(((X).ext)) -#define GSI_ARRAY_RETAIN(X) RetainObs(((X).ext)) + list = listPurge(list, observer); + if (list == ENDOBS) + { + /* + * The list is empty so remove from map. + */ + GSIMapRemoveKey(map, node->key); + } + else if (list != start) + { + /* + * The list is not empty, but we have changed its + * start, so we must place the new head in the map. + */ + node->value.ext = list; + } + } +} -#include - -#define GSI_MAP_RETAIN_VAL(X) X -#define GSI_MAP_RELEASE_VAL(X) -#define GSI_MAP_KTYPES GSUNION_OBJ -#define GSI_MAP_VTYPES GSUNION_PTR - -#include - -#if GS_WITH_GC /* * In order to hide pointers from garbage collection, we OR in an * extra bit. This should be ok for the objects we deal with * which are all aligned on 4 or 8 byte boundaries on all the machines * I know of. + * + * We also use this trick to differentiate between map table keys that + * should be treated as objects (notification names) and thise that + * should be treated as pointers (notification objects) */ -#define CHEATGC(X) (void*)(gsaddr)((X) | 1) -#else -#define CHEATGC(X) (void*)(gsaddr)(X) -#endif +#define CHEATGC(X) (id)(((gsaddr)X) | 1) @@ -180,21 +491,26 @@ const NSMapTableValueCallBacks ObsMapCallBacks = There is no need to mutex locking of this variable. */ static NSNotificationCenter *default_center = nil; -static SEL remSel = @selector(_removeObservationFromList:); -static void (*remImp)(NSNotificationCenter*, SEL, Observation*) = 0; + (void) initialize { if (self == [NSNotificationCenter class]) { + cHash = (unsigned (*)(id, SEL)) + [NSGCString instanceMethodForSelector: hSel]; + uHash = (unsigned (*)(id, SEL)) + [NSGString instanceMethodForSelector: hSel]; + cEqual = (BOOL (*)(id, SEL, id)) + [NSGCString instanceMethodForSelector: eqSel]; + uEqual = (BOOL (*)(id, SEL, id)) + [NSGString instanceMethodForSelector: eqSel]; + /* * Do alloc and init separately so the default center can refer to * the 'default_center' variable during initialisation. */ default_center = [self alloc]; [default_center init]; - remImp = (void (*)(NSNotificationCenter*, SEL, Observation*)) - [self instanceMethodForSelector: remSel]; } } @@ -206,18 +522,41 @@ static void (*remImp)(NSNotificationCenter*, SEL, Observation*) = 0; /* Initializing. */ +- (void) _becomeThreaded: (NSNotification*)notification +{ + unsigned count; + + TABLE->_lock = [NSRecursiveLock new]; + TABLE->lImp = [TABLE->_lock methodForSelector: @selector(lock)]; + TABLE->uImp = [TABLE->_lock methodForSelector: @selector(unlock)]; + count = LOCKCOUNT; + /* + * If we start locking inside a method that would normally have been + * locked, we must lock the lock enough times so that when we leave + * the method the number of unlocks will match. + */ + while (count-- > 0) + { + (*TABLE->lImp)(TABLE->_lock, @selector(lock)); + } +} + - (id) init { [super init]; - wildcard = ENDOBS; - nameless = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, - NSNonOwnedPointerMapValueCallBacks, 0); - observers = NSCreateMapTable(NSNonOwnedPointerOrNullMapKeyCallBacks, - NSNonOwnedPointerMapValueCallBacks, 0); - named = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIMapTable_t)); - GSIMapInitWithZoneAndCapacity((GSIMapTable)named,NSDefaultMallocZone(),128); - - _lock = [NSRecursiveLock new]; + TABLE = newNCTable(); + if ([NSThread isMultiThreaded]) + { + [self _becomeThreaded: nil]; + } + else + { + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector(_becomeThreaded:) + name: NSWillBecomeMultiThreadedNotification + object: nil]; + } return self; } @@ -226,56 +565,15 @@ static void (*remImp)(NSNotificationCenter*, SEL, Observation*) = 0; { [self gcFinalize]; - TEST_RELEASE(_lock); [super dealloc]; } - (void) gcFinalize { - NSMapEnumerator enumerator; - id o; - GSIMapTable f = (GSIMapTable)named; - GSIMapNode n; - Observation *l; - NSHashTable *h; - NSMapTable *m; - /* - * Free observations without notification names or numbers. + * Release all memory used to store Observations etc. */ - FreeList(wildcard); - - /* - * Free lists of observations without notification names. - */ - enumerator = NSEnumerateMapTable(nameless); - while (NSNextMapEnumeratorPair(&enumerator, (void**)&o, (void**)&l)) - { - FreeList(l); - } - NSFreeMapTable(nameless); - - /* - * Free lists of observations keyed by name and observer. - */ - n = f->firstNode; - while (n != 0) - { - NSFreeMapTable((NSMapTable*)n->value.ptr); - n = n->nextInMap; - } - GSIMapEmptyMap(f); - NSZoneFree(f->zone, named); - - /* - * Free tables of observations keyed by observer. - */ - enumerator = NSEnumerateMapTable(observers); - while (NSNextMapEnumeratorPair(&enumerator, (void**)&o, (void**)&h)) - { - NSFreeHashTable(h); - } - NSFreeMapTable(observers); + endNCTable(TABLE); } @@ -286,10 +584,11 @@ static void (*remImp)(NSNotificationCenter*, SEL, Observation*) = 0; name: (NSString*)name object: (id)object { - NSHashTable *h; + IMP method; + Observation *list; Observation *o; - unsigned i; - IMP m; + GSIMapTable m; + GSIMapNode n; if (observer == nil) [NSException raise: NSInvalidArgumentException @@ -305,221 +604,262 @@ static void (*remImp)(NSNotificationCenter*, SEL, Observation*) = 0; NSStringFromSelector(selector)); #endif - m = [observer methodForSelector: selector]; - if (m == 0) + method = [observer methodForSelector: selector]; + if (method == 0) [NSException raise: NSInvalidArgumentException format: @"Observer can not handle specified selector"]; - /* - * NB. Do Atomic malloc for garbage collection - so objects pointed to by - * the Observation structure will be garbage collected. - */ -#if GS_WITH_GC - o = (Observation*)NSZoneMallocAtomic(NSDefaultMallocZone(), - sizeof(Observation)); -#else - o = (Observation*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(Observation)); -#endif - o->name = name; - o->object = object; + lockNCTable(TABLE); + + if (TABLE->immutableInPost == YES && LOCKCOUNT > 1) + { + unlockNCTable(TABLE); + [NSException raise: NSInvalidArgumentException + format: @"Attempt to add to immutable center."]; + } + + o = obsNew(TABLE); o->selector = selector; - o->method = m; + o->method = method; o->observer = observer; o->retained = 0; o->next = 0; - [_lock lock]; + if (object != nil) + object = CHEATGC(object); - /* Record the Observation one of the linked lists */ + /* + * Record the Observation in one of the linked lists. + * + * NB. It is possible to register an observr for a notification more than + * once - in which case, the observer will receive multiple messages when + * the notification is posted... odd, but the MacOS-X docs specify this. + */ if (name) { - NSMapTable *m; - Observation *list; - GSIMapNode n; - /* * Locate the map table for this name - create it if not present. */ - n = GSIMapNodeForKey((GSIMapTable)named, (GSIMapKey)name); + n = GSIMapNodeForKey(NAMED, (GSIMapKey)name); if (n == 0) { - m = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, - ObsMapCallBacks, 0); + Class c; + + m = mapNew(TABLE); /* - * If this is the first observation for the given name, we take a + * As this is the first observation for the given name, we take a * copy of the name so it cannot be mutated while in the map. + * Also ensure the copy is one of our well-known string types so + * we can optimise it's hash and isEqualToString:. */ name = [name copyWithZone: NSDefaultMallocZone()]; - o->name = name; - GSIMapAddPair((GSIMapTable)named, (GSIMapKey)name, - (GSIMapVal)(void*)m); - RELEASE(name); + c = fastClassOfInstance(name); + if (c != _fastCls._NSGString && c != _fastCls._NSGCString + && c != _fastCls._NXConstantString) + { + id n = [[NSGString alloc] initWithString: name]; + RELEASE(name); + name = n; + } + GSIMapAddPair(NAMED, (GSIMapKey)name, (GSIMapVal)(void*)m); } else { - m = (NSMapTable*)n->value.ptr; - /* - * We record the name string that is used as the map key, so we - * don't need to retain it in the observation. - */ - o->name = n->key.obj; + m = (GSIMapTable)n->value.ptr; } /* * Add the observation to the list for the correct object. */ - list = (Observation*)NSMapGet(m, CHEATGC(object)); - if (list == 0) + n = GSIMapNodeForSimpleKey(m, (GSIMapKey)object); + if (n == 0) { o->next = ENDOBS; - NSMapInsert(m, CHEATGC(object), (void*)(gsaddr)o); + GSIMapAddPair(m, (GSIMapKey)object, (GSIMapVal)o); } else { + list = (Observation*)n->value.ptr; o->next = list->next; list->next = o; } } else if (object) { - Observation *list; - - list = (Observation*)NSMapGet(nameless, CHEATGC(object)); - if (list == 0) + n = GSIMapNodeForSimpleKey(NAMELESS, (GSIMapKey)object); + if (n == 0) { o->next = ENDOBS; - NSMapInsert(nameless, CHEATGC(object), (void*)(gsaddr)o); + GSIMapAddPair(NAMELESS, (GSIMapKey)object, (GSIMapVal)o); } else { + list = (Observation*)n->value.ptr; o->next = list->next; list->next = o; } } else { - o->next = wildcard; - wildcard = o; + o->next = WILDCARD; + WILDCARD = o; } - /* - * Record the notification request in a hash table keyed by OBSERVER. - * If it already exists, return without doing anything. - */ - h = (NSHashTable*)NSMapGet(observers, CHEATGC(observer)); - if (h == 0) - { - h = NSCreateHashTableWithZone(ObsCallBacks, 4, NSDefaultMallocZone()); - NSMapInsert(observers, CHEATGC(observer), (void*)h); - } - if (NSHashGet(h, (void*)o) != 0) - { - NSZoneFree(NSDefaultMallocZone(), o); - [_lock unlock]; - return; - } - NSHashInsert(h, (void*)o); - - [_lock unlock]; + unlockNCTable(TABLE); } -/* - * Method for internal use only. - */ -- (void) _removeObservationFromList: (Observation*)o +- (void) removeObserver: (id)observer + name: (NSString*)name + object: (id)object { - NSAssert(o->next != 0, NSInternalInconsistencyException); + if (name == nil && object == nil && observer == nil) + [NSException raise: NSInvalidArgumentException + format: @"Attempt to remove nil observer/name/object"]; - /* Remove the Observation from its list */ + /* + * NB. The removal algorithm depends on an implementation characteristic + * of our map tables - while enumerating a table, it is safe to remove + * the entry returned by the enumerator. + */ - if (o->name) + lockNCTable(TABLE); + + if (TABLE->immutableInPost == YES && LOCKCOUNT > 1) { - NSMapTable *m; - Observation *list; + unlockNCTable(TABLE); + [NSException raise: NSInvalidArgumentException + format: @"Attempt to remove from immutable center."]; + } + + if (object != nil) + object = CHEATGC(object); + + if (name == nil && object == nil) + { + WILDCARD = listPurge(WILDCARD, observer); + } + + if (name == nil) + { + GSIMapNode n; + + /* + * First try removing all named items set for this object. + */ + n = NAMED->firstNode; + while (n != 0) + { + GSIMapTable m = (GSIMapTable)n->value.ptr; + NSString *thisName = (NSString*)n->key.obj; + GSIMapNode n1; + + n = n->nextInMap; + if (object == nil) + { + /* + * Nil object and nil name, so we step through all the maps + * keyed under the current name and remove all the objects + * that match the observer. + */ + n1 = m->firstNode; + while (n1 != 0) + { + GSIMapNode next = n1->nextInMap; + + purgeMapNode(m, n1, observer); + n1 = next; + } + } + else + { + /* + * Nil name, but non-nil object - we locate the map for the + * specified object, and remove all the items that match + * the observer. + */ + n1 = GSIMapNodeForSimpleKey(m, (GSIMapKey)object); + if (n1 != 0) + { + purgeMapNode(m, n1, observer); + } + } + /* + * If we removed all the observations keyed under this name, we + * must remove the map table too. + */ + if (m->nodeCount == 0) + { + mapFree(TABLE, m); + GSIMapRemoveKey(NAMED, (GSIMapKey)thisName); + } + } + + /* + * Now remove unnamed items + */ + if (object == nil) + { + n = NAMELESS->firstNode; + while (n != 0) + { + GSIMapNode next = n->nextInMap; + + purgeMapNode(NAMELESS, n, observer); + n = next; + } + } + else + { + n = GSIMapNodeForSimpleKey(NAMELESS, (GSIMapKey)object); + if (n != 0) + { + purgeMapNode(NAMELESS, n, observer); + } + } + } + else + { + GSIMapTable m; GSIMapNode n; /* * Locate the map table for this name. */ - n = GSIMapNodeForKey((GSIMapTable)named, (GSIMapKey)o->name); - NSAssert(n != 0, NSInternalInconsistencyException); - m = (NSMapTable*)n->value.ptr; - - list = (Observation*)NSMapGet(m, CHEATGC(o->object)); - NSAssert(list != 0, NSInternalInconsistencyException); - if (list == o) + n = GSIMapNodeForKey(NAMED, (GSIMapKey)name); + if (n == 0) { - if (list->next == ENDOBS) + unlockNCTable(TABLE); + return; /* Nothing to do. */ + } + m = (GSIMapTable)n->value.ptr; + + if (object == nil) + { + n = m->firstNode; + while (n != 0) { - NSMapRemove(m, CHEATGC(o->object)); - if (NSCountMapTable(m) == 0) - { - GSIMapRemoveKey((GSIMapTable)named, (GSIMapKey)o->name); - } - } - else - { - NSMapInsert(m, CHEATGC(o->object), (void*)(gsaddr)o->next); + GSIMapNode next = n->nextInMap; + + purgeMapNode(m, n, observer); + n = next; } } else { - while (list->next != o) + n = GSIMapNodeForSimpleKey(m, (GSIMapKey)object); + if (n != 0) { - list = list->next; + purgeMapNode(m, n, observer); } - list->next = o->next; + } + if (m->nodeCount == 0) + { + mapFree(TABLE, m); + GSIMapRemoveKey(NAMED, (GSIMapKey)name); } } - else if (o->object) - { - Observation *list; - - list = (Observation*)NSMapGet(nameless, CHEATGC(o->object)); - NSAssert(list != 0, NSInternalInconsistencyException); - if (list == o) - { - if (list->next == ENDOBS) - { - NSMapRemove(nameless, CHEATGC(o->object)); - } - else - { - NSMapInsert(nameless, CHEATGC(o->object), - (void*)(gsaddr)o->next); - } - } - else - { - while (list->next != o) - { - list = list->next; - } - list->next = o->next; - } - } - else - { - if (wildcard == o) - { - wildcard = o->next; - } - else - { - Observation *list = wildcard; - - while (list->next != o) - { - list = list->next; - } - list->next = o->next; - } - } - /* - * Mark this observation as not being in a list. - */ - o->next = 0; + unlockNCTable(TABLE); } /* Remove all records pertaining to OBSERVER. For instance, this @@ -527,193 +867,11 @@ static void (*remImp)(NSNotificationCenter*, SEL, Observation*) = 0; - (void) removeObserver: (id)observer { - NSHashEnumerator enumerator; - NSHashTable *h; - Observation *obs; - if (observer == nil) [NSException raise: NSInvalidArgumentException format: @"Nil observer passed to removeObserver:"]; - [_lock lock]; - - h = (NSHashTable*)NSMapGet(observers, CHEATGC(observer)); - - if (h == 0) - return; - - enumerator = NSEnumerateHashTable(h); - while ((obs = (Observation*)NSNextHashEnumeratorItem(&enumerator)) != 0) - { - (*remImp)(self, remSel, obs); - } - - NSFreeHashTable(h); - NSMapRemove(observers, CHEATGC(observer)); - - [_lock unlock]; -} - - -/* Remove the notification requests for the given parameters. As with - adding an observation request, nil NAME or OBJECT act as wildcards. */ - -- (void) removeObserver: (id)observer - name: (NSString*)name - object: (id)object -{ - GSIArray a; - - /* - * If both NAME and OBJECT are nil, this call is the same as - * -removeObserver:, so just call it. - */ - if (name == nil && object == nil) - { - [self removeObserver: observer]; - return; - } - - /* We are now guaranteed that at least one of NAME and OBJECT is non-nil. */ - - [_lock lock]; - - a = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIArray_t)); - GSIArrayInitWithZoneAndCapacity(a, NSDefaultMallocZone(), 128); - - if (name) - { - NSMapTable *m; - GSIMapNode n; - - /* - * Locate items with specified name (if any). - */ - n = GSIMapNodeForKey((GSIMapTable)named, (GSIMapKey)name); - if (n) - m = (NSMapTable*)n->value.ptr; - else - m = 0; - if (m != 0) - { - if (object == nil) - { - Observation *list; - NSMapEnumerator e; - id o; - - /* - * Make a list of items for ALL objects. - */ - e = NSEnumerateMapTable(m); - while (NSNextMapEnumeratorPair(&e, (void**)&o, (void**)&list)) - { - while (list != ENDOBS) - { - if (observer == nil || observer == list->observer) - { - GSIArrayAddItem(a, (GSIArrayItem)list); - } - list = list->next; - } - } - } - else - { - Observation *list; - - /* - * Make a list of items matching specific object. - */ - list = (Observation*)NSMapGet(m, CHEATGC(object)); - if (list != 0) - { - while (list != ENDOBS) - { - if (observer == nil || observer == list->observer) - { - GSIArrayAddItem(a, (GSIArrayItem)list); - } - list = list->next; - } - } - } - } - } - else - { - Observation *list; - NSMapTable *m; - GSIMapNode n; - - /* - * Make a list of items matching specific object with NO names - */ - list = (Observation*)NSMapGet(nameless, CHEATGC(object)); - if (list != 0) - { - while (list != ENDOBS) - { - if (observer == nil || observer == list->observer) - { - GSIArrayAddItem(a, (GSIArrayItem)list); - } - list = list->next; - } - } - - /* - * Add items for ALL names. - */ - n = ((GSIMapTable)named)->firstNode; - while (n != 0) - { - m = (NSMapTable*)n->value.ptr; - n = n->nextInMap; - list = (Observation*)NSMapGet(m, CHEATGC(object)); - if (list != 0) - { - while (list != ENDOBS) - { - if (observer == nil || observer == list->observer) - { - GSIArrayAddItem(a, (GSIArrayItem)list); - } - list = list->next; - } - } - } - } - - if (GSIArrayCount(a) > 0) - { - id lastObs = nil; - NSHashTable *h = 0; - unsigned count = GSIArrayCount(a); - unsigned i; - Observation *o; - - for (i = 0; i < count; i++) - { - o = GSIArrayItemAtIndex(a, i).ext; - (*remImp)(self, remSel, o); - if (h == 0 || lastObs != o->observer) - { - h = (NSHashTable*)NSMapGet(observers, CHEATGC(o->observer)); - lastObs = o->observer; - } - NSHashRemove(h, (void*)o); - if (NSCountHashTable(h) == 0) - { - NSMapRemove(observers, CHEATGC(lastObs)); - } - } - } - - GSIArrayEmpty(a); - NSZoneFree(a->zone, (void*)a); - - [_lock unlock]; + [self removeObserver: observer name: nil object: nil]; } @@ -729,151 +887,246 @@ static void (*remImp)(NSNotificationCenter*, SEL, Observation*) = 0; NSString *n_name; id n_object; Observation *o; - GSIArray a; unsigned count; - unsigned i; + volatile GSIArray a; + unsigned arrayBase; if (notification == nil) [NSException raise: NSInvalidArgumentException format: @"Tried to post a nil notification."]; - n_name = [notification name]; - n_object = [notification object]; + n_name = ((NotificationStruct*)notification)->_name; + n_object = ((NotificationStruct*)notification)->_object; + if (n_object != nil) + n_object = CHEATGC(n_object); if (n_name == nil) [NSException raise: NSInvalidArgumentException format: @"Tried to post a notification with no name."]; - [_lock lock]; + lockNCTable(TABLE); - a = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIArray_t)); - GSIArrayInitWithZoneAndCapacity(a, NSDefaultMallocZone(), 16); + a = ARRAY; + /* + * If this is a recursive posting of a notification, the array will already + * be in use, so we restrict our operation to array indices beyond the end + * of those used by the posting that cuased this one. + */ + arrayBase = GSIArrayCount(a); +#if 0 NS_DURING +#endif { - /* - * Post the notification to all the observers that specified neither - * NAME nor OBJECT. - */ - for (o = wildcard; o != ENDOBS; o = o->next) - { - GSIArrayAddItem(a, (GSIArrayItem)o); - } - count = GSIArrayCount(a); - while (count-- > 0) - { - o = GSIArrayItemAtIndex(a, count).ext; - if (o->next != 0) - (*o->method)(o->observer, o->selector, notification); - GSIArrayRemoveItemAtIndex(a, count); - } + GSIMapNode n; + GSIMapTable m; /* - * Post the notification to all the observers that specified OBJECT, - * but didn't specify NAME. + * If the notification center guarantees that it will be immutable + * while a notification is being posted, we can simply send the + * message to each matching Observation. Otherwise, we put the + * Observations in a temporary array before starting sending the + * messages, so any changes to the tables don't mess us up. */ - if (n_object) + if (TABLE->immutableInPost) { - o = (Observation*)NSMapGet(nameless, CHEATGC(n_object)); - if (o != 0) + /* + * Post the notification to all the observers that specified neither + * NAME nor OBJECT. + */ + for (o = WILDCARD; o != ENDOBS; o = o->next) { - while (o != ENDOBS) + (*o->method)(o->observer, o->selector, notification); + } + + /* + * Post the notification to all the observers that specified OBJECT, + * but didn't specify NAME. + */ + if (n_object) + { + n = GSIMapNodeForSimpleKey(NAMELESS, (GSIMapKey)n_object); + if (n != 0) + { + o = n->value.ext; + while (o != ENDOBS) + { + (*o->method)(o->observer, o->selector, notification); + o = o->next; + } + } + } + + /* + * Post the notification to all the observers of NAME, except those + * observers with a non-nil OBJECT that doesn't match the + * notification's OBJECT). + */ + if (n_name) + { + n = GSIMapNodeForKey(NAMED, (GSIMapKey)n_name); + if (n) + m = (GSIMapTable)n->value.ptr; + else + m = 0; + if (m != 0) + { + /* + * First, observers with a matching object. + */ + n = GSIMapNodeForSimpleKey(m, (GSIMapKey)n_object); + if (n != 0) + { + o = n->value.ext; + while (o != ENDOBS) + { + (*o->method)(o->observer, o->selector, + notification); + o = o->next; + } + } + + if (n_object != nil) + { + /* + * Now observers with a nil object. + */ + n = GSIMapNodeForSimpleKey(m, (GSIMapKey)nil); + if (n != 0) + { + o = n->value.ext; + while (o != ENDOBS) + { + (*o->method)(o->observer, o->selector, + notification); + o = o->next; + } + } + } + } + } + } + else + { + /* + * Post the notification to all the observers that specified neither + * NAME nor OBJECT. + */ + if (o != ENDOBS) + { + for (o = WILDCARD; o != ENDOBS; o = o->next) { GSIArrayAddItem(a, (GSIArrayItem)o); - o = o->next; } count = GSIArrayCount(a); - while (count-- > 0) + while (count-- > arrayBase) { o = GSIArrayItemAtIndex(a, count).ext; if (o->next != 0) (*o->method)(o->observer, o->selector, notification); - GSIArrayRemoveItemAtIndex(a, count); } + GSIArrayRemoveItemsFromIndex(a, arrayBase); } - } - /* - * Post the notification to all the observers of NAME, except those - * observers with a non-nill OBJECT that doesn't match the - * notification's OBJECT). - */ - if (n_name) - { - NSMapTable *m; - GSIMapNode n; - - n = GSIMapNodeForKey((GSIMapTable)named, (GSIMapKey)n_name); - if (n) - m = (NSMapTable*)n->value.ptr; - else - m = 0; - if (m != 0) + /* + * Post the notification to all the observers that specified OBJECT, + * but didn't specify NAME. + */ + if (n_object) { - /* - * First, observers with a matching object. - */ - o = (Observation*)NSMapGet(m, CHEATGC(n_object)); - if (o != 0) + n = GSIMapNodeForSimpleKey(NAMELESS, (GSIMapKey)n_object); + if (n != 0) { + o = n->value.ext; while (o != ENDOBS) { GSIArrayAddItem(a, (GSIArrayItem)o); o = o->next; } count = GSIArrayCount(a); - while (count-- > 0) + while (count-- > arrayBase) { o = GSIArrayItemAtIndex(a, count).ext; - if (o->next != 0) + if (o->next != 0) (*o->method)(o->observer, o->selector, notification); - GSIArrayRemoveItemAtIndex(a, count); } + GSIArrayRemoveItemsFromIndex(a, arrayBase); } + } - if (n_object != nil) + /* + * Post the notification to all the observers of NAME, except those + * observers with a non-nill OBJECT that doesn't match the + * notification's OBJECT). + */ + if (n_name) + { + n = GSIMapNodeForKey(NAMED, (GSIMapKey)n_name); + if (n) + m = (GSIMapTable)n->value.ptr; + else + m = 0; + if (m != 0) { /* - * Now observers with a nil object. + * First, observers with a matching object. */ - o = (Observation*)NSMapGet(m, CHEATGC(0)); - if (o != 0) + n = GSIMapNodeForSimpleKey(m, (GSIMapKey)n_object); + if (n != 0) { + o = n->value.ext; while (o != ENDOBS) { GSIArrayAddItem(a, (GSIArrayItem)o); o = o->next; } - count = GSIArrayCount(a); - while (count-- > 0) + } + + if (n_object != nil) + { + /* + * Now observers with a nil object. + */ + n = GSIMapNodeForSimpleKey(m, (GSIMapKey)nil); + if (n != 0) { - o = GSIArrayItemAtIndex(a, count).ext; - if (o->next != 0) - (*o->method)(o->observer, o->selector, - notification); - GSIArrayRemoveItemAtIndex(a, count); + o = n->value.ext; + while (o != ENDOBS) + { + GSIArrayAddItem(a, (GSIArrayItem)o); + o = o->next; + } } } + + count = GSIArrayCount(a); + while (count-- > arrayBase) + { + o = GSIArrayItemAtIndex(a, count).ext; + if (o->next != 0) + (*o->method)(o->observer, o->selector, + notification); + } + GSIArrayRemoveItemsFromIndex(a, arrayBase); } } } } +#if 0 NS_HANDLER { /* * If we had a problem - release memory and unlock before going on. */ - GSIArrayEmpty(a); - NSZoneFree(a->zone, (void*)a); - [_lock unlock]; + GSIArrayRemoveItemsFromIndex(ARRAY, arrayBase); + unlockNCTable(TABLE); [localException raise]; } NS_ENDHANDLER +#endif - GSIArrayEmpty(a); - NSZoneFree(a->zone, (void*)a); - [_lock unlock]; + unlockNCTable(TABLE); } - (void) postNotificationName: (NSString*)name @@ -894,3 +1147,57 @@ static void (*remImp)(NSNotificationCenter*, SEL, Observation*) = 0; @end +@implementation NSNotificationCenter (GNUstep) + +- (BOOL) setImmutableInPost: (BOOL)flag +{ + BOOL old; + + lockNCTable(TABLE); + + if (self == default_center) + { + unlockNCTable(TABLE); + [NSException raise: NSInvalidArgumentException + format: @"Can't change behavior of default center."]; + } + if (LOCKCOUNT > 1) + { + unlockNCTable(TABLE); + [NSException raise: NSInvalidArgumentException + format: @"Can't change behavior during post."]; + } + + old = TABLE->immutableInPost; + TABLE->immutableInPost = flag; + unlockNCTable(TABLE); + + return old; +} + +- (BOOL) setLockingDisabled: (BOOL)flag +{ + BOOL old; + + lockNCTable(TABLE); + if (self == default_center) + { + unlockNCTable(TABLE); + [NSException raise: NSInvalidArgumentException + format: @"Can't change locking of default center."]; + } + if (LOCKCOUNT > 1) + { + unlockNCTable(TABLE); + [NSException raise: NSInvalidArgumentException + format: @"Can't change locking during post."]; + } + + old = TABLE->lockingDisabled; + TABLE->lockingDisabled = flag; + unlockNCTable(TABLE); + return old; +} + +@end + diff --git a/Source/NSNotificationQueue.m b/Source/NSNotificationQueue.m index 817d0b7a3..6a4265220 100644 --- a/Source/NSNotificationQueue.m +++ b/Source/NSNotificationQueue.m @@ -97,7 +97,7 @@ currentList() @implementation NotificationQueueList -+ (void)registerQueue: (NSNotificationQueue*)q ++ (void) registerQueue: (NSNotificationQueue*)q { NotificationQueueList* list; NotificationQueueList* elem; @@ -116,7 +116,8 @@ currentList() if (list->queue == q) return; /* Queue already registered. */ - elem = NSAllocateObject(self, 0, NSDefaultMallocZone()); + elem = (NotificationQueueList*)NSAllocateObject(self, 0, + NSDefaultMallocZone()); elem->queue = q; list->next = elem; } diff --git a/Source/NSNumber.m b/Source/NSNumber.m index c3e6f4b0c..67c039ff5 100644 --- a/Source/NSNumber.m +++ b/Source/NSNumber.m @@ -22,6 +22,7 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include diff --git a/Source/NSObjCRuntime.m b/Source/NSObjCRuntime.m index 50f545467..2ae616431 100644 --- a/Source/NSObjCRuntime.m +++ b/Source/NSObjCRuntime.m @@ -70,6 +70,7 @@ NSGetSizeAndAlignment(const char *typePtr, unsigned *sizep, unsigned *alignp) *sizep = info.size; if (alignp) *alignp = info.align; + return typePtr; } BOOL diff --git a/Source/NSObject.m b/Source/NSObject.m index ba7823789..b708dcdd7 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -42,6 +42,8 @@ #include +extern BOOL __objc_responds_to(id, SEL); + fastCls _fastCls; /* Structure to cache classes. */ fastImp _fastImp; /* Structure to cache methods. */ @@ -352,6 +354,9 @@ fastZone(NSObject *object) inline NSObject * NSAllocateObject (Class aClass, unsigned extraBytes, NSZone *zone) { +#ifndef NDEBUG + extern void GSDebugAllocationAdd(Class); +#endif id new = nil; int size = aClass->instance_size + extraBytes + sizeof(struct obj_layout); if (CLS_ISCLASS (aClass)) @@ -378,6 +383,9 @@ NSAllocateObject (Class aClass, unsigned extraBytes, NSZone *zone) inline void NSDeallocateObject(NSObject *anObject) { +#ifndef NDEBUG + extern void GSDebugAllocationRemove(Class); +#endif if ((anObject!=nil) && CLS_ISCLASS(((id)anObject)->class_pointer)) { obj o = &((obj)anObject)[-1]; diff --git a/Source/NSPage.m b/Source/NSPage.m index a81b5a09e..7cab6a8a8 100644 --- a/Source/NSPage.m +++ b/Source/NSPage.m @@ -98,6 +98,10 @@ NSRoundUpToMultipleOfPageSize (unsigned bytes) return ((bytes % a) ? ((bytes / a + 1) * a) : bytes); } +#if __linux__ +#include +#endif + unsigned NSRealMemoryAvailable () { diff --git a/Source/NSPortNameServer.m b/Source/NSPortNameServer.m index a02a604b0..08e615365 100644 --- a/Source/NSPortNameServer.m +++ b/Source/NSPortNameServer.m @@ -39,6 +39,7 @@ #include #include #include +#include /* * Protocol definition stuff for talking to gdomap process. @@ -278,7 +279,7 @@ static NSPortNameServer *defaultServer = nil; #ifndef HAVE_INET_ATON svrs->s_addr = inet_addr("127.0.0.1"); #else - inet_aton("127.0.0.1", &svrs->s_addr); + inet_aton("127.0.0.1", (struct in_addr *)&svrs->s_addr); #endif } @@ -549,6 +550,7 @@ static NSPortNameServer *defaultServer = nil; NS_ENDHANDLER [self _close]; [serverLock unlock]; + return YES; } - (void) removePortForName: (NSString*)name diff --git a/Source/NSScanner.m b/Source/NSScanner.m index 30703e87e..5b32dbd1c 100644 --- a/Source/NSScanner.m +++ b/Source/NSScanner.m @@ -510,7 +510,7 @@ if ((scanLocation < len) && ((c == 'e') || (c == 'E'))) { int expval; - int expScanLocation = scanLocation; + scanLocation++; if ([self _scanInt: &expval]) { diff --git a/Source/NSSerializer.m b/Source/NSSerializer.m index e92482a30..2bf4ab974 100644 --- a/Source/NSSerializer.m +++ b/Source/NSSerializer.m @@ -46,9 +46,9 @@ /* * Setup for inline operation of string map tables. */ -#define GSI_MAP_RETAIN_KEY(X) X +#define GSI_MAP_RETAIN_KEY(X) #define GSI_MAP_RELEASE_KEY(X) -#define GSI_MAP_RETAIN_VAL(X) X +#define GSI_MAP_RETAIN_VAL(X) #define GSI_MAP_RELEASE_VAL(X) #define GSI_MAP_HASH(X) [(X).obj hash] #define GSI_MAP_EQUAL(X,Y) [(X).obj isEqualToString: (Y).obj] @@ -58,7 +58,7 @@ /* * Setup for inline operation of string arrays. */ -#define GSI_ARRAY_RETAIN(X) X +#define GSI_ARRAY_RETAIN(X) #define GSI_ARRAY_RELEASE(X) #define GSI_ARRAY_TYPES GSUNION_OBJ @@ -149,7 +149,7 @@ endSerializerInfo(_NSSerializerInfo* info) GSIMapEmptyMap(&info->map); } -static id +static void serializeToInfo(id object, _NSSerializerInfo* info) { Class c = fastClass(object); diff --git a/Source/NSString.m b/Source/NSString.m index 8ae4a2f85..5a630d16a 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -616,11 +616,9 @@ handle_printf_atsign (FILE *stream, - (id) initWithContentsOfFile: (NSString*)path { - unsigned char *buff; NSStringEncoding enc; id d = [NSData dataWithContentsOfFile: path]; const unsigned char *test=[d bytes]; - unsigned len = [d length]; if (d == nil) return nil; if (test && (((test[0]==0xFF) && (test[1]==0xFE)) || ((test[1]==0xFF) && (test[0]==0xFE)))) @@ -1130,7 +1128,6 @@ handle_printf_atsign (FILE *stream, forRange: (NSRange)aRange { unichar thischar; - BOOL done; unsigned start, end, len; len = [self length]; @@ -1139,50 +1136,54 @@ handle_printf_atsign (FILE *stream, start = aRange.location; if (startIndex) - if (start==0) - *startIndex=0; - else - { - start--; - while (start > 0) - { - BOOL done = NO; + { + if (start==0) + { + *startIndex=0; + } + else + { + start--; + while (start > 0) + { + BOOL done = NO; - thischar = [self characterAtIndex: start]; - switch(thischar) - { - case (unichar)0x000A: - case (unichar)0x000D: - case (unichar)0x2028: - case (unichar)0x2029: - done = YES; - break; - default: - start--; - break; - }; - if (done) - break; - }; - if (start == 0) - { - thischar = [self characterAtIndex: start]; - switch(thischar) - { - case (unichar)0x000A: - case (unichar)0x000D: - case (unichar)0x2028: - case (unichar)0x2029: - start++; - break; - default: - break; - }; - } - else - start++; - *startIndex = start; - }; + thischar = [self characterAtIndex: start]; + switch(thischar) + { + case (unichar)0x000A: + case (unichar)0x000D: + case (unichar)0x2028: + case (unichar)0x2029: + done = YES; + break; + default: + start--; + break; + }; + if (done) + break; + }; + if (start == 0) + { + thischar = [self characterAtIndex: start]; + switch(thischar) + { + case (unichar)0x000A: + case (unichar)0x000D: + case (unichar)0x2028: + case (unichar)0x2029: + start++; + break; + default: + break; + }; + } + else + start++; + *startIndex = start; + } + } if (lineEndIndex || contentsEndIndex) { @@ -1759,7 +1760,6 @@ handle_printf_atsign (FILE *stream, - (NSString*) stringByExpandingTildeInPath { - unichar *s; NSString *homedir; NSRange first_slash_range; diff --git a/Source/NSTask.m b/Source/NSTask.m index 0d7c00a70..2921a4e1f 100644 --- a/Source/NSTask.m +++ b/Source/NSTask.m @@ -37,8 +37,11 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -548,7 +551,7 @@ extern char *objc_find_executable(const char *name); } chdir(path); - execve(executable, args, envl); + execve(executable, (char**)args, (char**)envl); exit(-1); } else diff --git a/Source/NSThread.m b/Source/NSThread.m index 96e2b5b9a..81828fd86 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/Source/NSTimeZone.m b/Source/NSTimeZone.m index bcf5177bf..d7da9669a 100644 --- a/Source/NSTimeZone.m +++ b/Source/NSTimeZone.m @@ -729,7 +729,7 @@ decode (const void *ptr) detail = [[NSConcreteTimeZoneDetail alloc] initWithTimeZone: zone - withAbbrev: abbrevsArray[types[i].abbr_idx] + withAbbrev: abbrevsArray[(int)types[i].abbr_idx] withOffset: types[i].offset withDST: (types[i].isdst > 0)]; [detailsArray addObject: detail]; diff --git a/Source/NSURL.m b/Source/NSURL.m index 918e44254..bbcbb6ec3 100644 --- a/Source/NSURL.m +++ b/Source/NSURL.m @@ -1,7 +1,7 @@ /* NSUrl.m - Class NSURL Copyright (C) 1999 Free Software Foundation, Inc. - Written by: Manuel Guesdon + Written by: Manuel Guesdon Date: Jan 1999 This file is part of the GNUstep Library. @@ -22,7 +22,7 @@ */ /* -Note from Manuel Guesdon: +Note from Manuel Guesdon: * I've made some test to compare apple NSURL results and GNUstep NSURL results but as there this class is not very documented, some function may be incorrect @@ -52,448 +52,449 @@ NSString* NSURLPartKey_fragment=@"fragment"; NSString* NSURLPartKey_parameterString=@"parameterString"; NSString* NSURLPartKey_query=@"query"; -//=================================================================================== +//============================================================================= @implementation NSURL -//----------------------------------------------------------------------------------- -+(id)fileURLWithPath:(NSString*)_path +//----------------------------------------------------------------------------- ++ (id) fileURLWithPath: (NSString*)_path { - return [[[NSURL alloc] initFileURLWithPath:_path] + return [[[NSURL alloc] initFileURLWithPath: _path] autorelease]; -}; +} -//----------------------------------------------------------------------------------- -+(id)URLWithString:(NSString*)_urlString +//----------------------------------------------------------------------------- ++ (id)URLWithString: (NSString*)_urlString { - return [[[NSURL alloc] initWithString:_urlString] + return [[[NSURL alloc] initWithString: _urlString] autorelease]; -}; +} -//----------------------------------------------------------------------------------- -+(id)URLWithString:(NSString*)_urlString - relativeToURL:(NSURL*)_baseURL +//----------------------------------------------------------------------------- ++ (id)URLWithString: (NSString*)_urlString + relativeToURL: (NSURL*)_baseURL { - return [[[NSURL alloc] initWithString:_urlString - relativeToURL:_baseURL] + return [[[NSURL alloc] initWithString: _urlString + relativeToURL: _baseURL] autorelease]; -}; +} -//----------------------------------------------------------------------------------- --(id)initWithScheme:(NSString*)_scheme - host:(NSString*)_host - path:(NSString*)_path +//----------------------------------------------------------------------------- +- (id) initWithScheme: (NSString*)_scheme + host: (NSString*)_host + path: (NSString*)_path { NSString* _urlString=nil; if (_host) - _urlString=[NSString stringWithFormat:@"%@://%@",_scheme,_host]; + _urlString=[NSString stringWithFormat: @"%@: //%@",_scheme,_host]; else - _urlString=[NSString stringWithFormat:@"%@:",_scheme]; + _urlString=[NSString stringWithFormat: @"%@: ",_scheme]; if (_path) - _urlString=[_urlString stringByAppendingString:_path]; - self=[self initWithString:_urlString]; + _urlString=[_urlString stringByAppendingString: _path]; + self=[self initWithString: _urlString]; return self; -}; +} -//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //Non Standard Function --(id)initWithScheme:(NSString*)_scheme - host:(NSString*)_host - port:(NSNumber*)_port - path:(NSString*)_path +- (id) initWithScheme: (NSString*)_scheme + host: (NSString*)_host + port: (NSNumber*)_port + path: (NSString*)_path { NSString* tmpHost=nil; if (_port) - tmpHost=[NSString stringWithFormat:@"%@:%@",_host,_port]; + tmpHost=[NSString stringWithFormat: @"%@: %@",_host,_port]; else tmpHost=_host; - self=[self initWithScheme:_scheme - host:tmpHost - path:_path]; + self=[self initWithScheme: _scheme + host: tmpHost + path: _path]; return self; -}; +} -//----------------------------------------------------------------------------------- -//Do a initWithScheme:NSFileScheme host:nil path:_path --(id)initFileURLWithPath:(NSString*)_path +//----------------------------------------------------------------------------- +//Do a initWithScheme: NSFileScheme host: nil path: _path +- (id) initFileURLWithPath: (NSString*)_path { - self=[self initWithScheme:NSURLFileScheme - host:nil - path:_path]; + self=[self initWithScheme: NSURLFileScheme + host: nil + path: _path]; return self; -}; +} -//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // urlString is escaped --(id)initWithString:(NSString*)_urlString +- (id) initWithString: (NSString*)_urlString { self=[self init]; ASSIGNCOPY(urlString,_urlString); return self; -}; +} -//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //urlString!=nil // urlString is escaped --(id)initWithString:(NSString*)_urlString - relativeToURL:(NSURL*)_baseURL +- (id) initWithString: (NSString*)_urlString + relativeToURL: (NSURL*)_baseURL { self=[self init]; ASSIGNCOPY(urlString,_urlString); ASSIGNCOPY(baseURL,_baseURL); return self; -}; +} -//----------------------------------------------------------------------------------- --(void)dealloc +//----------------------------------------------------------------------------- +- (void) dealloc { DESTROY(urlString); DESTROY(baseURL); [super dealloc]; } -//----------------------------------------------------------------------------------- --(id)copyWithZone: (NSZone*)zone +//----------------------------------------------------------------------------- +- (id) copyWithZone: (NSZone*)zone { if (NSShouldRetainWithZone(self, zone) == NO) - return [[isa allocWithZone: zone] initWithString:urlString - relativeToURL:baseURL]; + return [[isa allocWithZone: zone] initWithString: urlString + relativeToURL: baseURL]; else return [self retain]; -}; +} -//----------------------------------------------------------------------------------- --(void)encodeWithCoder:(NSCoder*)aCoder +//----------------------------------------------------------------------------- +- (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; - [aCoder encodeObject:urlString]; - [aCoder encodeObject:baseURL]; + [aCoder encodeObject: urlString]; + [aCoder encodeObject: baseURL]; //FIXME? clients ? -}; +} -//----------------------------------------------------------------------------------- --(id)initWithCoder: (NSCoder*)aCoder +//----------------------------------------------------------------------------- +- (id) initWithCoder: (NSCoder*)aCoder { self = [super initWithCoder: aCoder]; - [aCoder decodeValueOfObjCType: @encode(id) at:&urlString]; - [aCoder decodeValueOfObjCType: @encode(id) at:&baseURL]; + [aCoder decodeValueOfObjCType: @encode(id) at: &urlString]; + [aCoder decodeValueOfObjCType: @encode(id) at: &baseURL]; //FIXME? clients ? return self; -}; +} -//----------------------------------------------------------------------------------- --(NSString*)description +//----------------------------------------------------------------------------- +- (NSString*) description { NSString* dscr=urlString; if (baseURL) - dscr=[dscr stringByAppendingFormat:@" -- %@",baseURL]; + dscr=[dscr stringByAppendingFormat: @" -- %@",baseURL]; return dscr; -}; +} -//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // Non Standard Function --(NSString*)baseURLAbsolutePart +- (NSString*) baseURLAbsolutePart { if (baseURL) { NSString* suffix=[baseURL path]; NSString* tmp=nil; if ([baseURL query]) - suffix=[suffix stringByAppendingFormat:@"?%@",[baseURL query]]; - // /test?aa=bb&cc=dd -- http://user:passwd@www.gnustep.org:80/apache - // ==> http://user:passwd@www.gnustep.org:80/ - tmp=[[baseURL absoluteString]stringWithoutSuffix:suffix]; + suffix=[suffix stringByAppendingFormat: @"?%@",[baseURL query]]; + // /test?aa=bb&cc=dd -- http: //user: passwd@www.gnustep.org: 80/apache + // ==> http: //user: passwd@www.gnustep.org: 80/ + tmp=[[baseURL absoluteString]stringWithoutSuffix: suffix]; - // ==> http://user:passwd@www.gnustep.org:80 - if ([tmp hasSuffix:@"/"]) - tmp=[tmp stringWithoutSuffix:@"/"]; + // ==> http: //user: passwd@www.gnustep.org: 80 + if ([tmp hasSuffix: @"/"]) + tmp=[tmp stringWithoutSuffix: @"/"]; return tmp; } else return @""; -}; +} -//----------------------------------------------------------------------------------- --(NSString*)absoluteString +//----------------------------------------------------------------------------- +- (NSString*) absoluteString { NSString* absString=nil; if (baseURL) { - // /test?aa=bb&cc=dd -- http://user:passwd@www.gnustep.org:80/apache - // ==> http://user:passwd@www.gnustep.org:80 + // /test?aa=bb&cc=dd -- http: //user: passwd@www.gnustep.org: 80/apache + // ==> http: //user: passwd@www.gnustep.org: 80 absString=[self baseURLAbsolutePart]; - if ([urlString hasPrefix:@"/"]) - absString=[absString stringByAppendingString:urlString]; + if ([urlString hasPrefix: @"/"]) + absString=[absString stringByAppendingString: urlString]; else - absString=[absString stringByAppendingFormat:@"/%@",urlString]; + absString=[absString stringByAppendingFormat: @"/%@",urlString]; } else absString=urlString; return absString; -}; +} -//----------------------------------------------------------------------------------- --(NSString*)relativeString +//----------------------------------------------------------------------------- +- (NSString*) relativeString { return urlString; -}; +} -//----------------------------------------------------------------------------------- --(NSURL*)baseURL +//----------------------------------------------------------------------------- +- (NSURL*) baseURL { return baseURL; -}; +} -//----------------------------------------------------------------------------------- --(NSURL*)absoluteURL +//----------------------------------------------------------------------------- +- (NSURL*) absoluteURL { if (!baseURL) return self; else - return [NSURL URLWithString:[self absoluteString]]; -}; + return [NSURL URLWithString: [self absoluteString]]; +} -//----------------------------------------------------------------------------------- --(NSString*)scheme +//----------------------------------------------------------------------------- +- (NSString*) scheme { NSString* scheme=nil; NSString* absoluteString=[self absoluteString]; - NSRange range=[absoluteString rangeOfString:@"://"]; + NSRange range=[absoluteString rangeOfString: @": //"]; if (range.length>0) - scheme=[absoluteString substringToIndex:range.location]; + scheme=[absoluteString substringToIndex: range.location]; return scheme; -}; +} -//----------------------------------------------------------------------------------- --(NSString*)resourceSpecifier +//----------------------------------------------------------------------------- +- (NSString*) resourceSpecifier { NSString* absoluteString=[self absoluteString]; - NSRange range=[absoluteString rangeOfString:@"://"]; + NSRange range=[absoluteString rangeOfString: @": //"]; if (range.length>0) - return [absoluteString substringFromIndex:range.location+1]; + return [absoluteString substringFromIndex: range.location+1]; else return absoluteString; -}; +} -//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //Non Standard Function --(NSDictionary*)explode +- (NSDictionary*) explode { NSMutableDictionary* elements=nil; NSString* resourceSpecifier=[self resourceSpecifier]; - if ([resourceSpecifier hasPrefix:@"//"]) + if ([resourceSpecifier hasPrefix: @"//"]) { int index=2; NSRange range; elements=[[NSMutableDictionary new] autorelease]; - if (![[self scheme] isEqualToString:NSURLFileScheme]) + if (![[self scheme] isEqualToString: NSURLFileScheme]) { - range=[resourceSpecifier rangeOfString:@"/" - options:0 - range:NSMakeRange(index,[resourceSpecifier length]-index)]; + range=[resourceSpecifier rangeOfString: @"/" + options: 0 + range: NSMakeRange(index,[resourceSpecifier length]-index)]; if (range.length>0) { - NSString* userPasswordHostPort=[resourceSpecifier substringWithRange:NSMakeRange(index,range.location-index)]; + NSString* userPasswordHostPort=[resourceSpecifier substringWithRange: NSMakeRange(index,range.location-index)]; NSString* userPassword=nil; NSString* hostPort=nil; index=range.location; - range=[userPasswordHostPort rangeOfString:@"@"]; + range=[userPasswordHostPort rangeOfString: @"@"]; if (range.length>0) { if (range.location>0) - userPassword=[userPasswordHostPort substringToIndex:range.location]; + userPassword=[userPasswordHostPort substringToIndex: range.location]; if (range.location+1<[userPasswordHostPort length]) - hostPort=[userPasswordHostPort substringFromIndex:range.location+1]; + hostPort=[userPasswordHostPort substringFromIndex: range.location+1]; } else hostPort=userPasswordHostPort; if (userPassword) { - range=[userPassword rangeOfString:@":"]; + range=[userPassword rangeOfString: @": "]; if (range.length>0) { if (range.location>0) - [elements setObject:[userPassword substringToIndex:range.location] - forKey:NSURLPartKey_user]; + [elements setObject: [userPassword substringToIndex: range.location] + forKey: NSURLPartKey_user]; if (range.location+1<[userPassword length]) - [elements setObject:[userPassword substringFromIndex:range.location+1] - forKey:NSURLPartKey_password]; + [elements setObject: [userPassword substringFromIndex: range.location+1] + forKey: NSURLPartKey_password]; } else - [elements setObject:userPassword - forKey:NSURLPartKey_user]; - }; + [elements setObject: userPassword + forKey: NSURLPartKey_user]; + } if (hostPort) { - range=[hostPort rangeOfString:@":"]; + range=[hostPort rangeOfString: @": "]; if (range.length>0) { if (range.location>0) - [elements setObject:[hostPort substringToIndex:range.location] - forKey:NSURLPartKey_host]; + [elements setObject: [hostPort substringToIndex: range.location] + forKey: NSURLPartKey_host]; if (range.location+1<[hostPort length]) - [elements setObject:[NSNumber valueFromString: - [hostPort substringFromIndex:range.location+1]] - forKey:NSURLPartKey_port]; + [elements setObject: [NSNumber valueFromString: + [hostPort substringFromIndex: range.location+1]] + forKey: NSURLPartKey_port]; } else - [elements setObject:hostPort - forKey:NSURLPartKey_host]; + [elements setObject: hostPort + forKey: NSURLPartKey_host]; }; - }; + } } else index--; //To Take a / - range=[resourceSpecifier rangeOfString:@"?" - options:0 - range:NSMakeRange(index,[resourceSpecifier length]-index)]; + range=[resourceSpecifier rangeOfString: @"?" + options: 0 + range: NSMakeRange(index,[resourceSpecifier length]-index)]; if (range.length>0) { if (range.location>0) - [elements setObject:[resourceSpecifier substringWithRange:NSMakeRange(index,range.location-index)] - forKey:NSURLPartKey_path]; + [elements setObject: [resourceSpecifier substringWithRange: NSMakeRange(index,range.location-index)] + forKey: NSURLPartKey_path]; if (range.location+1<[resourceSpecifier length]) - [elements setObject:[resourceSpecifier substringFromIndex:range.location+1] - forKey:NSURLPartKey_query]; + [elements setObject: [resourceSpecifier substringFromIndex: range.location+1] + forKey: NSURLPartKey_query]; } else - [elements setObject:[resourceSpecifier substringFromIndex:index] - forKey:NSURLPartKey_path]; + [elements setObject: [resourceSpecifier substringFromIndex: index] + forKey: NSURLPartKey_path]; } else { - [NSException raise:NSGenericException - format:@"'%@' is a bad URL",self]; - }; + [NSException raise: NSGenericException + format: @"'%@' is a bad URL",self]; + } return elements; -}; +} -//----------------------------------------------------------------------------------- --(NSString*)host +//----------------------------------------------------------------------------- +- (NSString*) host { - return [[self explode] objectForKey:NSURLPartKey_host]; -}; + return [[self explode] objectForKey: NSURLPartKey_host]; +} -//----------------------------------------------------------------------------------- --(NSNumber*)port; +//----------------------------------------------------------------------------- +- (NSNumber*) port; { - return [[self explode] objectForKey:NSURLPartKey_port]; -}; + return [[self explode] objectForKey: NSURLPartKey_port]; +} -//----------------------------------------------------------------------------------- --(NSString*)user; +//----------------------------------------------------------------------------- +- (NSString*) user; { - return [[self explode] objectForKey:NSURLPartKey_user]; -}; + return [[self explode] objectForKey: NSURLPartKey_user]; +} -//----------------------------------------------------------------------------------- --(NSString*)password; +//----------------------------------------------------------------------------- +- (NSString*) password; { - return [[self explode] objectForKey:NSURLPartKey_password]; -}; + return [[self explode] objectForKey: NSURLPartKey_password]; +} -//----------------------------------------------------------------------------------- --(NSString*)path; +//----------------------------------------------------------------------------- +- (NSString*) path; { - return [[self explode] objectForKey:NSURLPartKey_path]; -}; + return [[self explode] objectForKey: NSURLPartKey_path]; +} -//----------------------------------------------------------------------------------- --(NSString*)fragment; +//----------------------------------------------------------------------------- +- (NSString*) fragment; { - return [[self explode] objectForKey:NSURLPartKey_fragment]; -}; + return [[self explode] objectForKey: NSURLPartKey_fragment]; +} -//----------------------------------------------------------------------------------- --(NSString*)parameterString; +//----------------------------------------------------------------------------- +- (NSString*) parameterString; { - return [[self explode] objectForKey:NSURLPartKey_parameterString]; -}; + return [[self explode] objectForKey: NSURLPartKey_parameterString]; +} -//----------------------------------------------------------------------------------- --(NSString*)query; +//----------------------------------------------------------------------------- +- (NSString*) query; { - return [[self explode] objectForKey:NSURLPartKey_query]; -}; + return [[self explode] objectForKey: NSURLPartKey_query]; +} -//----------------------------------------------------------------------------------- --(NSString*)relativePath +//----------------------------------------------------------------------------- +- (NSString*) relativePath { //FIXME? return [self path]; -}; +} -//----------------------------------------------------------------------------------- --(BOOL)isFileURL +//----------------------------------------------------------------------------- +- (BOOL) isFileURL { - return [[self scheme] isEqualToString:NSURLFileScheme]; -}; + return [[self scheme] isEqualToString: NSURLFileScheme]; +} -//----------------------------------------------------------------------------------- --(NSURL*)standardizedURL +//----------------------------------------------------------------------------- +- (NSURL*) standardizedURL { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(void) URLHandle:(NSURLHandle*)sender - resourceDataDidBecomeAvailable:(NSData*)newData +//----------------------------------------------------------------------------- +- (void) URLHandle: (NSURLHandle*)sender + resourceDataDidBecomeAvailable: (NSData*)newData { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)URLHandleResourceDidBeginLoading:(NSURLHandle*)sender +//----------------------------------------------------------------------------- +- (void)URLHandleResourceDidBeginLoading: (NSURLHandle*)sender { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)URLHandleResourceDidFinishLoading:(NSURLHandle*)sender +//----------------------------------------------------------------------------- +- (void)URLHandleResourceDidFinishLoading: (NSURLHandle*)sender { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)URLHandleResourceDidCancelLoading:(NSURLHandle*)sender +//----------------------------------------------------------------------------- +- (void)URLHandleResourceDidCancelLoading: (NSURLHandle*)sender { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void) URLHandle:(NSURLHandle*)sender - resourceDidFailLoadingWithReason:(NSString*)reason +//----------------------------------------------------------------------------- +- (void) URLHandle: (NSURLHandle*)sender + resourceDidFailLoadingWithReason: (NSString*)reason { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //FIXME: delete these fn when NSURL will be validated -+(void)test ++ (void) test { NSURL* url2; NSURL* url3; - NSURL* url=[NSURL URLWithString:@"http://user:passwd@www.gnustep.org:80/apache"]; - url2=[NSURL URLWithString:@"/test?aa=bb&cc=dd" relativeToURL:url]; - url3=[NSURL URLWithString:@"test?aa=bb&cc=dd" relativeToURL:url]; + NSURL* url=[NSURL URLWithString: @"http: //user: passwd@www.gnustep.org: 80/apache"]; + url2=[NSURL URLWithString: @"/test?aa=bb&cc=dd" relativeToURL: url]; + url3=[NSURL URLWithString: @"test?aa=bb&cc=dd" relativeToURL: url]; NSLog(@"===url==="); - [NSURL testPrint:url]; + [NSURL testPrint: url]; NSLog(@"===url2==="); - [NSURL testPrint:url2]; + [NSURL testPrint: url2]; NSLog(@"===url3==="); - [NSURL testPrint:url3]; -}; + [NSURL testPrint: url3]; +} -+(void)testPrint:(NSURL*)url ++ (void) testPrint: (NSURL*)url { id _baseURL=nil; id _urlString=nil; @@ -521,92 +522,97 @@ NSString* NSURLPartKey_query=@"query"; NSLog(@"*scheme: %@",[url scheme]); NSLog(@"*resourceSpecifier: %@",[url resourceSpecifier]); NSLog(@"*description: %@",[url description]); -}; +} @end -//=================================================================================== +//============================================================================= @implementation NSURL (NSURLLoading) -//----------------------------------------------------------------------------------- --(NSData*)resourceDataUsingCache:(BOOL)shouldUseCache +//----------------------------------------------------------------------------- +- (NSData*) resourceDataUsingCache: (BOOL)shouldUseCache { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(void)loadResourceDataNotifyingClient:(id)client - usingCache:(BOOL)shouldUseCache +//----------------------------------------------------------------------------- +- (void) loadResourceDataNotifyingClient: (id)client + usingCache: (BOOL)shouldUseCache { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(NSURLHandle*)URLHandleUsingCache:(BOOL)shouldUseCache +//----------------------------------------------------------------------------- +- (NSURLHandle*)URLHandleUsingCache: (BOOL)shouldUseCache { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(BOOL)setResourceData:(NSData*)data +//----------------------------------------------------------------------------- +- (BOOL) setResourceData: (NSData*)data { //FIXME [self notImplemented: _cmd]; -}; + return NO; +} -//----------------------------------------------------------------------------------- --(id)propertyForKey:(NSString*)propertyKey +//----------------------------------------------------------------------------- +- (id) propertyForKey: (NSString*)propertyKey { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(BOOL)setProperty:(id)property - forKey:(NSString*)propertyKey; +//----------------------------------------------------------------------------- +- (BOOL) setProperty: (id)property + forKey: (NSString*)propertyKey; { //FIXME [self notImplemented: _cmd]; -}; + return NO; +} @end -//=================================================================================== +//============================================================================= @implementation NSObject (NSURLClient) -//----------------------------------------------------------------------------------- --(void) URL:(NSURL*)sender - resourceDataDidBecomeAvailable:(NSData*)newBytes +//----------------------------------------------------------------------------- +- (void) URL: (NSURL*)sender + resourceDataDidBecomeAvailable: (NSData*)newBytes { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)URLResourceDidFinishLoading:(NSURL*)sender +//----------------------------------------------------------------------------- +- (void) URLResourceDidFinishLoading: (NSURL*)sender { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)URLResourceDidCancelLoading:(NSURL*)sender +//----------------------------------------------------------------------------- +- (void) URLResourceDidCancelLoading: (NSURL*)sender { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void) URL:(NSURL*)sender - resourceDidFailLoadingWithReason:(NSString*)reason +//----------------------------------------------------------------------------- +- (void) URL: (NSURL*)sender + resourceDidFailLoadingWithReason: (NSString*)reason { //FIXME [self notImplemented: _cmd]; -}; +} @end diff --git a/Source/NSURLHandle.m b/Source/NSURLHandle.m index bf206ecd8..1cd626951 100644 --- a/Source/NSURLHandle.m +++ b/Source/NSURLHandle.m @@ -1,7 +1,7 @@ /* NSURLHandle.h - Class NSURLHandle Copyright (C) 1999 Free Software Foundation, Inc. - Written by: Manuel Guesdon + Written by: Manuel Guesdon Date: Jan 1999 This file is part of the GNUstep Library. @@ -22,7 +22,7 @@ */ /* -Note from Manuel Guesdon: +Note from Manuel Guesdon: * functions are not implemented. If someone has documentation or ideas on how it should work... */ @@ -36,171 +36,184 @@ how it should work... #include #include -//=================================================================================== +//============================================================================= @implementation NSURLHandle -//----------------------------------------------------------------------------------- -+(void)registerURLHandleClass:(Class)_urlHandleSubclass +//----------------------------------------------------------------------------- ++ (void) registerURLHandleClass: (Class)_urlHandleSubclass { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- -+(Class)URLHandleClassForURL:(NSURL*)_url +//----------------------------------------------------------------------------- ++ (Class)URLHandleClassForURL: (NSURL*)_url { //FIXME [self notImplemented: _cmd]; -}; + return 0; +} -//----------------------------------------------------------------------------------- --(id)initWithURL:(NSURL*)_url - cached:(BOOL)_cached +//----------------------------------------------------------------------------- +- (id) initWithURL: (NSURL*)_url + cached: (BOOL)_cached { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(NSURLHandleStatus)status +//----------------------------------------------------------------------------- +- (NSURLHandleStatus) status { //FIXME [self notImplemented: _cmd]; -}; + return (NSURLHandleStatus)0; +} -//----------------------------------------------------------------------------------- --(NSString*)failureReason +//----------------------------------------------------------------------------- +- (NSString*) failureReason { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(void)addClient:(id )_client +//----------------------------------------------------------------------------- +- (void) addClient: (id )_client { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)removeClient:(id )_client +//----------------------------------------------------------------------------- +- (void) removeClient: (id )_client { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)loadInBackground +//----------------------------------------------------------------------------- +- (void) loadInBackground { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)cancelLoadInBackground +//----------------------------------------------------------------------------- +- (void) cancelLoadInBackground { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(NSData*)resourceData +//----------------------------------------------------------------------------- +- (NSData*) resourceData { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(NSData*)availableResourceData +//----------------------------------------------------------------------------- +- (NSData*) availableResourceData { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(void)flushCachedData +//----------------------------------------------------------------------------- +- (void) flushCachedData { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)backgroundLoadDidFailWithReason:(NSString*)reason +//----------------------------------------------------------------------------- +- (void) backgroundLoadDidFailWithReason: (NSString*)reason { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)didLoadBytes:(NSData*)newData - loadComplete:(BOOL)_loadComplete +//----------------------------------------------------------------------------- +- (void) didLoadBytes: (NSData*)newData + loadComplete: (BOOL)_loadComplete { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- -+(BOOL)canInitWithURL:(NSURL*)_url +//----------------------------------------------------------------------------- ++ (BOOL) canInitWithURL: (NSURL*)_url { //FIXME [self notImplemented: _cmd]; -}; + return NO; +} -//----------------------------------------------------------------------------------- -+(NSURLHandle*)cachedHandleForURL:(NSURL*)_url +//----------------------------------------------------------------------------- ++ (NSURLHandle*) cachedHandleForURL: (NSURL*)_url { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(id)propertyForKey:(NSString*)propertyKey +//----------------------------------------------------------------------------- +- (id) propertyForKey: (NSString*)propertyKey { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(id)propertyForKeyIfAvailable:(NSString*)propertyKey +//----------------------------------------------------------------------------- +- (id) propertyForKeyIfAvailable: (NSString*)propertyKey { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(BOOL)writeProperty:(id)propertyValue - forKey:(NSString*)propertyKey +//----------------------------------------------------------------------------- +- (BOOL) writeProperty: (id)propertyValue + forKey: (NSString*)propertyKey { //FIXME [self notImplemented: _cmd]; -}; + return NO; +} -//----------------------------------------------------------------------------------- --(BOOL)writeData:(NSData*)data +//----------------------------------------------------------------------------- +- (BOOL) writeData: (NSData*)data { //FIXME [self notImplemented: _cmd]; -}; + return NO; +} -//----------------------------------------------------------------------------------- --(NSData*)loadInForeground +//----------------------------------------------------------------------------- +- (NSData*) loadInForeground { //FIXME [self notImplemented: _cmd]; -}; + return nil; +} -//----------------------------------------------------------------------------------- --(void)beginLoadInBackground +//----------------------------------------------------------------------------- +- (void) beginLoadInBackground { //FIXME [self notImplemented: _cmd]; -}; +} -//----------------------------------------------------------------------------------- --(void)endLoadInBackground +//----------------------------------------------------------------------------- +- (void) endLoadInBackground { //FIXME [self notImplemented: _cmd]; -}; +} @end diff --git a/Source/NSUnarchiver.m b/Source/NSUnarchiver.m index a47c1a336..671f1215b 100644 --- a/Source/NSUnarchiver.m +++ b/Source/NSUnarchiver.m @@ -30,7 +30,7 @@ /* * Setup for inline operation of arrays. */ -#define GSI_ARRAY_RETAIN(X) X +#define GSI_ARRAY_RETAIN(X) #define GSI_ARRAY_RELEASE(X) #define GSI_ARRAY_TYPES GSUNION_OBJ|GSUNION_SEL|GSUNION_STR @@ -718,7 +718,6 @@ mapClassName(NSUnarchiverObjectInfo *info) else { unsigned size; - NSData *dat; if (GSIArrayCount(ptrMap) != xref) { @@ -744,8 +743,6 @@ mapClassName(NSUnarchiverObjectInfo *info) case _GSC_CHARPTR: { - char *str; - typeCheck(*type, _GSC_CHARPTR); /* * Special case - a zero crossref value size is a nil pointer. @@ -766,8 +763,6 @@ mapClassName(NSUnarchiverObjectInfo *info) } else { - int length; - if (xref != GSIArrayCount(ptrMap)) { [NSException raise: NSInternalInconsistencyException @@ -970,8 +965,7 @@ mapClassName(NSUnarchiverObjectInfo *info) [NSException raise: NSInternalInconsistencyException format: @"Decoding data object with unknown type"]; } - else - return [NSData data]; + return [NSData data]; } /* diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index f979837c3..fe005c2db 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -677,7 +677,7 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */ } } if (wantRead == NO) - return; + return YES; } /* diff --git a/Source/NSZone.m b/Source/NSZone.m index 0f58e7c3c..c86ada7e4 100644 --- a/Source/NSZone.m +++ b/Source/NSZone.m @@ -1576,7 +1576,6 @@ NSCreateZone (size_t start, size_t gran, BOOL canFree) ffree_zone *zone; ff_block *block; ff_block *chunk; - ff_block *header; ff_block *tailer; zone = objc_malloc(sizeof(ffree_zone)); @@ -1704,10 +1703,10 @@ NSZoneRealloc (NSZone *zone, void *ptr, size_t size) inline void NSRecycleZone (NSZone *zone) { - if (zone == 0) - zone == NSDefaultMallocZone(); + if (zone == 0) + zone = NSDefaultMallocZone(); - (zone->recycle)(zone); + (zone->recycle)(zone); } inline void diff --git a/Source/TcpPort.m b/Source/TcpPort.m index c0d21db1d..27b982bab 100644 --- a/Source/TcpPort.m +++ b/Source/TcpPort.m @@ -57,6 +57,7 @@ #include /* for MAXHOSTNAMELEN */ #include /* for inet_ntoa() */ #include +#include #include #include @@ -1207,7 +1208,7 @@ static NSMapTable* port_number_2_port; #ifndef HAVE_INET_ATON p->_listening_address.sin_addr.s_addr = inet_addr("127.0.0.1"); #else - inet_aton("127.0.0.1", &p->_listening_address.sin_addr.s_addr); + inet_aton("127.0.0.1", &p->_listening_address.sin_addr); #endif } else @@ -1247,7 +1248,6 @@ static NSMapTable* port_number_2_port; fromPort: (int)portn { TcpInPort* p = [self newForReceivingFromPortNumber: portn]; - struct sockaddr_in sin; if (p) { [[NSPortNameServer defaultPortNameServer] registerPort: p @@ -1808,7 +1808,7 @@ static NSMapTable *out_port_bag = NULL; || (p->_remote_in_port_address.sin_addr.s_addr != sockaddr->sin_addr.s_addr)) { - NSString *od = [p description]; +// NSString *od = [p description]; NSMapRemove (out_port_bag, (void*)p); memcpy (&(p->_remote_in_port_address), diff --git a/Source/UnixFileHandle.m b/Source/UnixFileHandle.m index 9b6c79a17..7966728ba 100644 --- a/Source/UnixFileHandle.m +++ b/Source/UnixFileHandle.m @@ -519,10 +519,12 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin) isStandardFile = NO; if ((e = fcntl(desc, F_GETFL, 0)) >= 0) - if (e & NBLK_OPT) - wasNonBlocking = YES; - else - wasNonBlocking = NO; + { + if (e & NBLK_OPT) + wasNonBlocking = YES; + else + wasNonBlocking = NO; + } isNonBlocking = wasNonBlocking; descriptor = desc; @@ -1222,7 +1224,6 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin) struct sockaddr_in buf; int desc; int blen = sizeof(buf); - NSFileHandle* hdl; desc = accept(descriptor, (struct sockaddr*)&buf, &blen); if (desc < 0) diff --git a/Source/propList.h b/Source/propList.h index 713975905..5f969801b 100644 --- a/Source/propList.h +++ b/Source/propList.h @@ -156,7 +156,7 @@ static BOOL skipSpace(pldata *pld) if (c == '/' && pld->pos < pld->end - 1) { /* - * Check for comments beginning '//' or '/*' + * Check for comments beginning '/' followed by '/' or '*' */ if (pld->ptr[pld->pos + 1] == '/') { diff --git a/Tools/gdnc.m b/Tools/gdnc.m index fa65417df..75e802094 100644 --- a/Tools/gdnc.m +++ b/Tools/gdnc.m @@ -31,6 +31,8 @@ #include #include +#include + #include "gdnc.h" @interface GDNCNotification : NSObject @@ -390,6 +392,7 @@ } NSMapRemove(connections, connection); } + return nil; } - (void) registerClient: (id)client diff --git a/Tools/gdomap.c b/Tools/gdomap.c index ea202142c..1485fb195 100644 --- a/Tools/gdomap.c +++ b/Tools/gdomap.c @@ -33,6 +33,7 @@ #include #include #include /* for strchr() */ +#include /* for strchr() */ #ifndef __WIN32__ #include #include @@ -451,7 +452,7 @@ map_by_port(unsigned p, unsigned char t) { if (debug > 2) { - fprintf(stderr, "Found port %d with name %.*s\n", + fprintf(stderr, "Found port %d with name %s\n", map[index]->port, map[index]->name); } return map[index]; @@ -700,7 +701,7 @@ dump_stats() fprintf(stderr, "tcp messages waiting for send - %d\n", tcp_pending); fprintf(stderr, "udp messages waiting for send - %d\n", udp_pending); fprintf(stderr, "size of name-to-port map - %d\n", map_used); - fprintf(stderr, "number of known name servers - %d\n", prb_used); + fprintf(stderr, "number of known name servers - %ld\n", prb_used); fprintf(stderr, "TCP %d read, %d sent\n", tcp_read, tcp_sent); fprintf(stderr, "UDP %d read, %d sent\n", udp_read, udp_sent); } @@ -1544,7 +1545,6 @@ handle_io() else if (rval == 0) { long now = time(0); - int i; /* * Let's handle a timeout. @@ -1706,7 +1706,7 @@ handle_request(int desc) { fprintf(stderr, "request type '%c' from chan %d", type, desc); } - fprintf(stderr, " - name: '%.*s' port: %d\n", size, buf, port); + fprintf(stderr, " - name: '%.*s' port: %ld\n", size, buf, port); } if (ptype != GDO_TCP_GDO && ptype != GDO_TCP_FOREIGN && @@ -1819,7 +1819,7 @@ handle_request(int desc) { if (debug > 1) { - fprintf(stderr, "re-register from %d to %d\n", + fprintf(stderr, "re-register from %d to %ld\n", m->port, port); } m->port = port; @@ -2970,7 +2970,7 @@ printf( fprintf(stderr, "Registration will take place locally.\n"); } doregister(optarg, port, ptype); - return; + return 0; case 'T': if (strcmp(optarg, "tcp_gdo") == 0) diff --git a/Tools/pldes.m b/Tools/pldes.m index 4c494d723..7e5b64e1e 100644 --- a/Tools/pldes.m +++ b/Tools/pldes.m @@ -33,7 +33,6 @@ int main(int argc, char** argv) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - NSUserDefaults *defs; NSProcessInfo *proc; NSArray *args; unsigned i; diff --git a/Tools/plparse.m b/Tools/plparse.m index 8fdd05c55..435c9fc81 100644 --- a/Tools/plparse.m +++ b/Tools/plparse.m @@ -31,7 +31,6 @@ int main(int argc, char** argv) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - NSUserDefaults *defs; NSProcessInfo *proc; NSArray *args; unsigned i; diff --git a/Tools/plser.m b/Tools/plser.m index a008681ef..4d7343b34 100644 --- a/Tools/plser.m +++ b/Tools/plser.m @@ -33,7 +33,6 @@ int main(int argc, char** argv) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - NSUserDefaults *defs; NSProcessInfo *proc; NSArray *args; unsigned i; diff --git a/Tools/sfparse.m b/Tools/sfparse.m index 33156b728..18b94e7cc 100644 --- a/Tools/sfparse.m +++ b/Tools/sfparse.m @@ -31,7 +31,6 @@ int main(int argc, char** argv) { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - NSUserDefaults *defs; NSProcessInfo *proc; NSArray *args; unsigned i;