Methods with Variable Numbers of Arguments
Methods with Variable Numbers of Arguments
- Subject: Methods with Variable Numbers of Arguments
- From: Joe Osborn <email@hidden>
- Date: Sat, 14 Dec 2002 16:56:56 -0600
I'm getting a weird bug by which NSConstantStrings suddenly
explode(EXC_BAD_ACCESS) when passed to a method I'm writing that takes
a variable number of arguments. I highly doubt that NSConstantString
has broken over the last three hours, and thus the blame probably falls
on how I've written my variable-number-of-argument-taking method.
Here's the prototype:
#import <stdarg.h>
...
+(OSBlock *)blockWithString:(NSString *)blockString
nouns:(id)firstNoun, ...;
and the guts("(bk)" indicates breakpoint):
+(OSBlock *)blockWithString:(NSString *)blockString
nouns:(id)firstNoun, ...
{
(bk)NSArray * nounNames = [OSBlockScanner
nounNamesInBlockString:blockString];
OSEnumerator * enumerator = [nounNames objectOSEnumerator];
NSMutableArray * nouns = [NSMutableArray
arrayWithCapacity:[nounNames count]];
va_list ap;
va_start(ap, firstNoun);
[nouns addObject:firstNoun];
[enumerator nextObject];
while([enumerator nextObject])
{
[nouns addObject:va_arg(ap, id)];
}
va_end(ap);
return [OSBlock blockWithString:blockString inContext:[NSDictionary
dictionaryWithObjects:nouns forKeys:nounNames]];
}
My test case is like this:
#import "OSBlock.h"
-(void)testBlocks
{
OSBlock * block = [OSBlock blockWithString:@"[self
workEffectively]; return [NSData class];" nouns:self, [NSData class]];
....
should([self workedEffectively]);
}
and the debugger, when it stops at (bk), tells me that "blockString" is
invalid. I try to print it out, and it EXC_BAD_ACCESSes. I'm a bit
confused.
Any help would be appreciated, please.
(By the way-- my project is an attempt to create "blocks" a la
smalltalk- first-class objects that represent a bunch of messagesends.)
--j.osborn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.