-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature #20507] Allow compilation of C extensions with -Wconversion
#10843
[Feature #20507] Allow compilation of C extensions with -Wconversion
#10843
Conversation
6f496f6
to
f13b5f7
Compare
Enclose them using |
f13b5f7
to
043b339
Compare
Any way to write a regression test for this? I fear we may re-introduce such warnings without noticing. |
@casperisfine A regression test would be as easy as running Short term, if there are regressions, I'll see them and then at that point I will surely try to address it. |
C extension maintainers can now compile with this warning option and the Ruby header files will generate no warnings. [Feature #20507]
043b339
to
197f9a7
Compare
@casperisfine I've added a regression test. Would love feedback. |
This comment has been minimized.
This comment has been minimized.
Under compilers with WERRORFLAG, MakeMakefile.try_compile treats warnings as errors, so we can use append_cflags to test whether the public header files emit warnings with certain flags turned on. [Regression test for feature #20507]
197f9a7
to
69ca057
Compare
I'm really no expert, but the extconf make sense and should prevent regressions from what I can tell. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now!
**What problem is this PR intended to solve?** While working with @stevecheckoway on #3205, we caught an edge case in how the `max_depth` parameter was converted from signed to unsigned int. It turned out that it would have been caught much earlier with the `-Wconversion` flag, but that flag is useless in Ruby C extensions because of the issue described at https://bugs.ruby-lang.org/issues/20507 That issue was fixed in Ruby 3.4-dev by ruby/ruby#10843 and so I'm using it here and fixing the compilation warnings it flags. **Have you included adequate test coverage?** N/A **Does this change affect the behavior of either the C or the Java implementations?** N/A
https://bugs.ruby-lang.org/issues/20507
As a maintainer of several C extensions, I like to compile my code with some of the common Warning Options to help maintain code quality and safety.
One of the options that is currently very difficult to use is
-Wsign-conversion
, because some of the Ruby public header files contain code that will generate warnings. So many warnings are printed when compiling against Ruby's header files that it's hard to see any warnings from my code.As an example, compiling just one file in Nokogiri with this flag enabled will print:
Compiling all 35 files in Nokogiri's C extension means these warnings are repeated another 34 times in a full build. This makes it difficult to see any conversion errors in my own code.
This pull request adds casts where there are intentional, known-safe integer conversions occurring that are triggering these warnings.
If merged, then C extension owners can add this to their
extconf.rb
:and then any warnings generated are from the C extension code, and not from Ruby's header files.