Skip to content
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

Remove "unused parameter" warnings on include of ruby.h #7085

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

flashcode
Copy link
Contributor

@flashcode flashcode commented Jan 7, 2023

This pull request removes "unused parameter" warnings when compiling with flag -Wunused-parameter (or with -Wall -Wextra).

The fix consists in fooling the compiler by adding a no-op instruction using the argument, like:

    (void)obj;

Steps to reproduce

  1. Create a C source called test_ruby.c, with this content:
#include <ruby.h>

int main()
{
    return 0;
}
  1. Compile the program with this command (using Ruby 3.1.0, but I'm pretty sure the problem is still there with latest versions):
gcc -Wunused-parameter -o test_ruby $(pkg-config --cflags ruby-3.1) $(pkg-config --libs ruby-3.1) test_ruby.c

Actual result

$ gcc -Wunused-parameter -o test_ruby $(pkg-config --cflags ruby-3.1) $(pkg-config --libs ruby-3.1) test_ruby.c 
In file included from /usr/include/ruby-3.1.0/ruby/internal/core/rstring.h:30,
                 from /usr/include/ruby-3.1.0/ruby/internal/arithmetic/char.h:29,
                 from /usr/include/ruby-3.1.0/ruby/internal/arithmetic.h:23,
                 from /usr/include/ruby-3.1.0/ruby/ruby.h:27,
                 from /usr/include/ruby-3.1.0/ruby.h:38,
                 from test_ruby.c:1:
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h: In function ‘RB_OBJ_TAINTABLE’:
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:794:24: warning: unused parameter ‘obj’ [-Wunused-parameter]
  794 | RB_OBJ_TAINTABLE(VALUE obj)
      |                  ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h: In function ‘RB_OBJ_TAINTED_RAW’:
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:811:26: warning: unused parameter ‘obj’ [-Wunused-parameter]
  811 | RB_OBJ_TAINTED_RAW(VALUE obj)
      |                    ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h: In function ‘RB_OBJ_TAINTED’:
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:828:22: warning: unused parameter ‘obj’ [-Wunused-parameter]
  828 | RB_OBJ_TAINTED(VALUE obj)
      |                ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h: In function ‘RB_OBJ_TAINT_RAW’:
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:843:24: warning: unused parameter ‘obj’ [-Wunused-parameter]
  843 | RB_OBJ_TAINT_RAW(VALUE obj)
      |                  ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h: In function ‘RB_OBJ_TAINT’:
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:858:20: warning: unused parameter ‘obj’ [-Wunused-parameter]
  858 | RB_OBJ_TAINT(VALUE obj)
      |              ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h: In function ‘RB_OBJ_INFECT_RAW’:
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:874:25: warning: unused parameter ‘dst’ [-Wunused-parameter]
  874 | RB_OBJ_INFECT_RAW(VALUE dst, VALUE src)
      |                   ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:874:36: warning: unused parameter ‘src’ [-Wunused-parameter]
  874 | RB_OBJ_INFECT_RAW(VALUE dst, VALUE src)
      |                              ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h: In function ‘RB_OBJ_INFECT’:
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:890:21: warning: unused parameter ‘dst’ [-Wunused-parameter]
  890 | RB_OBJ_INFECT(VALUE dst, VALUE src)
      |               ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/fl_type.h:890:32: warning: unused parameter ‘src’ [-Wunused-parameter]
  890 | RB_OBJ_INFECT(VALUE dst, VALUE src)
      |                          ~~~~~~^~~
In file included from /usr/include/ruby-3.1.0/ruby/ruby.h:44:
/usr/include/ruby-3.1.0/ruby/internal/newobj.h: In function ‘rb_clone_setup’:
/usr/include/ruby-3.1.0/ruby/internal/newobj.h:173:22: warning: unused parameter ‘clone’ [-Wunused-parameter]
  173 | rb_clone_setup(VALUE clone, VALUE obj)
      |                ~~~~~~^~~~~
/usr/include/ruby-3.1.0/ruby/internal/newobj.h:173:35: warning: unused parameter ‘obj’ [-Wunused-parameter]
  173 | rb_clone_setup(VALUE clone, VALUE obj)
      |                             ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/newobj.h: In function ‘rb_dup_setup’:
/usr/include/ruby-3.1.0/ruby/internal/newobj.h:190:20: warning: unused parameter ‘dup’ [-Wunused-parameter]
  190 | rb_dup_setup(VALUE dup, VALUE obj)
      |              ~~~~~~^~~
/usr/include/ruby-3.1.0/ruby/internal/newobj.h:190:31: warning: unused parameter ‘obj’ [-Wunused-parameter]
  190 | rb_dup_setup(VALUE dup, VALUE obj)
      |                         ~~~~~~^~~

Expected result

No warnings at all.

Additional info

This was caused by commit 0300dec and affects versions 3.1.0 and above.

The fix has been tested with gcc and clang versions on Debian unstable:

$ gcc --version
gcc (Debian 12.2.0-13) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang --version
Debian clang version 14.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

The fix has NOT been tested with Ruby version > 3.1.0; other functions may be affected by the similar warning in newer releases (I did not fully check).

These warnings are displayed when compiling with flag "-Wunused-parameter" (or
with "-Wall -Wextra").
Copy link
Member

@shyouhei shyouhei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. As these functions remain for backward compatibility only, I have 0 motivation to actually use those parameters. This fix seems valid.

@jwillemsen
Copy link
Contributor

jwillemsen commented Feb 27, 2023

Why not just remove the argument name, so for example make it

static inline bool
RB_OBJ_TAINTABLE(VALUE)
{
    return false;
}

@shyouhei
Copy link
Member

@jwillemsen That's too new. We have to use the C language of '90s in this project.

@shyouhei shyouhei merged commit 97b53d1 into ruby:master Feb 28, 2023
@jwillemsen
Copy link
Contributor

@jwillemsen That's too new. We have to use the C language of '90s in this project.

Ok, it has been fixed now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants