merges r24513,r24514 and r24515 from trunk into ruby_1_9_1.

--
* class.c (rb_define_class_id_under, rb_define_module_id_under):
  new functions to define a nested class/module with non-ascii
  name.

* struct.c (make_struct): use name with encoding.

* struct.c (inspect_struct): ditto.  [ruby-core:24849]
--
* test/ruby/test_marshal.rb (test_class_nonascii): test for non-ascii name class.
--
* class.c (rb_define_module_id_under): fix the name.

* class.c (rb_define_module_under): fix for prevvious changes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@25479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
yugui 2009-10-25 14:46:28 +00:00
parent 0a84a18ef4
commit 3a724e086a
6 changed files with 61 additions and 21 deletions

30
class.c
View file

@ -298,26 +298,30 @@ rb_define_class(const char *name, VALUE super)
VALUE
rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
VALUE klass;
ID id;
return rb_define_class_id_under(outer, rb_intern(name), super);
}
VALUE
rb_define_class_id_under(VALUE outer, ID id, VALUE super)
{
VALUE klass;
id = rb_intern(name);
if (rb_const_defined_at(outer, id)) {
klass = rb_const_get_at(outer, id);
if (TYPE(klass) != T_CLASS) {
rb_raise(rb_eTypeError, "%s is not a class", name);
rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
}
if (rb_class_real(RCLASS_SUPER(klass)) != super) {
rb_name_error(id, "%s is already defined", name);
rb_name_error(id, "%s is already defined", rb_id2name(id));
}
return klass;
}
if (!super) {
rb_warn("no super class for `%s::%s', Object assumed",
rb_class2name(outer), name);
rb_class2name(outer), rb_id2name(id));
}
klass = rb_define_class_id(id, super);
rb_set_class_path(klass, outer, name);
rb_set_class_path_string(klass, outer, rb_id2str(id));
rb_const_set(outer, id, klass);
rb_class_inherited(super, klass);
@ -368,10 +372,14 @@ rb_define_module(const char *name)
VALUE
rb_define_module_under(VALUE outer, const char *name)
{
VALUE module;
ID id;
return rb_define_module_id_under(outer, rb_intern(name));
}
VALUE
rb_define_module_id_under(VALUE outer, ID id)
{
VALUE module;
id = rb_intern(name);
if (rb_const_defined_at(outer, id)) {
module = rb_const_get_at(outer, id);
if (TYPE(module) == T_MODULE)
@ -381,7 +389,7 @@ rb_define_module_under(VALUE outer, const char *name)
}
module = rb_define_module_id(id);
rb_const_set(outer, id, module);
rb_set_class_path(module, outer, name);
rb_set_class_path_string(module, outer, rb_id2str(id));
return module;
}