From 33b5b4da890ca17ef45f94edaf5610363e57ad2c Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 25 Oct 2009 14:46:28 +0000 Subject: 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: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@25479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- class.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'class.c') diff --git a/class.c b/class.c index 89becccb5..08bd86a62 100644 --- a/class.c +++ b/class.c @@ -297,27 +297,31 @@ rb_define_class(const char *name, VALUE super) VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super) +{ + 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 id; - 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); @@ -367,11 +371,15 @@ rb_define_module(const char *name) VALUE rb_define_module_under(VALUE outer, const char *name) +{ + return rb_define_module_id_under(outer, rb_intern(name)); +} + +VALUE +rb_define_module_id_under(VALUE outer, ID id) { VALUE module; - ID id; - 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; } -- cgit