[MacRuby] #1339: macruby crashes when initialize() with optional arg called from File.open block

MacRuby ruby-noreply at macosforge.org
Thu Jun 23 16:03:13 PDT 2011


#1339: macruby crashes when initialize() with optional arg called from File.open
block
-------------------------------+--------------------------------------------
 Reporter:  bigwood@…          |       Owner:  lsansonetti@…        
     Type:  defect             |      Status:  new                  
 Priority:  critical           |   Milestone:  MacRuby 0.11         
Component:  MacRuby            |    Keywords:                       
-------------------------------+--------------------------------------------
 the following script will always crash.
 0) TTT.initialize() must have an optional argument (past the first
 argument)
 1) TTT.new() has to be called from a File.open() block

 #!/usr/local/bin/macruby -w

 # see http://www.macruby.org/documentation/gcd.html
 class Array
   def parallel_map(&block)
     result = []
     # Creating a group to synchronize block execution.
     group = Dispatch::Group.new
     # We will access the `result` array from within this serial queue,
     # as without a GIL we cannot assume array access to be thread-safe.
     result_queue = Dispatch::Queue.new('access-queue.#{result.object_id}')
     0.upto(size - 1) do |idx|
       # Dispatch a task to the default concurrent queue.
       Dispatch::Queue.concurrent.async(group) do
         #temp = block.call(self[idx])
         temp = block[self[idx]] # same
         #temp = block === self[idx] # same
         #puts "sending #{idx}: #{self[idx]} with #{block.class}\n"
         result_queue.async(group) { result[idx] = temp }
       end
     end
     # Wait for all the blocks to finish.
     group.wait
     result
   end
 end

 class TTT
   #def initialize(string)
   def initialize(string, dup = false)
   end
 end


 source =  $0
 (1..2).to_a.parallel_map do |idx|
   #puts idx
   File.open(source) do |file|
   #Dir.chdir("/tmp") do
     TTT.new("")
   end
 end

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/1339>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list