[前][次][番号順一覧][スレッド一覧]

ruby-changes:43632

From: nobu <ko1@a...>
Date: Tue, 19 Jul 2016 15:39:06 +0900 (JST)
Subject: [ruby-changes:43632] nobu:r55705 (trunk): variable.c: exclude private constants

nobu	2016-07-19 15:39:01 +0900 (Tue, 19 Jul 2016)

  New Revision: 55705

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55705

  Log:
    variable.c: exclude private constants
    
    * variable.c (rb_local_constants_i): exclude private constants
      when excluding inherited constants too.  [Bug #12345]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_module.rb
    trunk/variable.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55704)
+++ ChangeLog	(revision 55705)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jul 19 15:38:59 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* variable.c (rb_local_constants_i): exclude private constants
+	  when excluding inherited constants too.  [Bug #12345]
+
 Sun Jul 17 23:42:00 2016  Kenta Murata  <mrkn@m...>
 
 	* numeric.c (num_finite_p, num_infinite_p): Add Numeric#finite? and
Index: variable.c
===================================================================
--- variable.c	(revision 55704)
+++ variable.c	(revision 55705)
@@ -2399,7 +2399,7 @@ sv_i(ID key, VALUE v, void *a) https://github.com/ruby/ruby/blob/trunk/variable.c#L2399
 static enum rb_id_table_iterator_result
 rb_local_constants_i(ID const_name, VALUE const_value, void *ary)
 {
-    if (rb_is_const_id(const_name)) {
+    if (rb_is_const_id(const_name) && !RB_CONST_PRIVATE_P((rb_const_entry_t *)const_value)) {
 	rb_ary_push((VALUE)ary, ID2SYM(const_name));
     }
     return ID_TABLE_CONTINUE;
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 55704)
+++ test/ruby/test_module.rb	(revision 55705)
@@ -1423,6 +1423,8 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1423
 
   def test_constants_with_private_constant
     assert_not_include(::TestModule.constants, :PrivateClass)
+    assert_not_include(::TestModule.constants(true), :PrivateClass)
+    assert_not_include(::TestModule.constants(false), :PrivateClass)
   end
 
   def test_toplevel_private_constant

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]