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

ruby-changes:18690

From: mame <ko1@a...>
Date: Sat, 29 Jan 2011 03:01:53 +0900 (JST)
Subject: [ruby-changes:18690] Ruby:r30715 (trunk): * variable.c (rb_const_set): const_set shoud preserve constant

mame	2011-01-29 02:57:42 +0900 (Sat, 29 Jan 2011)

  New Revision: 30715

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30715

  Log:
    * variable.c (rb_const_set): const_set shoud preserve constant
      visibility.  see [ruby-core:32912].
    
    * test/ruby/test_module.rb: add a test for above.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_module.rb
    trunk/variable.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30714)
+++ ChangeLog	(revision 30715)
@@ -1,3 +1,10 @@
+Sat Jan 29 01:36:41 2011  Yusuke Endoh  <mame@t...>
+
+	* variable.c (rb_const_set): const_set shoud preserve constant
+	  visibility.  see [ruby-core:32912].
+
+	* test/ruby/test_module.rb: add a test for above.
+
 Sat Jan 29 01:24:57 2011  Yusuke Endoh  <mame@t...>
 
 	* compile.c (NODE_CLASS, NODE_MODULE), insns.def (defineclass): raise
Index: variable.c
===================================================================
--- variable.c	(revision 30714)
+++ variable.c	(revision 30715)
@@ -1876,6 +1876,7 @@
 rb_const_set(VALUE klass, ID id, VALUE val)
 {
     rb_const_entry_t *ce;
+    VALUE visibility = CONST_PUBLIC;
 
     if (NIL_P(klass)) {
 	rb_raise(rb_eTypeError, "no class/module to define constant %s",
@@ -1890,17 +1891,20 @@
 	st_data_t value;
 
 	if (st_lookup(RCLASS_CONST_TBL(klass), (st_data_t)id, &value)) {
-	    if (((rb_const_entry_t*)value)->value == Qundef)
+	    rb_const_entry_t *ce = (rb_const_entry_t*)value;
+	    if (ce->value == Qundef)
 		autoload_delete(klass, id);
-	    else
+	    else {
+		visibility = ce->flag;
 		rb_warn("already initialized constant %s", rb_id2name(id));
+	    }
 	}
     }
 
     rb_vm_change_state();
 
     ce = ALLOC(rb_const_entry_t);
-    ce->flag = CONST_PUBLIC;
+    ce->flag = visibility;
     ce->value = val;
 
     st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce);
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 30714)
+++ test/ruby/test_module.rb	(revision 30715)
@@ -948,6 +948,10 @@
     assert_raise(NameError) { c::FOO }
     assert_equal("foo", c.class_eval("FOO"))
     assert_equal("foo", c.const_get("FOO"))
+    $VERBOSE, verbose = nil, $VERBOSE
+    c.const_set(:FOO, "foo")
+    $VERBOSE = verbose
+    assert_raise(NameError) { c::FOO }
   end
 
   class PrivateClass

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

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