ruby-changes:21108
From: nobu <ko1@a...>
Date: Thu, 1 Sep 2011 17:31:57 +0900 (JST)
Subject: [ruby-changes:21108] nobu:r33157 (ruby_1_9_3, trunk): * insns.def (defineclass), vm_insnhelper.c (vm_get_cvar_base): see
nobu 2011-09-01 17:31:24 +0900 (Thu, 01 Sep 2011) New Revision: 33157 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33157 Log: * insns.def (defineclass), vm_insnhelper.c (vm_get_cvar_base): see also inherited constants for classes without superclass and modules. [ruby-core:37698] [Bug #3423] Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/insns.def branches/ruby_1_9_3/test/ruby/test_module.rb branches/ruby_1_9_3/vm_insnhelper.c trunk/ChangeLog trunk/insns.def trunk/test/ruby/test_autoload.rb trunk/test/ruby/test_module.rb trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 33156) +++ ChangeLog (revision 33157) @@ -1,3 +1,9 @@ +Thu Sep 1 17:31:22 2011 Nobuyoshi Nakada <nobu@r...> + + * insns.def (defineclass), vm_insnhelper.c (vm_get_cvar_base): see + also inherited constants for classes without superclass and + modules. [ruby-core:37698] [Bug #3423] + Thu Sep 1 16:18:44 2011 Hiroshi Nakamura <nahi@r...> * Release GVL while OpenSSL's public key generation. Index: insns.def =================================================================== --- insns.def (revision 33156) +++ insns.def (revision 33157) @@ -895,6 +895,7 @@ (VALUE val) { VALUE klass; + int newclass = 1; switch ((int)define_type) { case 0: /* scoped: class Foo::Bar */ @@ -903,15 +904,16 @@ if (super == Qnil) { super = rb_cObject; + newclass = 0; } vm_check_if_namespace(cbase); /* find klass */ rb_autoload_load(cbase, id); - if (rb_const_defined_at(cbase, id)) { + if (vm_const_defined_at(cbase, id, newclass)) { /* already exist */ - klass = define_type == 0 ? rb_public_const_get(cbase, id) : rb_const_get_at(cbase, id); + klass = define_type == 0 ? rb_public_const_get(cbase, id) : rb_const_get_from(cbase, id); if (TYPE(klass) != T_CLASS) { rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id)); } @@ -947,8 +949,8 @@ vm_check_if_namespace(cbase); /* find klass */ - if (rb_const_defined_at(cbase, id)) { - klass = define_type == 2 ? rb_public_const_get(cbase, id) : rb_const_get_at(cbase, id); + if (vm_const_defined_at(cbase, id, 0)) { + klass = define_type == 2 ? rb_public_const_get(cbase, id) : rb_const_get_from(cbase, id); /* already exist */ if (TYPE(klass) != T_MODULE) { rb_raise(rb_eTypeError, "%s is not a module", rb_id2name(id)); Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 33156) +++ vm_insnhelper.c (revision 33157) @@ -1253,6 +1253,16 @@ return klass; } +static int +vm_const_defined_at(VALUE cbase, ID id, int newclass) +{ + int ret = rb_const_defined_at(cbase, id); + if (!ret && !newclass) { + while ((cbase = RCLASS_SUPER(cbase)) != 0 && cbase != rb_cObject && + !(ret = rb_const_defined_at(cbase, id))); + } + return ret; +} #ifndef USE_IC_FOR_IVAR #define USE_IC_FOR_IVAR 1 Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 33156) +++ test/ruby/test_module.rb (revision 33157) @@ -545,6 +545,20 @@ INPUT end + def test_const_in_module + bug3423 = '[ruby-core:37698]' + assert_in_out_err([], <<-INPUT, %w[ok], [], bug3423) +module LangModuleSpecInObject + module LangModuleTop + end +end +include LangModuleSpecInObject +module LangModuleTop +end +puts "ok" if LangModuleSpecInObject::LangModuleTop == LangModuleTop +INPUT + end + def test_class_variable_get c = Class.new c.class_eval('@@foo = :foo') Index: test/ruby/test_autoload.rb =================================================================== --- test/ruby/test_autoload.rb (revision 33156) +++ test/ruby/test_autoload.rb (revision 33157) @@ -140,7 +140,9 @@ t = Thread.new { AutoloadTest } sleep 0.1 # override it - eval %q(AutoloadTest = 1) + EnvUtil.suppress_warning { + eval %q(AutoloadTest = 1) + } t.join assert_equal(1, AutoloadTest) ensure Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 33156) +++ ruby_1_9_3/ChangeLog (revision 33157) @@ -1,3 +1,9 @@ +Thu Sep 1 17:31:22 2011 Nobuyoshi Nakada <nobu@r...> + + * insns.def (defineclass), vm_insnhelper.c (vm_get_cvar_base): see + also inherited constants for classes without superclass and + modules. [ruby-core:37698] [Bug #3423] + Thu Sep 1 14:11:16 2011 NAKAMURA Usaku <usa@r...> * test/ruby/test_thread.rb (TestThread#test_no_valid_cfp): skip when Index: ruby_1_9_3/insns.def =================================================================== --- ruby_1_9_3/insns.def (revision 33156) +++ ruby_1_9_3/insns.def (revision 33157) @@ -895,6 +895,7 @@ (VALUE val) { VALUE klass; + int newclass = 1; switch ((int)define_type) { case 0: /* scoped: class Foo::Bar */ @@ -903,15 +904,16 @@ if (super == Qnil) { super = rb_cObject; + newclass = 0; } vm_check_if_namespace(cbase); /* find klass */ rb_autoload_load(cbase, id); - if (rb_const_defined_at(cbase, id)) { + if (vm_const_defined_at(cbase, id, newclass)) { /* already exist */ - klass = define_type == 0 ? rb_public_const_get(cbase, id) : rb_const_get_at(cbase, id); + klass = define_type == 0 ? rb_public_const_get(cbase, id) : rb_const_get_from(cbase, id); if (TYPE(klass) != T_CLASS) { rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id)); } @@ -947,8 +949,8 @@ vm_check_if_namespace(cbase); /* find klass */ - if (rb_const_defined_at(cbase, id)) { - klass = define_type == 2 ? rb_public_const_get(cbase, id) : rb_const_get_at(cbase, id); + if (vm_const_defined_at(cbase, id, 0)) { + klass = define_type == 2 ? rb_public_const_get(cbase, id) : rb_const_get_from(cbase, id); /* already exist */ if (TYPE(klass) != T_MODULE) { rb_raise(rb_eTypeError, "%s is not a module", rb_id2name(id)); Index: ruby_1_9_3/vm_insnhelper.c =================================================================== --- ruby_1_9_3/vm_insnhelper.c (revision 33156) +++ ruby_1_9_3/vm_insnhelper.c (revision 33157) @@ -1252,6 +1252,16 @@ return klass; } +static int +vm_const_defined_at(VALUE cbase, ID id, int newclass) +{ + int ret = rb_const_defined_at(cbase, id); + if (!ret && !newclass) { + while ((cbase = RCLASS_SUPER(cbase)) != 0 && cbase != rb_cObject && + !(ret = rb_const_defined_at(cbase, id))); + } + return ret; +} #ifndef USE_IC_FOR_IVAR #define USE_IC_FOR_IVAR 1 Index: ruby_1_9_3/test/ruby/test_module.rb =================================================================== --- ruby_1_9_3/test/ruby/test_module.rb (revision 33156) +++ ruby_1_9_3/test/ruby/test_module.rb (revision 33157) @@ -532,6 +532,20 @@ INPUT end + def test_const_in_module + bug3423 = '[ruby-core:37698]' + assert_in_out_err([], <<-INPUT, %w[ok], [], bug3423) +module LangModuleSpecInObject + module LangModuleTop + end +end +include LangModuleSpecInObject +module LangModuleTop +end +puts "ok" if LangModuleSpecInObject::LangModuleTop == LangModuleTop +INPUT + end + def test_class_variable_get c = Class.new c.class_eval('@@foo = :foo') -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/