summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-30 04:20:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-30 04:20:00 +0000
commit83cd51e3fe6e1e2be1375602274caa6ae0ac2a86 ()
treee2d59d7870dbc9b8e83c5af528bbaa709df41cc4
parentc3f6e4ea078af93e79d578bf312a9a26af82f09b (diff)
variable.c: Module#deprecate_constant
* variable.c (rb_const_get_0): warn deprecated constant reference. * variable.c (rb_mod_deprecate_constant): mark constants to be warned as deprecated. [Feature #11398] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--NEWS3
-rw-r--r--constant.h11
-rw-r--r--lib/timeout.rb3
-rw-r--r--object.c1
-rw-r--r--test/ruby/test_module.rb7
-rw-r--r--variable.c25
7 files changed, 51 insertions, 6 deletions
@@ -1,3 +1,10 @@
Thu Jul 30 11:53:54 2015 Nobuyoshi Nakada <[email protected]>
* thread.c (rb_thread_s_handle_interrupt): make identical hash,
@@ -44,6 +44,9 @@ with all sufficient information, see the ChangeLog file.
this parameter is bitwise-ORed to oflags generated by normal mode argument.
[Feature #11253]
* NameError
* NameError#receiver is added to take the receiver object. [Feature #10881]
@@ -12,15 +12,21 @@
#define CONSTANT_H
typedef enum {
CONST_PUBLIC = 0x00,
CONST_PRIVATE,
CONST_VISIBILITY_MAX
} rb_const_flag_t;
#define RB_CONST_PRIVATE_P(ce) \
- ((ce)->flag == CONST_PRIVATE)
#define RB_CONST_PUBLIC_P(ce) \
- ((ce)->flag == CONST_PUBLIC)
typedef struct rb_const_entry_struct {
rb_const_flag_t flag;
@@ -31,6 +37,7 @@ typedef struct rb_const_entry_struct {
VALUE rb_mod_private_constant(int argc, const VALUE *argv, VALUE obj);
VALUE rb_mod_public_constant(int argc, const VALUE *argv, VALUE obj);
void rb_free_const_table(st_table *tbl);
VALUE rb_public_const_get(VALUE klass, ID id);
VALUE rb_public_const_get_at(VALUE klass, ID id);
@@ -120,3 +120,6 @@ end
# Another name for Timeout::Error, defined for backwards compatibility with
# earlier versions of timeout.rb.
TimeoutError = Timeout::Error
@@ -3414,6 +3414,7 @@ Init_Object(void)
rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
rb_define_method(rb_cModule, "public_constant", rb_mod_public_constant, -1); /* in variable.c */
rb_define_method(rb_cModule, "private_constant", rb_mod_private_constant, -1); /* in variable.c */
rb_define_method(rb_cModule, "singleton_class?", rb_mod_singleton_p, 0);
rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
@@ -1360,6 +1360,13 @@ class TestModule < Test::Unit::TestCase
assert_equal("foo", c::FOO)
end
def test_constants_with_private_constant
assert_not_include(::TestModule.constants, :PrivateClass)
end
@@ -2149,6 +2149,15 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
rb_name_error(id, "private constant %"PRIsVALUE"::%"PRIsVALUE" referenced",
rb_class_name(klass), QUOTE_ID(id));
}
value = ce->value;
if (value == Qundef) {
if (am == tmp) break;
@@ -2576,7 +2585,7 @@ rb_define_global_const(const char *name, VALUE val)
}
static void
-set_const_visibility(VALUE mod, int argc, const VALUE *argv, rb_const_flag_t flag)
{
int i;
rb_const_entry_t *ce;
@@ -2600,7 +2609,8 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv, rb_const_flag_t fla
rb_class_name(mod), QUOTE(val));
}
if ((ce = rb_const_lookup(mod, id))) {
- ce->flag = flag;
}
else {
if (i > 0) {
@@ -2623,7 +2633,7 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv, rb_const_flag_t fla
VALUE
rb_mod_private_constant(int argc, const VALUE *argv, VALUE obj)
{
- set_const_visibility(obj, argc, argv, CONST_PRIVATE);
return obj;
}
@@ -2637,7 +2647,14 @@ rb_mod_private_constant(int argc, const VALUE *argv, VALUE obj)
VALUE
rb_mod_public_constant(int argc, const VALUE *argv, VALUE obj)
{
- set_const_visibility(obj, argc, argv, CONST_PUBLIC);
return obj;
}