ruby-changes:62818
From: Nobuyoshi <ko1@a...>
Date: Thu, 3 Sep 2020 18:56:39 +0900 (JST)
Subject: [ruby-changes:62818] eeb5325d3b (master): Hoisted out warn_deprecated
https://git.ruby-lang.org/ruby.git/commit/?id=eeb5325d3b From eeb5325d3bfd71301896360c17e8f51abcb9a7e5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 2 Sep 2020 16:08:51 +0900 Subject: Hoisted out warn_deprecated diff --git a/error.c b/error.c index a9adf57..70f24a0 100644 --- a/error.c +++ b/error.c @@ -379,6 +379,8 @@ rb_enc_warning(rb_encoding *enc, const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L379 } #endif +static void warn_deprecated(VALUE mesg); + void rb_warn_deprecated(const char *fmt, const char *suggest, ...) { @@ -392,22 +394,7 @@ rb_warn_deprecated(const char *fmt, const char *suggest, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L394 rb_str_cat_cstr(mesg, " is deprecated"); if (suggest) rb_str_catf(mesg, "; use %s instead", suggest); rb_str_cat_cstr(mesg, "\n"); - - VALUE warn_args[2]; - warn_args[0] = mesg; - - const rb_method_entry_t * me; - me = rb_method_entry(rb_singleton_class(rb_mWarning), id_warn); - - if (rb_method_entry_arity(me) != 1) { - VALUE kwargs = rb_hash_new(); - rb_hash_aset(kwargs, ID2SYM(rb_intern("category")), ID2SYM(rb_intern("deprecated"))); - warn_args[1] = kwargs; - - rb_funcallv_kw(rb_mWarning, id_warn, 2, warn_args, RB_PASS_KEYWORDS); - } else { - rb_funcall(rb_mWarning, id_warn, 1, mesg); - } + warn_deprecated(mesg); } void @@ -421,22 +408,24 @@ rb_warn_deprecated_to_remove(const char *fmt, const char *removal, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L408 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); + warn_deprecated(mesg); +} - VALUE warn_args[2]; - warn_args[0] = mesg; - - const rb_method_entry_t * me; - me = rb_method_entry(rb_singleton_class(rb_mWarning), id_warn); +static void +warn_deprecated(VALUE mesg) +{ + VALUE warn_args[2] = {mesg}; + int kwd = 0; + const rb_method_entry_t *me = rb_method_entry(rb_singleton_class(rb_mWarning), id_warn); if (rb_method_entry_arity(me) != 1) { VALUE kwargs = rb_hash_new(); rb_hash_aset(kwargs, ID2SYM(rb_intern("category")), ID2SYM(rb_intern("deprecated"))); warn_args[1] = kwargs; - - rb_funcallv_kw(rb_mWarning, id_warn, 2, warn_args, RB_PASS_KEYWORDS); - } else { - rb_funcall(rb_mWarning, id_warn, 1, mesg); + kwd = 1; } + + rb_funcallv_kw(rb_mWarning, id_warn, 1 + kwd, warn_args, kwd); } static inline int -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/