Constants defined in C extensions might be attributed other the gems#2555
Merged
Constants defined in C extensions might be attributed other the gems#2555
Conversation
Some constants like `ERB::Escape` that are defind in C extension components of gems are currently failing the `defined_in_gem?` look up. This happens for `ERB::Escape` because, instead of `erb/lib/erb/utils.rb` loading the shared-object for `escape`, we have `erubi` loading it. Thus, when we do the backtrace scan to find the file that is loading the constant we attribute it to the `erubi` gem. This is because there are no frames in the backtrace for the class definition coming from a C extension, thus we miss the actual file that does the `ERB::Escape` definition. Since we can look up the source location of constants now, it makes more sense to include that in the list of file candidate locations. Which makes it resilient against these kinds of mistakes.
e7069c0 to
1b8d4a3
Compare
vinistock
approved these changes
Mar 26, 2026
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.
Motivation
Some constants like
ERB::Escapethat are defind in C extension components of gems are currently failing thedefined_in_gem?look up.This happens for
ERB::Escapebecause, instead oferb/lib/erb/utils.rbloading the shared-object forescape, we haveerubiloading it. Thus, when we do the backtrace scan to find the file that is loading the constant we attribute it to theerubigem. This is because there are no frames in the backtrace for the class definition coming from a C extension, thus we miss the actual file that does theERB::Escapedefinition.Implementation
Since we can look up the source location of constants now, it makes more sense to include that in the list of file candidate locations. Which makes it resilient against these kinds of mistakes.
Tests
No added tests