mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* insns.def (defineclass): preserve encoding of class/module
names. [ruby-core:24600] * variable.c (rb_set_class_path_string): set class path with a string value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d919a67c1e
commit
b8b083dbd5
6 changed files with 43 additions and 2 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Thu Jul 30 16:45:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* insns.def (defineclass): preserve encoding of class/module
|
||||||
|
names. [ruby-core:24600]
|
||||||
|
|
||||||
|
* variable.c (rb_set_class_path_string): set class path with a
|
||||||
|
string value.
|
||||||
|
|
||||||
Thu Jul 30 16:12:48 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Jul 30 16:12:48 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* variable.c (Init_var_tables): initializes __classid__ ID.
|
* variable.c (Init_var_tables): initializes __classid__ ID.
|
||||||
|
|
|
@ -759,6 +759,7 @@ VALUE rb_time_num_new(VALUE, VALUE);
|
||||||
VALUE rb_mod_name(VALUE);
|
VALUE rb_mod_name(VALUE);
|
||||||
VALUE rb_class_path(VALUE);
|
VALUE rb_class_path(VALUE);
|
||||||
void rb_set_class_path(VALUE, VALUE, const char*);
|
void rb_set_class_path(VALUE, VALUE, const char*);
|
||||||
|
void rb_set_class_path_string(VALUE, VALUE, VALUE);
|
||||||
VALUE rb_path2class(const char*);
|
VALUE rb_path2class(const char*);
|
||||||
void rb_name_class(VALUE, ID);
|
void rb_name_class(VALUE, ID);
|
||||||
VALUE rb_class_name(VALUE);
|
VALUE rb_class_name(VALUE);
|
||||||
|
|
|
@ -909,7 +909,7 @@ defineclass
|
||||||
else {
|
else {
|
||||||
/* new class declaration */
|
/* new class declaration */
|
||||||
klass = rb_define_class_id(id, super);
|
klass = rb_define_class_id(id, super);
|
||||||
rb_set_class_path(klass, cbase, rb_id2name(id));
|
rb_set_class_path_string(klass, cbase, rb_id2str(id));
|
||||||
rb_const_set(cbase, id, klass);
|
rb_const_set(cbase, id, klass);
|
||||||
rb_class_inherited(super, klass);
|
rb_class_inherited(super, klass);
|
||||||
}
|
}
|
||||||
|
@ -936,7 +936,7 @@ defineclass
|
||||||
else {
|
else {
|
||||||
/* new module declaration */
|
/* new module declaration */
|
||||||
klass = rb_define_module_id(id);
|
klass = rb_define_module_id(id);
|
||||||
rb_set_class_path(klass, cbase, rb_id2name(id));
|
rb_set_class_path_string(klass, cbase, rb_id2str(id));
|
||||||
rb_const_set(cbase, id, klass);
|
rb_const_set(cbase, id, klass);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -144,4 +144,11 @@ class TestClass < Test::Unit::TestCase
|
||||||
assert_raise(TypeError) { Class.allocate.new }
|
assert_raise(TypeError) { Class.allocate.new }
|
||||||
assert_raise(TypeError) { Class.allocate.superclass }
|
assert_raise(TypeError) { Class.allocate.superclass }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_nonascii_name
|
||||||
|
c = eval("class ::C\u{df}; self; end")
|
||||||
|
assert_equal("C\u{df}", c.name, '[ruby-core:24600]')
|
||||||
|
c = eval("class C\u{df}; self; end")
|
||||||
|
assert_equal("TestClass::C\u{df}", c.name, '[ruby-core:24600]')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -741,4 +741,12 @@ class TestModule < Test::Unit::TestCase
|
||||||
assert_equal(:bClass2, b.__send__(:bClass2))
|
assert_equal(:bClass2, b.__send__(:bClass2))
|
||||||
assert_equal(:bClass3, b.__send__(:bClass3))
|
assert_equal(:bClass3, b.__send__(:bClass3))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_nonascii_name
|
||||||
|
c = eval("class ::C\u{df}; self; end")
|
||||||
|
assert_equal("C\u{df}", c.name, '[ruby-core:24600]')
|
||||||
|
c = eval("class C\u{df}; self; end")
|
||||||
|
assert_equal("TestModule::C\u{df}", c.name, '[ruby-core:24600]')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
17
variable.c
17
variable.c
|
@ -214,6 +214,23 @@ rb_class_path(VALUE klass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_set_class_path_string(VALUE klass, VALUE under, VALUE name)
|
||||||
|
{
|
||||||
|
VALUE str;
|
||||||
|
|
||||||
|
if (under == rb_cObject) {
|
||||||
|
str = rb_str_new_frozen(name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
str = rb_str_dup(rb_class_path(under));
|
||||||
|
rb_str_cat2(str, "::");
|
||||||
|
rb_str_append(str, name);
|
||||||
|
OBJ_FREEZE(str);
|
||||||
|
}
|
||||||
|
rb_ivar_set(klass, classpath, str);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_set_class_path(VALUE klass, VALUE under, const char *name)
|
rb_set_class_path(VALUE klass, VALUE under, const char *name)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue