pegkit icon indicating copy to clipboard operation
pegkit copied to clipboard

-[PKReader setString:] conflict terminates app due to Assertion failure

Open 98B opened this issue 8 years ago • 0 comments

Hi, some designated initializer[s] will setString: and also setStream: properties, more than once, it seems, and in a way that makes NSAssert(!_stream, @"") fail in PKReader.

For minimizing the problem description, I had ParserGenApp work on the following grammar, using defaults, and produce AParser.[hm]:

  a = 'A'
    ;

Then, I ran this command line utility:

#import <Foundation/Foundation.h>
#import <PEGKit/PEGKit.h>
#import "AParser.h"

void startParsing(NSInputStream* input) {
    NSError* report;
    PKParser* simplyA = [[AParser alloc] initWithDelegate:nil];
    [simplyA parseStream:input error:&report];
}

int main(int argc, const char * argv[]) {
    NSData* const pseudoFile = [@"A" dataUsingEncoding:NSUTF8StringEncoding];
    
    @autoreleasepool {
        NSInputStream* input = [NSInputStream inputStreamWithData:pseudoFile];
        startParsing(input);
    }
    return 0;
}

which terminated with backtrace, the second time setString: was called:

  ...
  4   PEGKit  0x0000000100013d1c -[PKReader setString:] + 204
  ...

Following call sequences with breakpoints set at -[PKReader setString:] and at -[PKReader setStream:] reveals that a stream is set (as expected), and then, later, another setString:nil effectively asserts the stream to be nil, which it isn't.

Is the above program using the PK-types properly?

98B avatar Jan 15 '17 09:01 98B