diff --git a/ChangeLog b/ChangeLog index d46896ddf..3a6a3134f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-02-11 Richard Frith-Macdonald + + Revert everything back to svn 32051 due to loads of commits of broken + code which have been occurring to fast for anyone to review, and either + don't compile or fail the testsuite. + Lets go through things checking that they at least compile with gcc + and pass the testsuite before we recommit them! + 2011-02-11 Richard Frith-Macdonald * Source/GSICUString.m: diff --git a/Source/GSICUString.h b/Source/GSICUString.h index a82447a51..434ccab0c 100644 --- a/Source/GSICUString.h +++ b/Source/GSICUString.h @@ -11,7 +11,6 @@ * contents directly. */ UText* UTextInitWithNSString(UText *txt, NSString *str); - /** * Initialises a UText structure with an NSMutableString. If txt is NULL, then * this allocates a new structure on the heap, otherwise it fills in the @@ -24,7 +23,6 @@ UText* UTextInitWithNSString(UText *txt, NSString *str); * reflected in the underlying NSMutableString. */ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); - /** * GSUTextString is an NSString subclass that is backed by a libicu UText * structure. This class is intended to be used when returning UText created @@ -32,9 +30,9 @@ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); */ @interface GSUTextString : NSString { - @public - /** The UText structure containing the libicu string interface. */ - UText txt; + @public + /** The UText structure containing the libicu string interface. */ + UText txt; } @end @@ -45,9 +43,9 @@ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); */ @interface GSUTextMutableString : NSMutableString { - @public - /** The UText structure containing the libicu string interface. */ - UText txt; + @public + /** The UText structure containing the libicu string interface. */ + UText txt; } @end @@ -56,10 +54,10 @@ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); */ static inline void free_string(unichar **buf) { - if (0 != *buf) - { - free(*buf); - } + if (0 != *buf) + { + free(*buf); + } } /** @@ -70,12 +68,12 @@ static inline void free_string(unichar **buf) * Buffers created in this way are exception safe when using native exceptions. */ #define TEMP_BUFFER(name, size)\ - __attribute__((cleanup(free_string))) unichar *name ##_onheap = 0;\ - unichar name ## _onstack[64 / sizeof(unichar)];\ - unichar *name = name ## _onstack;\ - if (size > 64)\ - {\ - name ## _onheap = malloc(size);\ - name = name ## _onheap;\ - } + __attribute__((cleanup(free_string))) unichar *name ##_onheap = 0;\ + unichar name ## _onstack[64 / sizeof(unichar)];\ + unichar *name = name ## _onstack;\ + if (size > 64)\ + {\ + name ## _onheap = malloc(size);\ + name = name ## _onheap;\ + } diff --git a/Source/GSICUString.m b/Source/GSICUString.m index 201557dca..c4e811da4 100644 --- a/Source/GSICUString.m +++ b/Source/GSICUString.m @@ -263,19 +263,12 @@ UTextNSMutableStringClone(UText *dest, UErrorCode *status) { NSMutableString *str = (NSMutableString*)src->p; - UText *txt; if (deep) { str = [str mutableCopy]; - txt = UTextInitWithNSMutableString(dest, str); - [str release]; } - else - { - txt = UTextInitWithNSMutableString(dest, str); - } - return txt; + return UTextInitWithNSMutableString(dest, str); } /** diff --git a/Source/GSPrivate.h b/Source/GSPrivate.h index 3110e95a2..3598813f5 100644 --- a/Source/GSPrivate.h +++ b/Source/GSPrivate.h @@ -93,41 +93,21 @@ typedef struct objc_category* Category; * arrays are allocated on the stack (for speed), but large arrays are * allocated from the heap (to avoid stack overflow). */ -#if __GNUC__ > 3 -__attribute__((unused)) static void GSFreeTempBuffer(void **b) -{ - if (NULL != *b) free(*b); -} -# define GS_BEGINITEMBUF(P, S, T) { \ - T _ibuf[GS_MAX_OBJECTS_FROM_STACK];\ - T *P = _ibuf;\ - __attribute__((cleanup(GSFreeTempBuffer))) void *_base = 0;\ - if (S > GS_MAX_OBJECTS_FROM_STACK)\ - {\ - _base = malloc(S);\ - P = _base;\ - } -#else -# define GS_BEGINITEMBUF(P, S, T) { \ +#define GS_BEGINITEMBUF(P, S, T) { \ T _ibuf[(S) <= GS_MAX_OBJECTS_FROM_STACK ? (S) : 0]; \ T *_base = ((S) <= GS_MAX_OBJECTS_FROM_STACK) ? _ibuf \ : (T*)NSZoneMalloc(NSDefaultMallocZone(), (S) * sizeof(T)); \ T *(P) = _base; -#endif /** * Macro to manage memory for chunks of code that need to work with * arrays of items. Use GS_BEGINITEMBUF() to start the block of code using * the array and this macro to end it. */ -#if __GNUC__ > 3 -# define GS_ENDITEMBUF() } -#else -# define GS_ENDITEMBUF() \ +#define GS_ENDITEMBUF() \ if (_base != _ibuf) \ NSZoneFree(NSDefaultMallocZone(), _base); \ } -#endif /** * Macro to manage memory for chunks of code that need to work with diff --git a/Source/NSArray.m b/Source/NSArray.m index 590e700fa..979876ff0 100644 --- a/Source/NSArray.m +++ b/Source/NSArray.m @@ -1680,7 +1680,7 @@ compare(id elem1, id elem2, void* context) enumerator = [self reverseObjectEnumerator]; } - FOR_IN (id, obj, enumerator) + FOR_IN (id, obj, self) if (CALL_BLOCK(predicate, obj, count, &shouldStop)) { /* TODO: It would be more efficient to collect an NSRange and only @@ -1692,7 +1692,7 @@ compare(id elem1, id elem2, void* context) return set; } count++; - END_FOR_IN(enumerator) + END_FOR_IN(self) return set; } @@ -1725,7 +1725,7 @@ compare(id elem1, id elem2, void* context) enumerator = [self reverseObjectEnumerator]; } - FOR_IN (id, obj, enumerator) + FOR_IN (id, obj, self) if (CALL_BLOCK(predicate, obj, count, &shouldStop)) { return count; @@ -1735,7 +1735,7 @@ compare(id elem1, id elem2, void* context) return NSNotFound; } count++; - END_FOR_IN(enumerator) + END_FOR_IN(self) return NSNotFound; } diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index d188f4a0a..fa499fd21 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -460,7 +460,7 @@ appendUIntData(NSMutableData *d, NSUInteger i) NSRange tmpRange; IMP getImp; - if (NSMaxRange(rangeLimit) > [self length]) + if (rangeLimit.location < 0 || NSMaxRange(rangeLimit) > [self length]) { [NSException raise: NSRangeException format: @"RangeError in method -attributesAtIndex:longestEffectiveRange:inRange: in class NSAttributedString"]; @@ -548,7 +548,7 @@ appendUIntData(NSMutableData *d, NSUInteger i) BOOL (*eImp)(id,SEL,id); IMP getImp; - if (NSMaxRange(rangeLimit) > [self length]) + if (rangeLimit.location < 0 || NSMaxRange(rangeLimit) > [self length]) { [NSException raise: NSRangeException format: @"RangeError in method -attribute:atIndex:longestEffectiveRange:inRange: in class NSAttributedString"]; diff --git a/Source/NSData.m b/Source/NSData.m index 5022bb6bb..845e447d8 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -3006,7 +3006,6 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) */ - (id) initWithContentsOfMappedFile: (NSString*)path { - off_t off; int fd; #if defined(__MINGW__) @@ -3034,15 +3033,14 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) return nil; } /* Find size of file to be mapped. */ - off = lseek(fd, 0, SEEK_END); - if (off < 0) + length = lseek(fd, 0, SEEK_END); + if (length < 0) { NSWarnMLog(@"unable to seek to eof %@ - %@", path, [NSError _last]); close(fd); DESTROY(self); return nil; } - length = off; /* Position at start of file. */ if (lseek(fd, 0, SEEK_SET) != 0) { diff --git a/Source/NSKeyValueObserving.m b/Source/NSKeyValueObserving.m index 4a0d997e5..34dc1cc73 100644 --- a/Source/NSKeyValueObserving.m +++ b/Source/NSKeyValueObserving.m @@ -313,7 +313,6 @@ static NSString *newKey(SEL _cmd) unsigned len = strlen(name); NSString *key; unsigned i; - NSCAssert(len > 0, @"Invalid selector name!"); if (*name == '_') { diff --git a/Source/NSLocale.m b/Source/NSLocale.m index fd3dcc40a..237c2b254 100644 --- a/Source/NSLocale.m +++ b/Source/NSLocale.m @@ -654,7 +654,7 @@ static NSRecursiveLock *classLock = nil; #if GS_USE_ICU == 1 int32_t length = 0; unichar buffer[ULOC_FULLNAME_CAPACITY]; - UErrorCode status = 0; + UErrorCode status; const char *keyword = NULL; const char *locale = [_localeId UTF8String]; diff --git a/Source/NSMethodSignature.m b/Source/NSMethodSignature.m index 81bdb1670..b81bbb0db 100644 --- a/Source/NSMethodSignature.m +++ b/Source/NSMethodSignature.m @@ -452,7 +452,6 @@ next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes) if (_inf == 0) { [self methodInfo]; - NSAssert(0 != _inf, @"Initialising failed"); } return _inf[index+1]; } @@ -472,7 +471,6 @@ next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes) if (_inf == 0) { [self methodInfo]; - NSAssert(0 != _inf, @"Initialising failed"); } return _inf[index+1].qtype; } @@ -482,7 +480,6 @@ next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes) if (_inf == 0) { [self methodInfo]; - NSAssert(0 != _inf, @"Initialising failed"); } return (_inf[0].qual & _F_ONEWAY) ? YES : NO; } @@ -492,7 +489,6 @@ next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes) if (_inf == 0) { [self methodInfo]; - NSAssert(0 != _inf, @"Initialising failed"); } return _inf[0].size; } @@ -502,7 +498,6 @@ next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes) if (_inf == 0) { [self methodInfo]; - NSAssert(0 != _inf, @"Initialising failed"); } return _inf[0].qtype; } diff --git a/Source/NSPropertyList.m b/Source/NSPropertyList.m index 94d38d3a6..358002647 100644 --- a/Source/NSPropertyList.m +++ b/Source/NSPropertyList.m @@ -1464,14 +1464,22 @@ PString(NSString *obj, NSMutableData *output) else if ([obj rangeOfCharacterFromSet: oldQuotables].length > 0 || [obj characterAtIndex: 0] == '/') { + unichar tmp[length <= 1024 ? length : 0]; unichar *ustring; unichar *from; unichar *end; unsigned char *ptr; int base = [output length]; int len = 0; - GS_BEGINITEMBUF(tmp, (length * sizeof(unichar)), unichar) + if (length <= 1024) + { + ustring = tmp; + } + else + { + ustring = NSAllocateCollectable(sizeof(unichar) * length, 0); + } end = &ustring[length]; [obj getCharacters: ustring]; for (from = ustring; from < end; from++) @@ -1573,7 +1581,10 @@ PString(NSString *obj, NSMutableData *output) } *ptr++ = '"'; - GS_ENDITEMBUF(); + if (ustring != tmp) + { + NSZoneFree(NSDefaultMallocZone(), ustring); + } } else { diff --git a/Source/NSThread.m b/Source/NSThread.m index a77a2282d..04eb388ed 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -277,6 +277,7 @@ commonModes(void) static BOOL entered_multi_threaded_state = NO; static NSThread *defaultThread; +static NSLock *thread_creation_lock; static pthread_key_t thread_object_key; @@ -304,7 +305,6 @@ static void exitedThread(void *thread) fprintf(stderr, "WARNING thread %p terminated without calling +exit!\n", thread); } - [(id)thread release]; } /** @@ -458,15 +458,17 @@ unregisterActiveThread(NSThread *thread) if (t == nil) { + [thread_creation_lock lock]; t = pthread_getspecific(thread_object_key); if (t == nil) { t = [self new]; t->_active = YES; pthread_setspecific(thread_object_key, t); - [t release]; + [thread_creation_lock unlock]; return YES; } + [thread_creation_lock unlock]; } return NO; } @@ -527,6 +529,7 @@ unregisterActiveThread(NSThread *thread) [NSException raise: NSInternalInconsistencyException format: @"Unable to create thread key!"]; } + thread_creation_lock = [NSLock new]; /* * Ensure that the default thread exists. */ diff --git a/Source/NSUnarchiver.m b/Source/NSUnarchiver.m index 091923fe6..1cf9bfa54 100644 --- a/Source/NSUnarchiver.m +++ b/Source/NSUnarchiver.m @@ -1196,6 +1196,7 @@ static Class NSDataMallocClass; { NSLog(@"Loss of information converting decoded value to uint16_t"); } + *(uint8_t*)address = (uint8_t)big; *(uint16_t*)address = (uint16_t)big; return; case 4: