ruby-changes:24526
From: nobu <ko1@a...>
Date: Mon, 30 Jul 2012 21:01:07 +0900 (JST)
Subject: [ruby-changes:24526] nobu:r36577 (trunk): variable.c: fix r36574
nobu 2012-07-30 21:00:56 +0900 (Mon, 30 Jul 2012) New Revision: 36577 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36577 Log: variable.c: fix r36574 * variable.c (find_class_path): no retry when preferred is given. * variable.c (classname): if classid is set try it to find full qualified class path, and then try arbitrary class path. try tmp_classpath at last even if enclosing namespace is anonymous. fix r36574. [ruby-core:42865][Bug #6078] * variable.c (rb_set_class_path_string, rb_set_class_path): set tmp_classpath instead of classpath if the name is not permanent. Modified files: trunk/ChangeLog trunk/test/ruby/test_module.rb trunk/variable.c Index: ChangeLog =================================================================== --- ChangeLog (revision 36576) +++ ChangeLog (revision 36577) @@ -1,3 +1,15 @@ +Mon Jul 30 21:00:53 2012 Nobuyoshi Nakada <nobu@r...> + + * variable.c (find_class_path): no retry when preferred is given. + + * variable.c (classname): if classid is set try it to find full + qualified class path, and then try arbitrary class path. try + tmp_classpath at last even if enclosing namespace is anonymous. + fix r36574. [ruby-core:42865][Bug #6078] + + * variable.c (rb_set_class_path_string, rb_set_class_path): set + tmp_classpath instead of classpath if the name is not permanent. + Mon Jul 30 14:24:20 2012 Nobuyoshi Nakada <nobu@r...> * variable.c: store anonymous class path in tmp_classpath but not in Index: variable.c =================================================================== --- variable.c (revision 36576) +++ variable.c (revision 36577) @@ -115,7 +115,6 @@ { struct fc_result arg; - find: arg.preferred = preferred; arg.name = 0; arg.path = 0; @@ -137,10 +136,6 @@ st_delete(RCLASS_IV_TBL(klass), &tmp, 0); return arg.path; } - if (preferred) { - preferred = 0; - goto find; - } return Qnil; } @@ -153,12 +148,17 @@ if (!klass) klass = rb_cObject; if (RCLASS_IV_TBL(klass)) { if (!st_lookup(RCLASS_IV_TBL(klass), (st_data_t)classpath, &n)) { - if (!st_lookup(RCLASS_IV_TBL(klass), (st_data_t)classid, &n)) { - return find_class_path(klass, (ID)0); + if (st_lookup(RCLASS_IV_TBL(klass), (st_data_t)classid, &n)) { + path = find_class_path(klass, SYM2ID(n)); } - path = find_class_path(klass, SYM2ID(n)); if (NIL_P(path)) { - path = rb_str_dup(rb_id2str(SYM2ID((VALUE)n))); + path = find_class_path(klass, (ID)0); + } + if (NIL_P(path)) { + if (!st_lookup(RCLASS_IV_TBL(klass), (st_data_t)tmp_classpath, &n)) { + return Qnil; + } + path = rb_str_dup((VALUE)n); OBJ_FREEZE(path); return path; } @@ -240,6 +240,7 @@ rb_set_class_path_string(VALUE klass, VALUE under, VALUE name) { VALUE str; + ID pathid = classpath; if (under == rb_cObject) { str = rb_str_new_frozen(name); @@ -250,28 +251,29 @@ rb_str_cat2(str, "::"); rb_str_append(str, name); OBJ_FREEZE(str); - if (!permanent) return; + if (!permanent) pathid = tmp_classpath; } - rb_ivar_set(klass, classpath, str); + rb_ivar_set(klass, pathid, str); } void rb_set_class_path(VALUE klass, VALUE under, const char *name) { VALUE str; - int permanent = 1; + ID pathid = classpath; if (under == rb_cObject) { str = rb_str_new2(name); } else { + int permanent; str = rb_str_dup(rb_tmp_class_path(under, &permanent)); rb_str_cat2(str, "::"); rb_str_cat2(str, name); + if (!permanent) pathid = tmp_classpath; } OBJ_FREEZE(str); - if (!permanent) return; - rb_ivar_set(klass, classpath, str); + rb_ivar_set(klass, pathid, str); } VALUE Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 36576) +++ test/ruby/test_module.rb (revision 36577) @@ -372,12 +372,16 @@ assert_equal([:N], m.constants) m.module_eval("module O end") assert_equal([:N, :O], m.constants) + m.module_eval("class C end") + assert_equal([:N, :O, :C], m.constants) assert_nil(m::N.name) - assert_match(/\A(?:#<Module:.*>::)?O\z/, m::O.name) + assert_match(/\A#<Module:.*>::O\z/, m::O.name) + assert_match(/\A#<Class:.*>::O\z/, m::C.name) self.class.const_set(:M, m) prefix = self.class.name + "::M::" assert_equal(prefix+"N", m.const_get(:N).name) assert_equal(prefix+"O", m.const_get(:O).name) + assert_equal(prefix+"C", m.const_get(:C).name) end def test_private_class_method -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/