Minor cleanups.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32031 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2011-02-10 10:52:54 +00:00
parent d5e9a52e35
commit a63d65764c
15 changed files with 137 additions and 53 deletions

View file

@ -1,6 +1,29 @@
2011-02-10 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSSocketStream.m:
* Source/NSPropertyList.m:
* Source/NSUserDefaults.m:
* Source/NSException.m:
* Source/NSURL.m:
* Source/NSDecimalNumber.m:
* Source/Additions/GSMime.m:
* Source/GSFileHandle.m:
* Source/NSNumberFormatter.m:
* Tools/gdomap.c:
* Tools/HTMLLinker.m:
Fix a couple of minor/theoretical memory leaks and make other code
alterations to try to avoid clang static analyser reporting some
issues.
* Source/GSPrivate.h:
* Source/NSObject.m:
* Source/Additions/NSObject+GNUstepBase.m:
New code to provide a single location to cache information which
should exist for the lifetime of the process, and a function to
clean it up on process exit. Just a placeholder so far.
2011-02-09 Stefan Bidigaray <stefanbidi@gmail.com> 2011-02-09 Stefan Bidigaray <stefanbidi@gmail.com>
* Source/NSTimeZone.m: ([-daylightSavingTimeOffsetForDate:]) Implemented. * Source/NSTimeZone.m: ([-daylightSavingTimeOffsetForDate:]) Implement.
2011-02-09 Stefan Bidigaray <stefanbidi@gmail.com> 2011-02-09 Stefan Bidigaray <stefanbidi@gmail.com>

View file

@ -4175,6 +4175,7 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
@"/?="]]; @"/?="]];
[m removeCharactersInString: @"."]; [m removeCharactersInString: @"."];
rfc2045Specials = [m copy]; rfc2045Specials = [m copy];
[m release];
whitespace = RETAIN([NSCharacterSet whitespaceAndNewlineCharacterSet]); whitespace = RETAIN([NSCharacterSet whitespaceAndNewlineCharacterSet]);
if (NSArrayClass == 0) if (NSArrayClass == 0)
{ {

View file

@ -121,3 +121,9 @@
} }
@end @end
/* See ../GSPrivate.h for details.
*/
#import "GSPrivate.h"
BaseCacheStruct GSBaseCache = { };

View file

@ -2174,7 +2174,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
- (NSString*) socketLocalAddress - (NSString*) socketLocalAddress
{ {
NSString *str = nil; NSString *str = nil;
struct sockaddr_in sin; struct sockaddr_in sin = { 0 };
unsigned size = sizeof(sin); unsigned size = sizeof(sin);
if (getsockname(descriptor, (struct sockaddr*)&sin, &size) == -1) if (getsockname(descriptor, (struct sockaddr*)&sin, &size) == -1)
@ -2191,7 +2191,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
- (NSString*) socketLocalService - (NSString*) socketLocalService
{ {
NSString *str = nil; NSString *str = nil;
struct sockaddr_in sin; struct sockaddr_in sin = { 0 };
unsigned size = sizeof(sin); unsigned size = sizeof(sin);
if (getsockname(descriptor, (struct sockaddr*)&sin, &size) == -1) if (getsockname(descriptor, (struct sockaddr*)&sin, &size) == -1)

View file

@ -523,5 +523,32 @@ GSPrivateIsCollectable(const void *ptr) GS_ATTRIB_PRIVATE;
NSZone* NSZone*
GSAtomicMallocZone (void); GSAtomicMallocZone (void);
/* NB ... this is a placeholder for future cleanups of the code!
*
* GSBaseCache is a structure in which base library classes may cache private
* information expected to be present for the lifetime of the process.
*
* The NSObject class registers the BSBaseCacheCleanup() function to be called
* to clean it up on process termination, but we actually keep the cleanup
* code here so we can easily update it in sync with the structure definition.
*
* This structure is actually implemented in Additions/NSObject+GNUstepBase.m
* so that it can be accessed from the base-additions library as well as the
* base library.
*/
typedef struct {
// Add fields to hold cached values here
} BaseCacheStruct;
BaseCacheStruct GSBaseCache GS_ATTRIB_PRIVATE;
#if defined(IN_NSOBJECT_M)
static void
GSBaseCacheCleanup(void)
{
// Add code to clean up cached values here
return;
}
#endif
#endif /* _GSPrivate_h_ */ #endif /* _GSPrivate_h_ */

View file

@ -1327,7 +1327,7 @@ setNonBlocking(SOCKET fd)
{ {
case AF_INET: case AF_INET:
{ {
struct sockaddr_in sin; struct sockaddr_in sin = { 0 };
socklen_t size = sizeof(sin); socklen_t size = sizeof(sin);
if ([key isEqualToString: GSStreamLocalAddressKey]) if ([key isEqualToString: GSStreamLocalAddressKey])
@ -1367,7 +1367,7 @@ setNonBlocking(SOCKET fd)
#if defined(AF_INET6) #if defined(AF_INET6)
case AF_INET6: case AF_INET6:
{ {
struct sockaddr_in6 sin; struct sockaddr_in6 sin = { 0 };
socklen_t size = sizeof(sin); socklen_t size = sizeof(sin);
if ([key isEqualToString: GSStreamLocalAddressKey]) if ([key isEqualToString: GSStreamLocalAddressKey])

View file

@ -165,9 +165,11 @@ static NSDecimalNumber *one;
+ (void) initialize + (void) initialize
{ {
NSDecimal d; /* Initialize d to an empty structure to avoid compiler warnings.
* This also sets d.validNumber to NO ... which is what is actually needed.
*/
NSDecimal d = { 0 };
d.validNumber = NO;
notANumber = [[self alloc] initWithDecimal: d]; notANumber = [[self alloc] initWithDecimal: d];
NSDecimalMax(&d); NSDecimalMax(&d);
maxNumber = [[self alloc] initWithDecimal: d]; maxNumber = [[self alloc] initWithDecimal: d];

View file

@ -968,7 +968,7 @@ callUncaughtHandler(id value)
thread = GSCurrentThread(); thread = GSCurrentThread();
handler = thread->_exception_handler; handler = thread->_exception_handler;
if (handler == NULL) if (NULL == handler)
{ {
static int recursion = 0; static int recursion = 0;
@ -991,10 +991,12 @@ callUncaughtHandler(id value)
*/ */
callUncaughtHandler(self); callUncaughtHandler(self);
} }
else
thread->_exception_handler = handler->next; {
handler->exception = self; thread->_exception_handler = handler->next;
longjmp(handler->jumpState, 1); handler->exception = self;
longjmp(handler->jumpState, 1);
}
} }
#endif #endif
} }

View file

@ -968,13 +968,13 @@ static NSUInteger _defaultBehavior = 0;
[intPartString insertString: [intPartString insertString:
[intPad substringWithRange: ipRange] atIndex: 0]; [intPad substringWithRange: ipRange] atIndex: 0];
[intPartString replaceOccurrencesOfString: @"_" [intPartString replaceOccurrencesOfString: @"_"
withString: @" " withString: @" "
options: 0 options: 0
range: NSMakeRange(0, [intPartString length])]; range: NSMakeRange(0, [intPartString length])];
[intPartString replaceOccurrencesOfString: @"#" [intPartString replaceOccurrencesOfString: @"#"
withString: @"0" withString: @"0"
options: 0 options: 0
range: NSMakeRange(0, [intPartString length])]; range: NSMakeRange(0, [intPartString length])];
} }
// fix the thousands separators up // fix the thousands separators up
if (displayThousandsSeparators && [intPartString length] > 3) if (displayThousandsSeparators && [intPartString length] > 3)
@ -982,9 +982,10 @@ static NSUInteger _defaultBehavior = 0;
int index = [intPartString length]; int index = [intPartString length];
while (0 < (index -= 3)) while (0 < (index -= 3))
{ {
[intPartString insertString: [self thousandSeparator] atIndex: index]; [intPartString insertString: [self thousandSeparator]
} atIndex: index];
}
} }
formattedNumber = [intPartString mutableCopy]; formattedNumber = [intPartString mutableCopy];
@ -994,37 +995,37 @@ static NSUInteger _defaultBehavior = 0;
{ {
if (0 != decimalPlaces) if (0 != decimalPlaces)
{ {
NSMutableString *ms; NSMutableString *ms;
fracPart = [fracPart decimalNumberByMultiplyingByPowerOf10: fracPart = [fracPart decimalNumberByMultiplyingByPowerOf10:
decimalPlaces]; decimalPlaces];
ms = [[fracPart descriptionWithLocale: locale] mutableCopy]; ms = [[fracPart descriptionWithLocale: locale] mutableCopy];
[ms replaceOccurrencesOfString: @"0" [ms replaceOccurrencesOfString: @"0"
withString: @"" withString: @""
options: (NSBackwardsSearch | NSAnchoredSearch) options: (NSBackwardsSearch | NSAnchoredSearch)
range: NSMakeRange(0, [ms length])]; range: NSMakeRange(0, [ms length])];
if ([fracPad length] > [ms length]) if ([fracPad length] > [ms length])
{ {
NSRange fpRange; NSRange fpRange;
fpRange = NSMakeRange([ms length], fpRange = NSMakeRange([ms length],
([fracPad length] - [ms length])); ([fracPad length] - [ms length]));
[ms appendString: [ms appendString:
[fracPad substringWithRange: fpRange]]; [fracPad substringWithRange: fpRange]];
[ms replaceOccurrencesOfString: @"#" [ms replaceOccurrencesOfString: @"#"
withString: @"" withString: @""
options: (NSBackwardsSearch | NSAnchoredSearch) options: (NSBackwardsSearch | NSAnchoredSearch)
range: NSMakeRange(0, [ms length])]; range: NSMakeRange(0, [ms length])];
[ms replaceOccurrencesOfString: @"#" [ms replaceOccurrencesOfString: @"#"
withString: @"0" withString: @"0"
options: 0 options: 0
range: NSMakeRange(0, [ms length])]; range: NSMakeRange(0, [ms length])];
[ms replaceOccurrencesOfString: @"_" [ms replaceOccurrencesOfString: @"_"
withString: @" " withString: @" "
options: 0 options: 0
range: NSMakeRange(0, [ms length])]; range: NSMakeRange(0, [ms length])];
} }
fracPartString = AUTORELEASE(ms); fracPartString = AUTORELEASE(ms);
} }
else else
{ {

View file

@ -65,6 +65,7 @@
#include <fenv.h> #include <fenv.h>
#endif #endif
#define IN_NSOBJECT_M 1
#import "GSPrivate.h" #import "GSPrivate.h"
@ -945,6 +946,10 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
# endif # endif
#endif #endif
/* Cleanup cached information on exit.
*/
atexit(GSBaseCacheCleanup);
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
GSSetLocaleC(LC_ALL, ""); // Set up locale from environment. GSSetLocaleC(LC_ALL, ""); // Set up locale from environment.
#endif #endif
@ -2312,3 +2317,4 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
return [object methodSignatureForSelector: aSelector]; return [object methodSignatureForSelector: aSelector];
} }
@end @end

View file

@ -2160,7 +2160,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
#define STRIDE_FACTOR 3 #define STRIDE_FACTOR 3
unsigned c,d, stride; unsigned c,d, stride;
BOOL found; BOOL found;
NSComparisonResult (*comp)(id, SEL, id) = 0; NSComparisonResult (*comp)(id, SEL, id);
unsigned int count = numKeys; unsigned int count = numKeys;
#ifdef GSWARN #ifdef GSWARN
BOOL badComparison = NO; BOOL badComparison = NO;
@ -2171,7 +2171,15 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
{ {
stride = stride * STRIDE_FACTOR + 1; stride = stride * STRIDE_FACTOR + 1;
} }
lastClass = 0;
/* Initialise lastClass and comparison method to those of the
* first object to be sorted ... this is done here to avoid
* bogus compiler warnings.
*/
lastClass = object_getClass(keys[0]);
comp = (NSComparisonResult (*)(id, SEL, id))
[keys[0] methodForSelector: @selector(compare:)];
while (stride > (STRIDE_FACTOR - 1)) while (stride > (STRIDE_FACTOR - 1))
{ {
// loop to sort for each value of stride // loop to sort for each value of stride

View file

@ -162,6 +162,7 @@ static char *unescape(const char *from, char * to);
*/ */
static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize) static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize)
{ {
const char *rpath;
char *buf; char *buf;
char *ptr; char *ptr;
char *tmp; char *tmp;
@ -189,8 +190,13 @@ static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize)
} }
if (rel->path != 0) if (rel->path != 0)
{ {
len += strlen(rel->path) + 1; // path rpath = rel->path;
} }
else
{
rpath = "";
}
len += strlen(rpath) + 1; // path
if (base != 0 && base->path != 0) if (base != 0 && base->path != 0)
{ {
len += strlen(base->path) + 1; // path len += strlen(base->path) + 1; // path
@ -267,13 +273,13 @@ static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize)
{ {
*tmp++ = '/'; *tmp++ = '/';
} }
strcpy(tmp, rel->path); strcpy(tmp, rpath);
} }
else if (base == 0) else if (base == 0)
{ {
strcpy(tmp, rel->path); strcpy(tmp, rpath);
} }
else if (rel->path[0] == 0) else if (rpath[0] == 0)
{ {
if (base->hasNoPath == NO) if (base->hasNoPath == NO)
{ {
@ -293,7 +299,7 @@ static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize)
tmp += (end - start); tmp += (end - start);
} }
*tmp++ = '/'; *tmp++ = '/';
strcpy(tmp, rel->path); strcpy(tmp, rpath);
} }
if (standardize == YES) if (standardize == YES)
@ -394,7 +400,6 @@ static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize)
{ {
*ptr++ = '#'; *ptr++ = '#';
strcpy(ptr, rel->fragment); strcpy(ptr, rel->fragment);
ptr = &ptr[strlen(ptr)];
} }
return buf; return buf;

View file

@ -1150,8 +1150,9 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
} }
else else
{ {
dict = [obj mutableCopy]; dict = obj = [obj mutableCopy];
[_persDomains setObject: dict forKey: processName]; [_persDomains setObject: dict forKey: processName];
[obj release];
} }
[dict removeObjectForKey: defaultName]; [dict removeObjectForKey: defaultName];
[self __changePersistentDomain: processName]; [self __changePersistentDomain: processName];
@ -1575,6 +1576,7 @@ static BOOL isLocked = NO;
{ {
NSLog(@"Failed to lock user defaults database even after " NSLog(@"Failed to lock user defaults database even after "
@"breaking old locks!"); @"breaking old locks!");
RELEASE(arp);
return NO; return NO;
} }
@ -1901,7 +1903,7 @@ NSLog(@"Creating empty user defaults database");
- (NSDictionary*) dictionaryRepresentation - (NSDictionary*) dictionaryRepresentation
{ {
NSDictionary *rep = nil; NSDictionary *rep;
[_lock lock]; [_lock lock];
NS_DURING NS_DURING
@ -1937,16 +1939,17 @@ NSLog(@"Creating empty user defaults database");
} }
_dictionaryRep = [dictRep makeImmutableCopyOnFail: NO]; _dictionaryRep = [dictRep makeImmutableCopyOnFail: NO];
} }
rep = RETAIN(_dictionaryRep); rep = [[_dictionaryRep retain] autorelease];
[_lock unlock]; [_lock unlock];
} }
NS_HANDLER NS_HANDLER
{ {
rep = nil;
[_lock unlock]; [_lock unlock];
[localException raise]; [localException raise];
} }
NS_ENDHANDLER NS_ENDHANDLER
return AUTORELEASE(rep); return rep;
} }
- (void) registerDefaults: (NSDictionary*)newVals - (void) registerDefaults: (NSDictionary*)newVals

View file

@ -1307,8 +1307,8 @@ int main (int argc, char** argv, char** env)
HTMLDirectoryEnumerator *e; HTMLDirectoryEnumerator *e;
NSString *filename; NSString *filename;
e = [HTMLDirectoryEnumerator alloc]; e = [[[HTMLDirectoryEnumerator alloc]
e = [e initWithBasePath: arg]; initWithBasePath: arg] autorelease];
[e setReturnsAbsolutePaths: YES]; [e setReturnsAbsolutePaths: YES];
while ((filename = [e nextObject]) != nil) while ((filename = [e nextObject]) != nil)

View file

@ -2065,7 +2065,7 @@ init_probe()
{ {
int broadcast = 0; int broadcast = 0;
int elen = 0; int elen = 0;
struct in_addr *other; struct in_addr *other = 0;
struct in_addr sin; struct in_addr sin;
int high = 0; int high = 0;
int low = 0; int low = 0;