Handle non-string keys returning immediate values via to_s#792
Merged
Conversation
365c4b9 to
b2cd83f
Compare
We can't directly call `RBASIC_CLASS` as the return value of `to_s` may be an immediate.
b2cd83f to
12dc394
Compare
eregon
reviewed
Apr 27, 2025
| { | ||
| VALUE key_to_s = rb_funcall(key, i_to_s, 0); | ||
|
|
||
| if (RB_UNLIKELY(rb_type(key_to_s) != T_STRING)) { |
Member
There was a problem hiding this comment.
RB_TYPE_P() might be faster: https://github.com/ruby/ruby/blob/3ec7bfff2e7ac4f6f69d26676edcfd2e73ea3b05/include/ruby/internal/value_type.h#L376
Member
There was a problem hiding this comment.
Ah it doesn't handle T_STRING explicitly currently, so I guess it's the same, but maybe in the future it might?
Member
Author
There was a problem hiding this comment.
This is an unlucky path, so I don't think it matter too much, but it's nicer to read, so I changed it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We can't directly call
RBASIC_CLASSas the return value ofto_smay be an immediate.