From: Paul C Date: 2001-03-14T05:40:02+09:00 Subject: [ruby-talk:12580] Re: Strange segmentation fault problem with C++ extension - the plot thickens Having played around a but more it looks like the behaviour of the module when called within a begin/rescue block is a somewhat more complex that I had described earlier and depending on context I can get a segmentation fault in either ruby or IRB Some of the calling sequences I have tried are shown below. As far as I can work out the symptoms are - In Ruby: - The sequence {ok-fail-ok} works ok within a block context - The sequence {ok-fail-ok-ok} causes a segmentation fault - Multiple sequences of {ok-fail} in separate blocks are ok - Multiple sequences of {ok-fail-ok} cause a segmentation fault In IRB: - The sequence {ok-fail-ok} within a block always causes a segmentation fault - Multiple repetitions of an {ok-fail} are ok Also if I replace the 'raise' in the offending function with a 'return Qnil' all the problems go away. I am fairly sure that I have some sort of loose pointer in the code which gets reset with the block context however I havent been able to track anything down yet. Apologies for the length of the post and thanks in advance for everybodies help Regards, Paul ==== test_ok.rb : require 'Zip' : z = Zip::ZipFile.new "test.zip" : : begin : entry = z.entry "extconf.rb" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : begin : entry = z.entry "zzzzzz" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : begin : entry = z.entry "extconf.rb" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end # ruby test_ok.rb -> OK # irb test_ok.rb -> Segmentation Fault ==== test_ok2.rb : require 'Zip' : z = Zip::ZipFile.new "test.zip" : : 5.times { : begin : entry = z.entry "extconf.rb" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : begin : entry = z.entry "zzzzz" : print entry.inspect, "\n" #fails : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : } # ruby test_ok2.rb -> OK # irb test_ok2.rb -> OK ==== test_ok3.rb : require 'Zip' : z = Zip::ZipFile.new "test.zip" : : ["extconf.rb","zzzzzz"].each { |e| : begin : entry = z.entry e : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : } : : ["extconf.rb","zzzzzz"].each { |e| : begin : entry = z.entry e : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : } # ruby test_ok3.rb -> OK # irb test_ok3.rb -> Segmentation Fault # ruby test_ok3.rb -> OK # irb test_ok3.rb -> Segmentation Fault ==== test_fail.rb : require 'Zip' : z = Zip::ZipFile.new "test.zip" : : begin : entry = z.entry "extconf.rb" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : begin : entry = z.entry "zzzzzz" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : begin : entryntry = z.entry "extconf.rb" : print entryntry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : begin : entry = z.entry "extconf.rb" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end # ruby test_fail.rb -> Segmentation Fault # irb test_fail.rb -> Segmentation Fault ==== test_fail2.rb :require 'Zip' : :z = Zip::ZipFile.new "test.zip" : :5.times { : : begin : entry = z.entry "extconf.rb" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : begin : entry = z.entry "zzzzz" : print entry.inspect, "\n" #fails : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : begin : entry = z.entry "extconf.rb" : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end :} # ruby test_fail2.rb -> Segmentation Fault # irb test_fail2.rb -> Segmentation Fault ==== test_fail3.rb : require 'Zip' : z = Zip::ZipFile.new "test.zip" : : ["extconf.rb","zzzzzz","extconf.rb"].each { |e| : : begin : entry = z.entry e : print entry.inspect, "\n" : rescue RuntimeError => err : print "Caught Exception: #{err}\n" : end : : } # ruby test_fail3.rb -> Segmentation Fault # irb test_fail3.rb -> Segmentation Fault