Skip to content

Commit

Permalink
many small changes to fix warnings from the Xcode static analyzer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Burks committed Jul 3, 2010
1 parent 33d095f commit add9113
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 67 deletions.
9 changes: 4 additions & 5 deletions objc/bridge.m
Expand Up @@ -1110,7 +1110,7 @@ id nu_calling_objc_method_handler(id target, Method_t m, NSMutableArray *args)
}
}
[result retain];
[pool release];
[pool drain];
[result autorelease];
return result;
}
Expand Down Expand Up @@ -1184,7 +1184,7 @@ static void objc_calling_nu_method_handler(ffi_cif* cif, void* returnvalue, void
if (pool) {
if (resultType[0] == '@')
[*((id *)returnvalue) retain];
[pool release];
[pool drain];
if (resultType[0] == '@')
[*((id *)returnvalue) autorelease];
}
Expand Down Expand Up @@ -1385,7 +1385,6 @@ - (id) evalWithArguments:(id) cdr context:(NSMutableDictionary *) context
for (i = 0; i < argument_count; i++) {
// NSLog(@"argument %d type is %s", i, argument_type_identifiers[i]);
}
id result = [NSNull null];

ffi_cif *cif = (ffi_cif *)malloc(sizeof(ffi_cif));

Expand All @@ -1411,7 +1410,7 @@ - (id) evalWithArguments:(id) cdr context:(NSMutableDictionary *) context
arg_cursor = [arg_cursor cdr];
}
ffi_call(cif, FFI_FN(function), result_value, argument_values);
result = get_nu_value_from_objc_value(result_value, return_type_identifier);
id result = get_nu_value_from_objc_value(result_value, return_type_identifier);

// free the value structures
for (i = 0; i < argument_count; i++) {
Expand All @@ -1425,7 +1424,7 @@ - (id) evalWithArguments:(id) cdr context:(NSMutableDictionary *) context
free(cif);

[result retain];
[pool release];
[pool drain];
[result autorelease];
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion objc/bridgesupport.m
Expand Up @@ -70,7 +70,7 @@ + (void)importFramework:(NSString *) framework fromPath:(NSString *) path intoDi
NSMutableDictionary *enums = [BridgeSupport valueForKey:@"enums"];
NSMutableDictionary *functions = [BridgeSupport valueForKey:@"functions"];

NSXMLDocument *xmlDocument = [[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:xmlPath] options:0 error:nil];
NSXMLDocument *xmlDocument = [[[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:xmlPath] options:0 error:nil] autorelease];
if (xmlDocument) {
id node;
NSEnumerator *childEnumerator = [[[xmlDocument rootElement] children] objectEnumerator];
Expand Down
11 changes: 4 additions & 7 deletions objc/cell.m
Expand Up @@ -298,7 +298,7 @@ - (id) eachWithIndex:(id) block
{
if (nu_objectIsKindOfClass(block, [NuBlock class])) {
id args = [[NuCell alloc] init];
[args setCdr:[[NuCell alloc] init]];
[args setCdr:[[[NuCell alloc] init] autorelease]];
id cursor = self;
int i = 0;
while (cursor && (cursor != Nu__null)) {
Expand All @@ -315,7 +315,7 @@ - (id) eachWithIndex:(id) block

- (id) select:(id) block
{
NuCell *parent = [[NuCell alloc] init];
NuCell *parent = [[[NuCell alloc] init] autorelease];
if (nu_objectIsKindOfClass(block, [NuBlock class])) {
id args = [[NuCell alloc] init];
id cursor = self;
Expand All @@ -334,7 +334,6 @@ - (id) select:(id) block
else
return Nu__null;
NuCell *selected = [parent cdr];
[parent release];
return selected;
}

Expand All @@ -359,7 +358,7 @@ - (id) find:(id) block

- (id) map:(id) block
{
NuCell *parent = [[NuCell alloc] init];
NuCell *parent = [[[NuCell alloc] init] autorelease];
if (nu_objectIsKindOfClass(block, [NuBlock class])) {
id args = [[NuCell alloc] init];
id cursor = self;
Expand All @@ -376,7 +375,6 @@ - (id) map:(id) block
else
return Nu__null;
NuCell *result = [parent cdr];
[parent release];
return result;
}

Expand Down Expand Up @@ -404,15 +402,14 @@ - (id) reduce:(id) block from:(id) initial
id result = initial;
if (nu_objectIsKindOfClass(block, [NuBlock class])) {
id args = [[NuCell alloc] init];
[args setCdr:[[NuCell alloc] init]];
[args setCdr:[[[NuCell alloc] init] autorelease]];
id cursor = self;
while (cursor && (cursor != Nu__null)) {
[args setCar:result];
[[args cdr] setCar:[cursor car]];
result = [block evalWithArguments:args context:Nu__null];
cursor = [cursor cdr];
}
[[args cdr] release];
[args release];
}
return result;
Expand Down
16 changes: 8 additions & 8 deletions objc/class.m
Expand Up @@ -68,14 +68,14 @@ - (id) initWithClass:(Class) class

+ (NSArray *) all
{
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *array = [NSMutableArray array];
int numClasses = objc_getClassList(NULL, 0);
if(numClasses > 0) {
Class *classes = (Class *) malloc( sizeof(Class) * numClasses );
objc_getClassList(classes, numClasses);
int i = 0;
while (i < numClasses) {
NuClass *class = [[NuClass alloc] initWithClass:classes[i]];
NuClass *class = [[[NuClass alloc] initWithClass:classes[i]] autorelease];
[array addObject:class];
i++;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ - (Class) wrappedClass

- (NSArray *) classMethods
{
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *array = [NSMutableArray array];
unsigned int method_count;
#ifdef DARWIN
Method *method_list = class_copyMethodList(object_getClass([self wrappedClass]), &method_count);
Expand All @@ -115,7 +115,7 @@ - (NSArray *) classMethods
#endif
int i;
for (i = 0; i < method_count; i++) {
[array addObject:[[NuMethod alloc] initWithMethod:method_list[i]]];
[array addObject:[[[NuMethod alloc] initWithMethod:method_list[i]] autorelease]];
}
free(method_list);
[array sortUsingSelector:@selector(compare:)];
Expand All @@ -124,7 +124,7 @@ - (NSArray *) classMethods

- (NSArray *) instanceMethods
{
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *array = [NSMutableArray array];
unsigned int method_count;
#ifdef DARWIN
Method *method_list = class_copyMethodList([self wrappedClass], &method_count);
Expand All @@ -133,7 +133,7 @@ - (NSArray *) instanceMethods
#endif
int i;
for (i = 0; i < method_count; i++) {
[array addObject:[[NuMethod alloc] initWithMethod:method_list[i]]];
[array addObject:[[[NuMethod alloc] initWithMethod:method_list[i]] autorelease]];
}
free(method_list);
[array sortUsingSelector:@selector(compare:)];
Expand Down Expand Up @@ -187,7 +187,7 @@ - (NuMethod *) classMethodWithName:(NSString *) methodName
#else
if (!strcmp(methodNameString, sel_get_name(method_getName(method_list[i])))) {
#endif
method = [[NuMethod alloc] initWithMethod:method_list[i]];
method = [[[NuMethod alloc] initWithMethod:method_list[i]] autorelease];
}
}
free(method_list);
Expand All @@ -211,7 +211,7 @@ - (NuMethod *) instanceMethodWithName:(NSString *) methodName
#else
if (!strcmp(methodNameString, sel_get_name(method_getName(method_list[i])))) {
#endif
method = [[NuMethod alloc] initWithMethod:method_list[i]];
method = [[[NuMethod alloc] initWithMethod:method_list[i]] autorelease];
}
}
free(method_list);
Expand Down
6 changes: 2 additions & 4 deletions objc/extensions.m
Expand Up @@ -384,13 +384,12 @@ - (id) evalWithContext:(NSMutableDictionary *) context
NSArray *parts = [[components objectAtIndex:i] componentsSeparatedByString:@"}"];
NSString *expression = [parts objectAtIndex:0];
// evaluate each expression
id value = Nu__null;
if (expression) {
id body;
@synchronized(parser) {
body = [parser parse:expression];
}
value = [body evalWithContext:context];
id value = [body evalWithContext:context];
NSString *stringValue = [value stringValue];
[result appendString:stringValue];
}
Expand Down Expand Up @@ -882,12 +881,11 @@ - (id) loadNuFile:(NSString *) nuFileName withContext:(NSMutableDictionary *) co
NSString *fileName = [self pathForResource:nuFileName ofType:@"nu"];
if (fileName) {
NSString *string = [NSString stringWithContentsOfFile:fileName encoding:NSUTF8StringEncoding error:nil];
id value = Nu__null;
if (string) {
NuSymbolTable *symbolTable = [context objectForKey:SYMBOLS_KEY];
id parser = [context lookupObjectForKey:[symbolTable symbolWithString:@"_parser"]];
id body = [parser parse:string asIfFromFilename:[fileName cStringUsingEncoding:NSUTF8StringEncoding]];
value = [body evalWithContext:context];
[body evalWithContext:context];
return [symbolTable symbolWithCString:"t"];
}
return nil;
Expand Down
2 changes: 1 addition & 1 deletion objc/handler.m
Expand Up @@ -96,7 +96,7 @@ void nu_handler(void *return_value, struct handler_description *description, id
set_objc_value_from_nu_value(return_value, result, description->description[0]+1);
}
[arguments release];
[pool release];
[pool drain];
if (description->description[0][1] == '@') {
[result autorelease];
}
Expand Down
3 changes: 1 addition & 2 deletions objc/macro_0.m
Expand Up @@ -182,7 +182,6 @@ - (id) expandAndEval:(id)cdr context:(NSMutableDictionary *)calling_context eval
// set the arguments to the special variable "margs"
[calling_context setPossiblyNullObject:cdr forKey:[symbolTable symbolWithCString:"margs"]];
// evaluate the body of the block in the calling context (implicit progn)
id value = Nu__null;

// if the macro contains gensyms, give them a unique prefix
int gensymCount = [[self gensyms] count];
Expand All @@ -198,7 +197,7 @@ - (id) expandAndEval:(id)cdr context:(NSMutableDictionary *)calling_context eval
//bodyToEvaluate = body;
//NSLog(@"evaluating %@", [bodyToEvaluate stringValue]);

value = [self expandUnquotes:bodyToEvaluate withContext:calling_context];
id value = [self expandUnquotes:bodyToEvaluate withContext:calling_context];

if (evalFlag)
{
Expand Down
2 changes: 1 addition & 1 deletion objc/nu.m
Expand Up @@ -267,7 +267,7 @@ void NuInit()
[NSArray include: [NuClass classWithClass:[NuEnumerable class]]];
[NSSet include: [NuClass classWithClass:[NuEnumerable class]]];
[NSString include: [NuClass classWithClass:[NuEnumerable class]]];
[pool release];
[pool drain];

[NSObject exchangeInstanceMethod:@selector(dealloc) withMethod:@selector(nuDealloc)];

Expand Down
23 changes: 10 additions & 13 deletions objc/object.m
Expand Up @@ -112,7 +112,7 @@ - (NuSelectorCache *) lookupSymbol:(NuSymbol *)childSymbol
{
NuSelectorCache *child = [children objectForKey:childSymbol];
if (!child) {
child = [[NuSelectorCache alloc] initWithSymbol:childSymbol parent:self];
child = [[[NuSelectorCache alloc] initWithSymbol:childSymbol parent:self] autorelease];
NSString *selectorString = [child selectorName];
#ifdef DARWIN
[child setSelector:sel_registerName([selectorString cStringUsingEncoding:NSUTF8StringEncoding])];
Expand Down Expand Up @@ -254,17 +254,14 @@ - (id) sendMessage:(id)cdr withContext:(NSMutableDictionary *)context
[argValues addObject:[[args objectAtIndex:i] evalWithContext:context]];
}
// Then call the method.
if (sel == @selector(animator)) {
imax = 0; // break here
}
result = nu_calling_objc_method_handler(target, m, argValues);
[argValues release];
}
else {
// If the head of the list is a label, we treat the list as a property list.
// We just evaluate the elements of the list and return the result.
if (nu_objectIsKindOfClass(self, [NuSymbol class]) && [((NuSymbol *)self) isLabel]) {
NuCell *cell = [[NuCell alloc] init];
NuCell *cell = [[[NuCell alloc] init] autorelease];
[cell setCar: self];
id cursor = cdr;
id result_cursor = cell;
Expand All @@ -290,7 +287,7 @@ - (id) sendMessage:(id)cdr withContext:(NSMutableDictionary *)context

[args release];
[result retain];
[pool release];
[pool drain];
[result autorelease];
return result;
}
Expand All @@ -314,7 +311,7 @@ - (id) handleUnknownMessage:(id) cdr withContext:(NSMutableDictionary *) context
// This seems like a bottleneck, and it also lacks flexibility.
// Replacing explicit string building with the selector cache reduced runtimes by around 20%.
// Methods with variadic arguments (NSArray arrayWithObjects:...) are not supported.
NSMutableArray *args = [[NSMutableArray alloc] init];
NSMutableArray *args = [NSMutableArray array];
id cursor = cdr;
SEL sel = 0;
id nextSymbol = [cursor car];
Expand Down Expand Up @@ -461,7 +458,7 @@ - (void) nuDealloc

+ (NSArray *) classMethods
{
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *array = [NSMutableArray array];
unsigned int method_count;
#ifdef DARWIN
Method *method_list = class_copyMethodList(object_getClass([self class]), &method_count);
Expand All @@ -470,7 +467,7 @@ + (NSArray *) classMethods
#endif
int i;
for (i = 0; i < method_count; i++) {
[array addObject:[[NuMethod alloc] initWithMethod:method_list[i]]];
[array addObject:[[[NuMethod alloc] initWithMethod:method_list[i]] autorelease]];
}
free(method_list);
[array sortUsingSelector:@selector(compare:)];
Expand All @@ -479,7 +476,7 @@ + (NSArray *) classMethods

+ (NSArray *) instanceMethods
{
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *array = [NSMutableArray array];
unsigned int method_count;
#ifdef DARWIN
Method *method_list = class_copyMethodList([self class], &method_count);
Expand All @@ -488,7 +485,7 @@ + (NSArray *) instanceMethods
#endif
int i;
for (i = 0; i < method_count; i++) {
[array addObject:[[NuMethod alloc] initWithMethod:method_list[i]]];
[array addObject:[[[NuMethod alloc] initWithMethod:method_list[i]] autorelease]];
}
free(method_list);
[array sortUsingSelector:@selector(compare:)];
Expand All @@ -513,7 +510,7 @@ + (NSArray *) instanceMethodNames

+ (NSArray *) instanceVariableNames
{
NSMutableArray *array = [[NSMutableArray alloc] init];
NSMutableArray *array = [NSMutableArray array];
unsigned int ivar_count;
Ivar *ivar_list = class_copyIvarList([self class], &ivar_count);
int i;
Expand Down Expand Up @@ -557,7 +554,7 @@ + (id) createSubclassNamed:(NSString *) subclassName
s = objc_allocateClassPair(c, name, 0);
objc_registerClassPair(s);
}
NuClass *newClass = [[NuClass alloc] initWithClass:s];
NuClass *newClass = [[[NuClass alloc] initWithClass:s] autorelease];

if ([self respondsToSelector:@selector(inheritedByClass:)]) {
[self inheritedByClass:newClass];
Expand Down

0 comments on commit add9113

Please sign in to comment.