Skip to content

Commit

Permalink
Spec 'Signal.trap ignores the signal when passed nil' OK for rx19:
Browse files Browse the repository at this point in the history
  - extract Signal.trap from kernel/common/signal.rb to
    kernel/common/signal18.rb;
  - create a new file kernel/common/signal19.rb with new version for
    Signal.trap:
      - in case stattement, add a new +when nil+ statetement which
        set +prc+ to +nil+;
      - in +when "IGNORE", "SIG_IGN"+ statement, +prc+ is set to
        "IGNORE" string;
      - in Rubinius.watch_signal, replace +prc.nil?+ with
        +prc.nil? || prc == 'IGNORE'+;
      - return statements now return +nil+ when +old+ is false
        instead of "IGNORE";
  - modify kernel/common/load_order*.
  • Loading branch information
sdaubert committed Jan 6, 2013
1 parent d6de247 commit 62f6c84
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 56 deletions.
1 change: 1 addition & 0 deletions kernel/common/load_order18.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ random.rbc
regexp.rbc
regexp18.rbc
signal.rbc
signal18.rbc
splitter.rbc
splitter18.rbc
sprinter.rbc
Expand Down
1 change: 1 addition & 0 deletions kernel/common/load_order19.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ random19.rbc
regexp.rbc
regexp19.rbc
signal.rbc
signal19.rbc
splitter.rbc
splitter19.rbc
sprinter.rbc
Expand Down
1 change: 1 addition & 0 deletions kernel/common/load_order20.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ random19.rbc
regexp.rbc
regexp19.rbc
signal.rbc
signal19.rbc
splitter.rbc
splitter19.rbc
sprinter.rbc
Expand Down
56 changes: 0 additions & 56 deletions kernel/common/signal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,6 @@ module Signal
@threads = {}
@handlers = {}

def self.trap(sig, prc=nil, &block)
sig = sig.to_s if sig.kind_of?(Symbol)

if sig.kind_of?(String)
osig = sig

if sig.prefix? "SIG"
sig = sig[3..-1]
end

unless number = Names[sig]
raise ArgumentError, "Unknown signal '#{osig}'"
end
else
number = sig.to_i
end

# If no command, use the block.
prc ||= block

case prc
when "DEFAULT", "SIG_DFL"
had_old = @handlers.key?(number)
old = @handlers.delete(number)

if number != Names["EXIT"]
Rubinius.watch_signal(-number, prc.nil?)
end

return "DEFAULT" unless had_old
return old ? old : "IGNORE"
when "IGNORE", "SIG_IGN", nil
prc = nil
when "EXIT"
prc = proc { exit }
when String
raise ArgumentError, "Unsupported command '#{prc}'"
else
unless prc.respond_to? :call
raise ArgumentError, "Handler must respond to #call (was #{prc.class})"
end
end

had_old = @handlers.key?(number)

old = @handlers[number]
@handlers[number] = prc

if number != Names["EXIT"]
Rubinius.watch_signal(number, prc.nil?)
end

return "DEFAULT" unless had_old
return old ? old : "IGNORE"
end

def self.run_handler(sig)
# Ignore nil handlers
if handler = @handlers[sig]
Expand Down
61 changes: 61 additions & 0 deletions kernel/common/signal18.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- encoding: us-ascii -*-

module Signal

def self.trap(sig, prc=nil, &block)
sig = sig.to_s if sig.kind_of?(Symbol)

if sig.kind_of?(String)
osig = sig

if sig.prefix? "SIG"
sig = sig[3..-1]
end

unless number = Names[sig]
raise ArgumentError, "Unknown signal '#{osig}'"
end
else
number = sig.to_i
end

# If no command, use the block.
prc ||= block

case prc
when "DEFAULT", "SIG_DFL"
had_old = @handlers.key?(number)
old = @handlers.delete(number)

if number != Names["EXIT"]
Rubinius.watch_signal(-number, prc.nil?)
end

return "DEFAULT" unless had_old
return old ? old : "IGNORE"
when "IGNORE", "SIG_IGN", nil
prc = nil
when "EXIT"
prc = proc { exit }
when String
raise ArgumentError, "Unsupported command '#{prc}'"
else
unless prc.respond_to? :call
raise ArgumentError, "Handler must respond to #call (was #{prc.class})"
end
end

had_old = @handlers.key?(number)

old = @handlers[number]
@handlers[number] = prc

if number != Names["EXIT"]
Rubinius.watch_signal(number, prc.nil?)
end

return "DEFAULT" unless had_old
return old ? old : "IGNORE"
end

end
63 changes: 63 additions & 0 deletions kernel/common/signal19.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- encoding: us-ascii -*-

module Signal

def self.trap(sig, prc=nil, &block)
sig = sig.to_s if sig.kind_of?(Symbol)

if sig.kind_of?(String)
osig = sig

if sig.prefix? "SIG"
sig = sig[3..-1]
end

unless number = Names[sig]
raise ArgumentError, "Unknown signal '#{osig}'"
end
else
number = sig.to_i
end

# If no command, use the block.
prc ||= block

case prc
when "DEFAULT", "SIG_DFL"
had_old = @handlers.key?(number)
old = @handlers.delete(number)

if number != Names["EXIT"]
Rubinius.watch_signal(-number, prc.nil?)
end

return "DEFAULT" unless had_old
return old ? old : nil
when "IGNORE", "SIG_IGN"
prc = "IGNORE"
when nil
prc = nil
when "EXIT"
prc = proc { exit }
when String
raise ArgumentError, "Unsupported command '#{prc}'"
else
unless prc.respond_to? :call
raise ArgumentError, "Handler must respond to #call (was #{prc.class})"
end
end

had_old = @handlers.key?(number)

old = @handlers[number]
@handlers[number] = prc

if number != Names["EXIT"]
Rubinius.watch_signal(number, prc.nil? || prc == 'IGNORE')
end

return "DEFAULT" unless had_old
return old ? old : nil
end

end

0 comments on commit 62f6c84

Please sign in to comment.