<commit_before>module Signal
  Names = {"EXIT" => 0}

  @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

      if sig == "EXIT"
        at_exit(&block)
        return
      end

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

      if number == 0
        at_exit(&block)
        return
      end
    end

    if prc and block
      raise ArgumentError, "Either a Proc/String or a block, not both."
    elsif block
      prc = block
    end

    case prc
    when "DEFAULT", "_DFL"
      old = @handlers.delete(number)
      Rubinius.watch_signal -number
      return old
    when "IGNORE", "_IGN"
      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"
      end
    end

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

    Rubinius.watch_signal number

    return old
  end

  def self.run_handler(sig)
    # Ignore nil handlers
    if handler = @handlers[sig]
      handler.call(sig)
    end
  end

  def self.list
    Names.dup
  end

end<commit_msg>Fix Signal.trap<commit_after>module Signal
  Names = {"EXIT" => 0}

  @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

      if sig == "EXIT"
        at_exit(&block)
        return
      end

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

      if number == 0
        at_exit(&block)
        return
      end
    end

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

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

      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

    Rubinius.watch_signal number

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

  def self.run_handler(sig)
    # Ignore nil handlers
    if handler = @handlers[sig]
      handler.call(sig)
    end
  end

  def self.list
    Names.dup
  end

end
{'fraction_non_alphanumeric': 0.10438626317579054, 'fraction_numerical': 0.0027201632097925877, 'mean_word_length': 1.9837728194726165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4975574', 'n_tokens_mistral': 1023, 'n_tokens_neox': 991, 'n_words': 278}