Skip to content

Commit a4a4e8b

Browse files
committed
add tag v2_4_0_preview2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v2_4_0_preview2@56122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2 parents 277d1f5 + 4785df5 commit a4a4e8b

File tree

7 files changed

+38
-15
lines changed

7 files changed

+38
-15
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Fri Sep 9 10:10:00 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* variable.c (rb_const_search): warn with the actual class/module
4+
name which defines the deprecated constant.
5+
6+
* variable.c (rb_const_search): raise with the actual class/module
7+
name which defines the private constant.
8+
19
Thu Sep 8 17:47:18 2016 Kazuki Tsujimoto <kazuki@callcc.net>
210

311
* array.c (flatten): use rb_obj_class instead of rb_class_of

internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ VALUE rb_search_class_path(VALUE);
14981498
VALUE rb_attr_delete(VALUE, ID);
14991499
VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef);
15001500
void rb_autoload_str(VALUE mod, ID id, VALUE file);
1501+
void rb_deprecate_constant(VALUE mod, const char *name);
15011502

15021503
/* version.c */
15031504
extern const char ruby_engine[];

lib/e2mmap.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ def E2MM.def_e2message(k, c, m)
128128
# define exception named ``c'' with message m.
129129
#
130130
def E2MM.def_exception(k, n, m, s = StandardError)
131-
n = n.id2name if n.kind_of?(Fixnum)
132131
e = Class.new(s)
133132
E2MM.instance_eval{@MessageMap[[k, e]] = m}
134133
k.const_set(n, e)

object.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,9 +3512,10 @@ InitVM_Object(void)
35123512
rb_undef_alloc_func(rb_cNilClass);
35133513
rb_undef_method(CLASS_OF(rb_cNilClass), "new");
35143514
/*
3515-
* An alias of +nil+
3515+
* An obsolete alias of +nil+
35163516
*/
35173517
rb_define_global_const("NIL", Qnil);
3518+
rb_deprecate_constant(rb_cObject, "NIL");
35183519

35193520
rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0);
35203521
rb_define_method(rb_cModule, "===", rb_mod_eqq, 1);
@@ -3596,9 +3597,10 @@ InitVM_Object(void)
35963597
rb_undef_alloc_func(rb_cTrueClass);
35973598
rb_undef_method(CLASS_OF(rb_cTrueClass), "new");
35983599
/*
3599-
* An alias of +true+
3600+
* An obsolete alias of +true+
36003601
*/
36013602
rb_define_global_const("TRUE", Qtrue);
3603+
rb_deprecate_constant(rb_cObject, "TRUE");
36023604

36033605
rb_cFalseClass = rb_define_class("FalseClass", rb_cObject);
36043606
rb_define_method(rb_cFalseClass, "to_s", false_to_s, 0);
@@ -3610,17 +3612,10 @@ InitVM_Object(void)
36103612
rb_undef_alloc_func(rb_cFalseClass);
36113613
rb_undef_method(CLASS_OF(rb_cFalseClass), "new");
36123614
/*
3613-
* An alias of +false+
3615+
* An obsolete alias of +false+
36143616
*/
36153617
rb_define_global_const("FALSE", Qfalse);
3616-
3617-
{
3618-
VALUE names[3];
3619-
names[0] = ID2SYM(rb_intern_const("TRUE"));
3620-
names[1] = ID2SYM(rb_intern_const("FALSE"));
3621-
names[2] = ID2SYM(rb_intern_const("NIL"));
3622-
rb_mod_deprecate_constant(3, names, rb_cObject);
3623-
}
3618+
rb_deprecate_constant(rb_cObject, "FALSE");
36243619
}
36253620

36263621
void

test/ruby/test_module.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,9 @@ def test_private_constant
13601360
c.const_set(:FOO, "foo")
13611361
$VERBOSE = verbose
13621362
assert_raise(NameError) { c::FOO }
1363+
assert_raise_with_message(NameError, /#{c}::FOO/) do
1364+
Class.new(c)::FOO
1365+
end
13631366
end
13641367

13651368
def test_private_constant2
@@ -1417,6 +1420,7 @@ def test_deprecate_constant
14171420
c.const_set(:FOO, "foo")
14181421
c.deprecate_constant(:FOO)
14191422
assert_warn(/deprecated/) {c::FOO}
1423+
assert_warn(/#{c}::FOO is deprecated/) {Class.new(c)::FOO}
14201424
bug12382 = '[ruby-core:75505] [Bug #12382]'
14211425
assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"}
14221426
end

variable.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,9 +2261,9 @@ rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility)
22612261
while ((ce = rb_const_lookup(tmp, id))) {
22622262
if (visibility && RB_CONST_PRIVATE_P(ce)) {
22632263
rb_name_err_raise("private constant %2$s::%1$s referenced",
2264-
klass, ID2SYM(id));
2264+
tmp, ID2SYM(id));
22652265
}
2266-
rb_const_warn_if_deprecated(ce, klass, id);
2266+
rb_const_warn_if_deprecated(ce, tmp, id);
22672267
value = ce->value;
22682268
if (value == Qundef) {
22692269
if (am == tmp) break;
@@ -2732,6 +2732,22 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv,
27322732
rb_clear_constant_cache();
27332733
}
27342734

2735+
void
2736+
rb_deprecate_constant(VALUE mod, const char *name)
2737+
{
2738+
rb_const_entry_t *ce;
2739+
ID id;
2740+
long len = strlen(name);
2741+
2742+
rb_frozen_class_p(mod);
2743+
if (!(id = rb_check_id_cstr(name, len, NULL)) ||
2744+
!(ce = rb_const_lookup(mod, id))) {
2745+
rb_name_err_raise("constant %2$s::%1$s not defined",
2746+
mod, rb_fstring_new(name, len));
2747+
}
2748+
ce->flag |= CONST_DEPRECATED;
2749+
}
2750+
27352751
/*
27362752
* call-seq:
27372753
* mod.private_constant(symbol, ...) => mod

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#define RUBY_RELEASE_YEAR 2016
66
#define RUBY_RELEASE_MONTH 9
7-
#define RUBY_RELEASE_DAY 8
7+
#define RUBY_RELEASE_DAY 9
88

99
#include "ruby/version.h"
1010

0 commit comments

Comments
 (0)