ruby-changes:44047
From: nobu <ko1@a...>
Date: Fri, 9 Sep 2016 12:02:29 +0900 (JST)
Subject: [ruby-changes:44047] nobu:r56119 (trunk): variable.c: rb_deprecate_constant
nobu 2016-09-09 12:02:22 +0900 (Fri, 09 Sep 2016) New Revision: 56119 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56119 Log: variable.c: rb_deprecate_constant * variable.c (rb_deprecate_constant): new function to deprecate a constant by the name. Modified files: trunk/internal.h trunk/variable.c Index: internal.h =================================================================== --- internal.h (revision 56118) +++ internal.h (revision 56119) @@ -1498,6 +1498,7 @@ VALUE rb_search_class_path(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1498 VALUE rb_attr_delete(VALUE, ID); VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef); void rb_autoload_str(VALUE mod, ID id, VALUE file); +void rb_deprecate_constant(VALUE mod, const char *name); /* version.c */ extern const char ruby_engine[]; Index: variable.c =================================================================== --- variable.c (revision 56118) +++ variable.c (revision 56119) @@ -2732,6 +2732,22 @@ set_const_visibility(VALUE mod, int argc https://github.com/ruby/ruby/blob/trunk/variable.c#L2732 rb_clear_constant_cache(); } +void +rb_deprecate_constant(VALUE mod, const char *name) +{ + rb_const_entry_t *ce; + ID id; + long len = strlen(name); + + rb_frozen_class_p(mod); + if (!(id = rb_check_id_cstr(name, len, NULL)) || + !(ce = rb_const_lookup(mod, id))) { + rb_name_err_raise("constant %2$s::%1$s not defined", + mod, rb_fstring_new(name, len)); + } + ce->flag |= CONST_DEPRECATED; +} + /* * call-seq: * mod.private_constant(symbol, ...) => mod -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/