From 60885954c6a5de65678fcf81e9f51d347c20f5af Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Fri, 11 Feb 2011 14:31:25 +0000 Subject: [PATCH] Recommit tested changes. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32075 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++++++++ Source/GSICUString.h | 38 +++++++++++++++++++------------------ Source/GSICUString.m | 9 ++++++++- Source/NSArray.m | 8 ++++---- Source/NSAttributedString.m | 4 ++-- Source/NSData.m | 6 ++++-- Source/NSMethodSignature.m | 5 +++++ 7 files changed, 52 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 21011054f7..63be6151ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-02-11 Richard Frith-Macdonald + + * Source/NSArray.m: Recommit fixed version + * Source/GSICUString.h: Formatting fixups + * Source/GSICUString.m: Recommit + * Source/NSAttributedString.m: Recommit + * Source/NSData.m: Recommit + * Source/NSMethodSignature.m: Recommit + 2011-02-11 Richard Frith-Macdonald * Source/NSPropertyList.m: Recommit with modification fixed and tested. diff --git a/Source/GSICUString.h b/Source/GSICUString.h index 434ccab0c0..a82447a515 100644 --- a/Source/GSICUString.h +++ b/Source/GSICUString.h @@ -11,6 +11,7 @@ * 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 @@ -23,6 +24,7 @@ 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 @@ -30,9 +32,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 @@ -43,9 +45,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 @@ -54,10 +56,10 @@ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str); */ static inline void free_string(unichar **buf) { - if (0 != *buf) - { - free(*buf); - } + if (0 != *buf) + { + free(*buf); + } } /** @@ -68,12 +70,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 c4e811da43..201557dcab 100644 --- a/Source/GSICUString.m +++ b/Source/GSICUString.m @@ -263,12 +263,19 @@ void UTextNSStringCopy(UText *ut, UErrorCode *status) { NSMutableString *str = (NSMutableString*)src->p; + UText *txt; if (deep) { str = [str mutableCopy]; + txt = UTextInitWithNSMutableString(dest, str); + [str release]; } - return UTextInitWithNSMutableString(dest, str); + else + { + txt = UTextInitWithNSMutableString(dest, str); + } + return txt; } /** diff --git a/Source/NSArray.m b/Source/NSArray.m index 979876ff0e..590e700fa3 100644 --- a/Source/NSArray.m +++ b/Source/NSArray.m @@ -1680,7 +1680,7 @@ - (NSIndexSet *) indexesOfObjectsWithOptions: (NSEnumerationOptions)opts enumerator = [self reverseObjectEnumerator]; } - FOR_IN (id, obj, self) + FOR_IN (id, obj, enumerator) if (CALL_BLOCK(predicate, obj, count, &shouldStop)) { /* TODO: It would be more efficient to collect an NSRange and only @@ -1692,7 +1692,7 @@ - (NSIndexSet *) indexesOfObjectsWithOptions: (NSEnumerationOptions)opts return set; } count++; - END_FOR_IN(self) + END_FOR_IN(enumerator) return set; } @@ -1725,7 +1725,7 @@ - (NSUInteger)indexOfObjectWithOptions: (NSEnumerationOptions)opts enumerator = [self reverseObjectEnumerator]; } - FOR_IN (id, obj, self) + FOR_IN (id, obj, enumerator) if (CALL_BLOCK(predicate, obj, count, &shouldStop)) { return count; @@ -1735,7 +1735,7 @@ - (NSUInteger)indexOfObjectWithOptions: (NSEnumerationOptions)opts return NSNotFound; } count++; - END_FOR_IN(self) + END_FOR_IN(enumerator) return NSNotFound; } diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index fa499fd215..d188f4a0af 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -460,7 +460,7 @@ - (NSDictionary*) attributesAtIndex: (NSUInteger)index NSRange tmpRange; IMP getImp; - if (rangeLimit.location < 0 || NSMaxRange(rangeLimit) > [self length]) + if (NSMaxRange(rangeLimit) > [self length]) { [NSException raise: NSRangeException format: @"RangeError in method -attributesAtIndex:longestEffectiveRange:inRange: in class NSAttributedString"]; @@ -548,7 +548,7 @@ - (id) attribute: (NSString*)attributeName BOOL (*eImp)(id,SEL,id); IMP getImp; - if (rangeLimit.location < 0 || NSMaxRange(rangeLimit) > [self length]) + if (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 845e447d8f..5022bb6bb7 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -3006,6 +3006,7 @@ - (void) finalize */ - (id) initWithContentsOfMappedFile: (NSString*)path { + off_t off; int fd; #if defined(__MINGW__) @@ -3033,14 +3034,15 @@ - (id) initWithContentsOfMappedFile: (NSString*)path return nil; } /* Find size of file to be mapped. */ - length = lseek(fd, 0, SEEK_END); - if (length < 0) + off = lseek(fd, 0, SEEK_END); + if (off < 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/NSMethodSignature.m b/Source/NSMethodSignature.m index b81bbb0db0..81bdb1670f 100644 --- a/Source/NSMethodSignature.m +++ b/Source/NSMethodSignature.m @@ -452,6 +452,7 @@ - (NSArgumentInfo) argumentInfoAtIndex: (NSUInteger)index if (_inf == 0) { [self methodInfo]; + NSAssert(0 != _inf, @"Initialising failed"); } return _inf[index+1]; } @@ -471,6 +472,7 @@ - (const char*) getArgumentTypeAtIndex: (NSUInteger)index if (_inf == 0) { [self methodInfo]; + NSAssert(0 != _inf, @"Initialising failed"); } return _inf[index+1].qtype; } @@ -480,6 +482,7 @@ - (BOOL) isOneway if (_inf == 0) { [self methodInfo]; + NSAssert(0 != _inf, @"Initialising failed"); } return (_inf[0].qual & _F_ONEWAY) ? YES : NO; } @@ -489,6 +492,7 @@ - (NSUInteger) methodReturnLength if (_inf == 0) { [self methodInfo]; + NSAssert(0 != _inf, @"Initialising failed"); } return _inf[0].size; } @@ -498,6 +502,7 @@ - (const char*) methodReturnType if (_inf == 0) { [self methodInfo]; + NSAssert(0 != _inf, @"Initialising failed"); } return _inf[0].qtype; }