Skip navigation.
 
mlMethods with Variable Numbers of Arguments
FROM : Joe Osborn
DATE : Sat Dec 14 23:56:56 2002

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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlMethods with Variable Numbers of Arguments Joe Osborn Dec 14, 23:56
mlRe: Methods with Variable Numbers of Arguments Joe Osborn Dec 15, 00:17
mlRe: Methods with Variable Numbers of Arguments matt neuburg Dec 17, 18:38
mlRe: Methods with Variable Numbers of Arguments Joe Osborn Dec 17, 22:30
mlRe: Methods with Variable Numbers of Arguments matt neuburg Dec 17, 23:02
mlRe: Methods with Variable Numbers of Arguments Joe Osborn Dec 18, 05:04