From c99b57bedc6bfc0e298ff686b1f4935845abaec2 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 29 May 2020 09:53:14 -0700 Subject: [PATCH] Make -W:no-deprecated silence rb_scan_args warnings These are deprecation warnings, so -W:no-deprecated should silence them. Fixes [Bug #16522] --- class.c | 18 +++++++++++++----- error.c | 2 +- include/ruby/ruby.h | 18 +++++++++++++----- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/class.c b/class.c index c866d1d727..555fe57108 100644 --- a/class.c +++ b/class.c @@ -1956,6 +1956,14 @@ struct rb_scan_args_t { VALUE *tmp_buffer; }; +static void +warn_deprecated(const char *msg) +{ + if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) { + rb_warn(msg); + } +} + static void rb_scan_args_parse(int kw_flag, int argc, const VALUE *argv, const char *fmt, struct rb_scan_args_t *arg) { @@ -2035,7 +2043,7 @@ rb_scan_args_parse(int kw_flag, int argc, const VALUE *argv, const char *fmt, st not specified and arguments are given more than sufficient. This will be removed in Ruby 3. */ if (!arg->f_var && arg->n_mand + arg->n_opt < argc) { - rb_warn("The last argument is nil, treating as empty keywords"); + warn_deprecated("The last argument is nil, treating as empty keywords"); argc--; } } @@ -2051,14 +2059,14 @@ rb_scan_args_parse(int kw_flag, int argc, const VALUE *argv, const char *fmt, st if (!keyword_given && !last_hash_keyword) { /* Warn if treating positional as keyword, as in Ruby 3, this will be an error */ - rb_warn("Using the last argument as keyword parameters is deprecated"); + warn_deprecated("Using the last argument as keyword parameters is deprecated"); } argc--; } else { /* Warn if splitting either positional hash to keywords or keywords to positional hash, as in Ruby 3, no splitting will be done */ - rb_warn("The last argument is split into positional and keyword parameters"); + warn_deprecated("The last argument is split into positional and keyword parameters"); arg->last_idx = argc - 1; } arg->hash = opts ? opts : Qnil; @@ -2066,7 +2074,7 @@ rb_scan_args_parse(int kw_flag, int argc, const VALUE *argv, const char *fmt, st } else if (arg->f_hash && keyword_given && arg->n_mand == argc) { /* Warn if treating keywords as positional, as in Ruby 3, this will be an error */ - rb_warn("Passing the keyword argument as the last hash parameter is deprecated"); + warn_deprecated("Passing the keyword argument as the last hash parameter is deprecated"); } } if (arg->f_hash && arg->n_mand == argc+1 && empty_keyword_given) { @@ -2075,7 +2083,7 @@ rb_scan_args_parse(int kw_flag, int argc, const VALUE *argv, const char *fmt, st ptr[argc] = rb_hash_new(); argc++; *(&argv) = ptr; - rb_warn("Passing the keyword argument as the last hash parameter is deprecated"); + warn_deprecated("Passing the keyword argument as the last hash parameter is deprecated"); } arg->argc = argc; diff --git a/error.c b/error.c index 9557d8552b..bae3c88f3b 100644 --- a/error.c +++ b/error.c @@ -128,7 +128,7 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, return exc; } -static unsigned int warning_disabled_categories; +unsigned int warning_disabled_categories; static unsigned int rb_warning_category_mask(VALUE category) diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 9b7c9842f8..3bf1daf789 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -2512,6 +2512,14 @@ rb_scan_args_set(int argc, const VALUE *argv, int f_var, int f_hash, int f_block, VALUE *vars[], char *fmt, int varc)); +extern unsigned int warning_disabled_categories; + +/* 1: RB_WARN_CATEGORY_DEPRECATED */ +#define WARN_DEPRECATED(msg) \ + if (!(warning_disabled_categories & 1)) { \ + rb_warn(msg); \ + } + inline int rb_scan_args_set(int argc, const VALUE *argv, int n_lead, int n_opt, int n_trail, @@ -2553,7 +2561,7 @@ rb_scan_args_set(int argc, const VALUE *argv, not specified and arguments are given more than sufficient. This will be removed in Ruby 3. */ if (!f_var && n_mand + n_opt < argc) { - rb_warn("The last argument is nil, treating as empty keywords"); + WARN_DEPRECATED("The last argument is nil, treating as empty keywords"); argc--; } } @@ -2569,14 +2577,14 @@ rb_scan_args_set(int argc, const VALUE *argv, if (!keyword_given) { /* Warn if treating positional as keyword, as in Ruby 3, this will be an error */ - rb_warn("Using the last argument as keyword parameters is deprecated"); + WARN_DEPRECATED("Using the last argument as keyword parameters is deprecated"); } argc--; } else { /* Warn if splitting either positional hash to keywords or keywords to positional hash, as in Ruby 3, no splitting will be done */ - rb_warn("The last argument is split into positional and keyword parameters"); + WARN_DEPRECATED("The last argument is split into positional and keyword parameters"); last_idx = argc - 1; } hash = opts ? opts : Qnil; @@ -2584,7 +2592,7 @@ rb_scan_args_set(int argc, const VALUE *argv, } else if (f_hash && keyword_given && n_mand == argc) { /* Warn if treating keywords as positional, as in Ruby 3, this will be an error */ - rb_warn("Passing the keyword argument as the last hash parameter is deprecated"); + WARN_DEPRECATED("Passing the keyword argument as the last hash parameter is deprecated"); } } if (f_hash && n_mand > 0 && n_mand == argc+1 && empty_keyword_given) { @@ -2593,7 +2601,7 @@ rb_scan_args_set(int argc, const VALUE *argv, ptr[argc] = rb_hash_new(); argc++; *(&argv) = ptr; - rb_warn("Passing the keyword argument as the last hash parameter is deprecated"); + WARN_DEPRECATED("Passing the keyword argument as the last hash parameter is deprecated"); } -- 2.26.2