Skip to content

Return nil from Signal.signame for an unknown signal - #10098

Open
sferik wants to merge 2 commits into
jruby:masterfrom
sferik:signame-returns-nil
Open

sferik wants to merge 2 commits into
jruby:masterfrom
sferik:signame-returns-nil

Conversation

@sferik

@sferik sferik commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Signal.signame raised an ArgumentError for a number with no signal name, like Signal.signame(99). CRuby returns nil there, because sig_signame returns nil when signo2signm finds no name:

https://github.com/ruby/ruby/blob/06b18f11f4b0078e2683c661e7762fff7c04636c/signal.c#L310-L315

This makes JRuby return nil too. Signal.signame(0) still returns "EXIT". trap already treats a nil from signame as an invalid number, so trap(99) {} still raises ArgumentError as before.

There was already a spec for this in spec/ruby/core/signal/signame_spec.rb, so I removed its failing tag. I also added a spec that an out-of-range number raises RangeError, like CRuby's NUM2INT does. JRuby already did that, but nothing tested it. I ran spec/ruby/core/signal on JRuby, and the signame spec with the JIT and on CRuby too. They all pass.

One thing I noticed but didn't change: signame_tags.txt has a stale duplicate tag with the old spelling "precendence".

Fixes #10094

CRuby's sig_signame returns nil when signo2signm has no name for the
number, but JRuby raised an ArgumentError. Return nil instead and
remove the tag for the spec that now passes.

Fixes jruby#10094
CRuby converts the argument with NUM2INT, which raises RangeError
when the number doesn't fit in an int. JRuby already does the same,
but no spec covered it.
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.

Signal.signame raises instead of returning nil for unknown values

2 participants