ruby-changes:66632
From: Nobuyoshi <ko1@a...>
Date: Wed, 30 Jun 2021 10:47:25 +0900 (JST)
Subject: [ruby-changes:66632] 8118d435d0 (master): rb_warn_deprecated_to_remove_at [Feature #17432]
https://git.ruby-lang.org/ruby.git/commit/?id=8118d435d0 From 8118d435d000adec3023a0ff509baa11cc73fabb Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 22 Dec 2020 16:37:35 +0900 Subject: rb_warn_deprecated_to_remove_at [Feature #17432] At compilation time with RUBY_DEBUG enabled, check if the removal version has been reached. --- error.c | 47 +++++++++++++++++++++++++++++++---------------- hash.c | 2 +- internal/error.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- object.c | 14 +++++++------- string.c | 4 ++-- 5 files changed, 85 insertions(+), 27 deletions(-) diff --git a/error.c b/error.c index a0d81c8..c719d54 100644 --- a/error.c +++ b/error.c @@ -484,34 +484,49 @@ rb_enc_warning(rb_encoding *enc, const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L484 } #endif +static bool +deprecation_warning_enabled(void) +{ + if (NIL_P(ruby_verbose)) return false; + if (!rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) return false; + return true; +} + +static void +warn_deprecated(VALUE mesg, bool removal, const char *suggest) +{ + rb_str_set_len(mesg, RSTRING_LEN(mesg) - 1); + rb_str_cat_cstr(mesg, " is deprecated"); + if (removal) rb_str_cat_cstr(mesg, ", and is planned for removal"); + if (suggest) rb_str_catf(mesg, "; use %s instead", suggest); + rb_str_cat_cstr(mesg, "\n"); + rb_warn_category(mesg, ID2SYM(id_deprecated)); +} + void rb_warn_deprecated(const char *fmt, const char *suggest, ...) { - if (NIL_P(ruby_verbose)) return; - if (!rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) return; + if (!deprecation_warning_enabled()) return; + va_list args; va_start(args, suggest); VALUE mesg = warning_string(0, fmt, args); va_end(args); - rb_str_set_len(mesg, RSTRING_LEN(mesg) - 1); - rb_str_cat_cstr(mesg, " is deprecated"); - if (suggest) rb_str_catf(mesg, "; use %s instead", suggest); - rb_str_cat_cstr(mesg, "\n"); - rb_warn_category(mesg, ID2SYM(id_deprecated)); + + warn_deprecated(mesg, false, suggest); } void -rb_warn_deprecated_to_remove(const char *fmt, const char *removal, ...) +rb_warn_deprecated_to_remove(const char *fmt, const char *suggest, ...) { - if (NIL_P(ruby_verbose)) return; - if (!rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) return; + if (!deprecation_warning_enabled()) return; + va_list args; - va_start(args, removal); + va_start(args, suggest); VALUE mesg = warning_string(0, fmt, args); va_end(args); - rb_str_set_len(mesg, RSTRING_LEN(mesg) - 1); - rb_str_catf(mesg, " is deprecated and will be removed in Ruby %s\n", removal); - rb_warn_category(mesg, ID2SYM(id_deprecated)); + + warn_deprecated(mesg, true, suggest); } static inline int @@ -3296,14 +3311,14 @@ rb_check_frozen(VALUE obj) https://github.com/ruby/ruby/blob/trunk/error.c#L3311 void rb_error_untrusted(VALUE obj) { - rb_warn_deprecated_to_remove("rb_error_untrusted", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "rb_error_untrusted", NULL); } #undef rb_check_trusted void rb_check_trusted(VALUE obj) { - rb_warn_deprecated_to_remove("rb_check_trusted", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "rb_check_trusted", NULL); } void diff --git a/hash.c b/hash.c index 7ef30b4..e4c7423 100644 --- a/hash.c +++ b/hash.c @@ -5043,7 +5043,7 @@ env_fetch(int argc, VALUE *argv, VALUE _) https://github.com/ruby/ruby/blob/trunk/hash.c#L5043 int rb_env_path_tainted(void) { - rb_warn_deprecated_to_remove("rb_env_path_tainted", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "rb_env_path_tainted", NULL); return 0; } diff --git a/internal/error.h b/internal/error.h index 0dd629f..16a2f38 100644 --- a/internal/error.h +++ b/internal/error.h @@ -49,7 +49,50 @@ NORETURN(void rb_async_bug_errno(const char *,int)); https://github.com/ruby/ruby/blob/trunk/internal/error.h#L49 const char *rb_builtin_type_name(int t); const char *rb_builtin_class_name(VALUE x); PRINTF_ARGS(void rb_warn_deprecated(const char *fmt, const char *suggest, ...), 1, 3); -PRINTF_ARGS(void rb_warn_deprecated_to_remove(const char *fmt, const char *removal, ...), 1, 3); +PRINTF_ARGS(void rb_warn_deprecated_to_remove(const char *fmt, const char *suggest, ...), 1, 3); +#if RUBY_DEBUG && (RBIMPL_HAS_ATTRIBUTE(diagnose_if) || defined(__OPTIMIZE__)) +# include "ruby/version.h" + +#define RUBY_VERSION_isdigit(c) ('0'<=(c)&&(c)<='9') +// upto 99 +#define RUBY_VERSION__number_len(v, ofs) \ + (!RUBY_VERSION_isdigit((v)[ofs]) ? \ + 0 : !RUBY_VERSION_isdigit((v)[(ofs) + 1]) ? 1 : 2) +#define RUBY_VERSION__to_number(v, ofs) \ + (!RUBY_VERSION_isdigit((v)[ofs]) ? \ + 0 : !RUBY_VERSION_isdigit((v)[(ofs) + 1]) ? \ + ((v)[ofs]-'0') : \ + (((v)[ofs]-'0')*10+(v)[(ofs)+1]-'0')) + +#define RUBY_VERSION_CODE_FROM_MAJOR_MINOR_STRING(v) \ + (RUBY_VERSION__to_number(v, 0) * 10000 + \ + ((v)[RUBY_VERSION__number_len(v, 0)] == '.' ? \ + RUBY_VERSION__to_number(v, RUBY_VERSION__number_len(v, 0)+1) * 100 : 0)) +#define RUBY_VERSION_SINCE(v) (RUBY_API_VERSION_CODE >= RUBY_VERSION_CODE_FROM_MAJOR_MINOR_STRING(v)) +#define RUBY_VERSION_BEFORE(v) (RUBY_API_VERSION_CODE < RUBY_VERSION_CODE_FROM_MAJOR_MINOR_STRING(v)) + +# if RBIMPL_HAS_ATTRIBUTE(diagnose_if) +RBIMPL_ATTR_FORCEINLINE() +static void +rb_deprecated_method_to_be_removed(const char *removal) + RBIMPL_ATTR_DIAGNOSE_IF(RUBY_VERSION_SINCE(removal), "deprecated method to be removed", "error") +{ +} +# else +RBIMPL_ATTR_ERROR(("deprecated")) +void rb_deprecated_method_to_be_removed(const char *); +# define rb_deprecated_method_to_be_removed(removal) \ + (sizeof(char[1-2*RUBY_VERSION_SINCE(removal)])!=1 ? \ + rb_deprecated_method_to_be_removed(removal) : \ + RBIMPL_ASSERT_NOTHING) +# endif +# define rb_warn_deprecated_to_remove_at(removal, ...) \ + (rb_deprecated_method_to_be_removed(removal), \ + rb_warn_deprecated_to_remove(__VA_ARGS__)) +#else +# define rb_warn_deprecated_to_remove_at(removal, ...) \ + rb_warn_deprecated_to_remove(__VA_ARGS__) +#endif VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list); PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3); PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3); diff --git a/object.c b/object.c index 1994fe9..91e348a 100644 --- a/object.c +++ b/object.c @@ -1205,7 +1205,7 @@ rb_obj_dummy1(VALUE _x, VALUE _y) https://github.com/ruby/ruby/blob/trunk/object.c#L1205 VALUE rb_obj_tainted(VALUE obj) { - rb_warn_deprecated_to_remove("Object#tainted?", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "Object#tainted?", NULL); return Qfalse; } @@ -1219,7 +1219,7 @@ rb_obj_tainted(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1219 VALUE rb_obj_taint(VALUE obj) { - rb_warn_deprecated_to_remove("Object#taint", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "Object#taint", NULL); return obj; } @@ -1234,7 +1234,7 @@ rb_obj_taint(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1234 VALUE rb_obj_untaint(VALUE obj) { - rb_warn_deprecated_to_remove("Object#untaint", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "Object#untaint", NULL); return obj; } @@ -1248,7 +1248,7 @@ rb_obj_untaint(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1248 VALUE rb_obj_untrusted(VALUE obj) { - rb_warn_deprecated_to_remove("Object#untrusted?", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "Object#untrusted?", NULL); return Qfalse; } @@ -1262,7 +1262,7 @@ rb_obj_untrusted(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1262 VALUE rb_obj_untrust(VALUE obj) { - rb_warn_deprecated_to_remove("Object#untrust", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "Object#untrust", NULL); return obj; } @@ -1277,7 +1277,7 @@ rb_obj_untrust(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1277 VALUE rb_obj_trust(VALUE obj) { - rb_warn_deprecated_to_remove("Object#trust", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "Object#trust", NULL); return obj; } @@ -1288,7 +1288,7 @@ rb_obj_trust(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1288 void rb_obj_infect(VALUE victim, VALUE carrier) { - rb_warn_deprecated_to_remove("rb_obj_infect", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "rb_obj_infect", NULL); } /** diff --git a/string.c b/string.c index c183f2b..edc3288 100644 --- a/string.c +++ b/string.c @@ -944,14 +944,14 @@ rb_enc_str_new_static(const char *ptr, long len, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/string.c#L944 VALUE rb_tainted_str_new(const char *ptr, long len) { - rb_warn_deprecated_to_remove("rb_tainted_str_new", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "rb_tainted_str_new", NULL); return rb_str_new(ptr, len); } VALUE rb_tainted_str_new_cstr(const char *ptr) { - rb_warn_deprecated_to_remove("rb_tainted_str_new_cstr", "3.2"); + rb_warn_deprecated_to_remove_at("3.2", "rb_tainted_str_new_cstr", NULL); return rb_str_new_cstr(ptr); } -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/