[MacRuby] #1029: Possible PDFKit bug
#1029: Possible PDFKit bug ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- I encountered an error using block with PDFDocument's findString:withOptions: Sample.rb {{{ #!/usr/local/bin/macruby framework 'cocoa';framework 'Quartz' PDFDocument.alloc.initWithURL(NSURL.fileURLWithPath("sample.pdf")).findString("the",withOptions:NSCaseInsensitiveSearch).each{|x| p x.string} }}} 'sample.pdf' is an academic journal PDF with about 12000 words in English. Along with this, I also tried .map{|x| x.string} instead of .each{} and got the same errors. The error messages I got are (multiple, all while processing the block): {{{ => NSInvalidArgumentException: -[CPCharacterIndex count]: unrecognized selector sent to instance (RuntimeError Error) => NSRangeException: *** -[NSCFArray objectAtIndex:]: index (220) beyond bounds (2) (RuntimeError) => [CPZoneBorderIntersection count]: unrecognized selector sent to instance => Segmentation fault }}} As suggested by Laurent, I set GC_DISABLE = 1 when I run this script (though I'm not sure if I did it correctly). Then this script ran without any problem. {{{ $ GC_DISABLE=1 macruby sample.rb => expected result ("the"/"The") }}} Also, without using block, I got an array of PDFSelection objects without an error. {{{ p PDFDocument.alloc.initWithURL(NSURL.fileURLWithPath("sample.pdf")).findString("the",withOptions:NSCaseInsensitiveSearch) => an array of "PDFSelection" objects }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1029> MacRuby <http://macruby.org/>
#1029: Possible PDFKit bug ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): If the snippet runs fine with GC_DISABLE, then I suspect a bug in PDFKit itself. We need to rewrite the snippet in pure Objective-C and see if it still crashes. -- Ticket URL: <http://www.macruby.org/trac/ticket/1029#comment:1> MacRuby <http://macruby.org/>
#1029: Possible PDFKit bug ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by yasuimao@…): I forgot to mention that the same process runs without returning error in RubyCocoa. -- Ticket URL: <http://www.macruby.org/trac/ticket/1029#comment:2> MacRuby <http://macruby.org/>
#1029: Possible PDFKit bug ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): Yes but RubyCocoa does not use the Objective-C GC. -- Ticket URL: <http://www.macruby.org/trac/ticket/1029#comment:3> MacRuby <http://macruby.org/>
#1029: Possible PDFKit bug ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): Here is an Objective-C implementation of your snippet: {{{ #import <Cocoa/Cocoa.h> #import <Quartz/Quartz.h> int main(void) { PDFDocument *doc = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"sample.pdf"]]; for (id result in [doc findString:@"the" withOptions:NSCaseInsensitiveSearch]) { NSLog(@"found %@", result); } return 0; } }}} Could you save it as test.m, then compile and run using: {{{ $ gcc test.m -o test -fobjc-gc -framework Cocoa -framework Quartz $ ./test }}} And let me know if you see the crash? -- Ticket URL: <http://www.macruby.org/trac/ticket/1029#comment:4> MacRuby <http://macruby.org/>
#1029: Possible PDFKit bug ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by yasuimao@…): I was able to run it 10 times without crash. -- Ticket URL: <http://www.macruby.org/trac/ticket/1029#comment:5> MacRuby <http://macruby.org/>
#1029: Possible PDFKit bug ----------------------------------+----------------------------------------- Reporter: yasuimao@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): This is a very strange bug. I'm 99% convinced that this is a bug in PDFKit, as it seems that the internal PDFSelection objects get corrupted during the -findString:withOptions: call. In 10.6.5 I am able to reproduce the crash from MacRuby but can't reproduce it from pure Objective-C, yet. A temporary workaround is to pause the collection when calling findString:withOptions:. {{{ GC.disable ary = doc.findString("the", withOptions:NSCaseInsensitiveSearch) GC.enable }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1029#comment:6> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby