Skip to content

Commit

Permalink
Fix Process.exit[!]. Fixes #247. Fixes #248.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed Apr 5, 2010
1 parent 877d16f commit 26c82a3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
27 changes: 24 additions & 3 deletions kernel/alpha.rb
Expand Up @@ -165,7 +165,7 @@ def raise(cls, str, junk=nil)
Rubinius::VM.write_error str
Rubinius::VM.write_error "\n"
Rubinius::VM.show_backtrace
Process.exit 1
Process.exit! 1
end

# Returns true if the given Class is either the class or superclass of the
Expand Down Expand Up @@ -423,9 +423,30 @@ def to_s
class Process
# Terminate with given status code.
#
def self.exit(code)
def self.exit(code=0)
case code
when true
code = 0
when false
code = 1
else
code = Type.coerce_to code, Integer, :to_int
end

raise SystemExit.new(code)
end

def self.exit!(code=1)
Ruby.primitive :vm_exit
raise PrimitiveFailure, "exit() failed. Wow, something is screwed."

case code
when true
exit! 0
when false
exit! 1
else
exit! Type.coerce_to(code, Integer, :to_int)
end
end
end

Expand Down
14 changes: 3 additions & 11 deletions kernel/common/kernel.rb
Expand Up @@ -148,20 +148,12 @@ def warning(message)
module_function :warning

def exit(code=0)
if code.equal? true
code = 0
elsif code.equal? false
code = 1
else
code = Type.coerce_to code, Integer, :to_int
end

raise SystemExit.new(code)
Process.exit(code)
end
module_function :exit

def exit!(code=0)
Process.exit(code)
def exit!(code=1)
Process.exit!(code)
end
module_function :exit!

Expand Down
3 changes: 0 additions & 3 deletions kernel/common/process.rb
Expand Up @@ -102,9 +102,6 @@ def self.abort(msg=nil)
$stderr.puts(msg) if(msg)
exit 1
end
def self.exit!(code=0)
exit(code)
end

def self.getpgid(pid)
ret = FFI::Platform::POSIX.getpgid(pid)
Expand Down
8 changes: 4 additions & 4 deletions kernel/loader.rb
Expand Up @@ -418,7 +418,7 @@ def script
else
if @script.suffix?(".rb")
puts "Unable to find '#{@script}'"
exit! 1
exit 1
else
prog = File.join @main_lib, "bin", "#{@script}.rb"
if File.exist? prog
Expand Down Expand Up @@ -491,7 +491,7 @@ def epilogue

# Exit.
def done
Process.exit @exit_code
Process.exit! @exit_code
end

# Orchestrate everything.
Expand Down Expand Up @@ -522,6 +522,7 @@ def main
rescue Object => e
e.render "An exception occurred #{@stage}"
@exit_code = 1

ensure
epilogue
done
Expand All @@ -535,7 +536,6 @@ def main
puts "\n====================================="
puts "Exception occurred during top-level exception output! (THIS IS BAD)"
puts
puts "Original Exception: #{e.inspect} (#{e.class})"
puts "New Exception: #{e2.inspect} (#{e.class})"
puts "Exception: #{exc.inspect} (#{exc.class})"
@exit_code = 128
end

0 comments on commit 26c82a3

Please sign in to comment.