mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d9acd1965d
commit
43284b6bf8
5 changed files with 39 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Thu Sep 1 17:31:22 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Thu Sep 1 16:18:44 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* Release GVL while OpenSSL's public key generation.
|
* Release GVL while OpenSSL's public key generation.
|
||||||
|
|
10
insns.def
10
insns.def
|
@ -895,6 +895,7 @@ defineclass
|
||||||
(VALUE val)
|
(VALUE val)
|
||||||
{
|
{
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
|
int newclass = 1;
|
||||||
|
|
||||||
switch ((int)define_type) {
|
switch ((int)define_type) {
|
||||||
case 0: /* scoped: class Foo::Bar */
|
case 0: /* scoped: class Foo::Bar */
|
||||||
|
@ -903,15 +904,16 @@ defineclass
|
||||||
|
|
||||||
if (super == Qnil) {
|
if (super == Qnil) {
|
||||||
super = rb_cObject;
|
super = rb_cObject;
|
||||||
|
newclass = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm_check_if_namespace(cbase);
|
vm_check_if_namespace(cbase);
|
||||||
|
|
||||||
/* find klass */
|
/* find klass */
|
||||||
rb_autoload_load(cbase, id);
|
rb_autoload_load(cbase, id);
|
||||||
if (rb_const_defined_at(cbase, id)) {
|
if (vm_const_defined_at(cbase, id, newclass)) {
|
||||||
/* already exist */
|
/* 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) {
|
if (TYPE(klass) != T_CLASS) {
|
||||||
rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
|
rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
|
||||||
}
|
}
|
||||||
|
@ -947,8 +949,8 @@ defineclass
|
||||||
vm_check_if_namespace(cbase);
|
vm_check_if_namespace(cbase);
|
||||||
|
|
||||||
/* find klass */
|
/* find klass */
|
||||||
if (rb_const_defined_at(cbase, id)) {
|
if (vm_const_defined_at(cbase, id, 0)) {
|
||||||
klass = define_type == 2 ? rb_public_const_get(cbase, id) : rb_const_get_at(cbase, id);
|
klass = define_type == 2 ? rb_public_const_get(cbase, id) : rb_const_get_from(cbase, id);
|
||||||
/* already exist */
|
/* already exist */
|
||||||
if (TYPE(klass) != T_MODULE) {
|
if (TYPE(klass) != T_MODULE) {
|
||||||
rb_raise(rb_eTypeError, "%s is not a module", rb_id2name(id));
|
rb_raise(rb_eTypeError, "%s is not a module", rb_id2name(id));
|
||||||
|
|
|
@ -140,7 +140,9 @@ p Foo::Bar
|
||||||
t = Thread.new { AutoloadTest }
|
t = Thread.new { AutoloadTest }
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
# override it
|
# override it
|
||||||
eval %q(AutoloadTest = 1)
|
EnvUtil.suppress_warning {
|
||||||
|
eval %q(AutoloadTest = 1)
|
||||||
|
}
|
||||||
t.join
|
t.join
|
||||||
assert_equal(1, AutoloadTest)
|
assert_equal(1, AutoloadTest)
|
||||||
ensure
|
ensure
|
||||||
|
|
|
@ -545,6 +545,20 @@ class TestModule < Test::Unit::TestCase
|
||||||
INPUT
|
INPUT
|
||||||
end
|
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
|
def test_class_variable_get
|
||||||
c = Class.new
|
c = Class.new
|
||||||
c.class_eval('@@foo = :foo')
|
c.class_eval('@@foo = :foo')
|
||||||
|
|
|
@ -1253,6 +1253,16 @@ vm_get_cvar_base(NODE *cref)
|
||||||
return klass;
|
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
|
#ifndef USE_IC_FOR_IVAR
|
||||||
#define USE_IC_FOR_IVAR 1
|
#define USE_IC_FOR_IVAR 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue