Methods with Variable Numbers of Arguments--Second Attempt
Methods with Variable Numbers of Arguments--Second Attempt
- Subject: Methods with Variable Numbers of Arguments--Second Attempt
- From: Joe Osborn <email@hidden>
- Date: Tue, 17 Dec 2002 11:11:26 -0600
I'm still at a loss, everyone, and I think my previous plea got lost in
noise.. Any help would be tremendous, thanks in advance.
I'm getting a weird bug by which NSConstantStrings suddenly explode
(EXC_BAD_ACCESS, vanish, lose most of their contents, otherwise act
unpredictably) 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, or is
otherwise weird. I'm a bit confused.
(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
"Blame yourself first. If that doesn't work, you must have done
something wrong."
--unknown(someone please attribute this)
_______________________________________________
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.