mruby-exit: fix SystemExit#status inaccessible from Ruby#6890
Conversation
MRB_SYM(status) stores the exit status under the plain `status` symbol, which is invisible to Ruby's ivar machinery. Switch both the write site in mruby_exit.c and the read macro MRB_EXC_EXIT_STATUS in error.h to MRB_IVSYM(status) so the value is stored under `@status` and C callers remain consistent. Also add SystemExit#status accessor in mrblib to match CRuby behaviour. https://claude.ai/code/session_018JRpuKQBupCU8iNrvdtrmv
There was a problem hiding this comment.
Code Review
This pull request updates the SystemExit implementation in mruby by changing the status symbol from MRB_SYM(status) to MRB_IVSYM(status) and introducing a SystemExit#status reader in Ruby. The reviewer suggested implementing a custom initialize method for SystemExit to match CRuby's behavior and ensure @status is correctly initialized when SystemExit is instantiated directly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| class SystemExit | ||
| def status | ||
| @status | ||
| end | ||
| end |
There was a problem hiding this comment.
To fully match CRuby's behavior and prevent SystemExit#status from returning nil when SystemExit is instantiated directly (e.g., via SystemExit.new), we should implement a custom initialize method that supports the standard arguments: SystemExit.new(status), SystemExit.new(status, message), and SystemExit.new(message). This ensures @status is always initialized to a valid integer (defaulting to 0), matching CRuby's behavior.
class SystemExit
def initialize(*args)
status = 0
message = nil
if args.size == 1
if args[0].is_a?(Integer)
status = args[0]
else
message = args[0]
end
elsif args.size >= 2
status = args[0]
message = args[1]
end
if message
super(message)
else
super()
end
@status = status
end
def status
@status
end
end
Problem
mruby-exitstores the exit status usingMRB_SYM(status)(plainstatussymbol) instead ofMRB_IVSYM(status)(@statusivar symbol). Ruby's instance variable machinery only enumerates and accesses@-prefixed names, so the value is unreachable from Ruby code:The internal
MRB_EXC_EXIT_STATUSmacro inerror.hreads with the same wrong symbol, so C consumers (e.g.MRB_EXC_CHECK_EXIT) work correctly — but Ruby callers diverge from CRuby behaviour. All other exception ivars insrc/error.c(@name,@args) consistently useMRB_IVSYM.Fixes #6888.
Changes
mruby_exit.c:MRB_SYM(status)→MRB_IVSYM(status)at the write siteerror.h:MRB_EXC_EXIT_STATUSmacro updated to match (C callers remain consistent)mrblib/mruby-exit.rb: addSystemExit#statusaccessor to match CRubyAfter
Generated by Claude Code