Skip to content

Convert exit statuses that are not Objects, and SystemExit.new statuses, with to_int - #10112

Open
taxor03 wants to merge 1 commit into
jruby:jruby-10.0from
taxor03:fix-exit-status-conversion-10.0
Open

taxor03 wants to merge 1 commit into
jruby:jruby-10.0from
taxor03:fix-exit-status-conversion-10.0

Conversation

@taxor03

@taxor03 taxor03 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10106.

  • exit, exit! and Process.exit cast their argument to RubyObject before converting it, so a BasicObject status that is not an Object, such as a SimpleDelegator, raised a Java ClassCastException. The argument is now kept as an IRubyObject; the rest of the method already handled one. As with CRuby's exit_status_code (true, false or NUM2INT(status), process.c#L4341), exit(SimpleDelegator.new(3)) now exits with status 3, and a delegator of something that is not an Integer raises TypeError.
  • SystemExit#initialize took the first argument as the status only when it was a Fixnum or a boolean, and otherwise as the message. Like exit_initialize, which calls rb_check_to_int(status) (error.c#L2244), it is now the status when it is an Integer or to_int returns one, and the message otherwise. So SystemExit.new(obj) with obj.to_int returning 3 has status 3 and message "SystemExit". rb_check_to_int returns nil when to_int returns something else, so this calls to_int without the type check of Convert.checkToInteger, which would raise TypeError there. With the same change, SystemExit.new(3.7) has status 3 and SystemExit.new(2**70) keeps the Bignum as its status, as in CRuby 4.0.9 and 3.4.12; before, both were taken as the message with status 0.

This adds "converts an argument that is not an Object with #to_int" to the shared process_exit and process_exit! specs in spec/ruby/shared/process/exit.rb (run for Kernel#exit, Kernel.exit, Process.exit and the exit! variants), and "accepts a status that converts with #to_int" and "uses the argument as the message if #to_int does not return an Integer" to spec/ruby/core/exception/system_exit_spec.rb. The new examples fail before this change and pass after it, and pass on CRuby 4.0.9 and 3.4.12. Tested with spec/ruby/core/exception, spec/ruby/core/kernel/exit_spec.rb and spec/ruby/core/process/exit_spec.rb (also with -Xjit.threshold=0 and -X-C), test/mri/ruby/test_exception.rb and the fast RubySpec suite. No new failures.

On master exit has moved to Helpers.exit, so this does not merge forward cleanly. #10113 is the same change for master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant