ruby-changes:31288
From: nobu <ko1@a...>
Date: Sun, 20 Oct 2013 05:24:37 +0900 (JST)
Subject: [ruby-changes:31288] nobu:r43367 (trunk): variable.c: real class name
nobu 2013-10-20 05:24:30 +0900 (Sun, 20 Oct 2013) New Revision: 43367 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43367 Log: variable.c: real class name * variable.c (rb_class2name): should return real class name, not singleton class or iclass. Added directories: trunk/ext/-test-/class/ trunk/test/-ext-/class/ Added files: trunk/ext/-test-/class/class2name.c trunk/ext/-test-/class/extconf.rb trunk/ext/-test-/class/init.c trunk/test/-ext-/class/test_class2name.rb Modified files: trunk/ChangeLog trunk/variable.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43366) +++ ChangeLog (revision 43367) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Oct 20 05:24:29 2013 Nobuyoshi Nakada <nobu@r...> + + * variable.c (rb_class2name): should return real class name, not + singleton class or iclass. + Sun Oct 20 04:18:48 2013 Aman Gupta <ruby@t...> * variable.c (rb_class2name): call rb_tmp_class_path() directly to Index: variable.c =================================================================== --- variable.c (revision 43366) +++ variable.c (revision 43367) @@ -386,7 +386,7 @@ const char * https://github.com/ruby/ruby/blob/trunk/variable.c#L386 rb_class2name(VALUE klass) { int permanent; - VALUE path = rb_tmp_class_path(klass, &permanent, rb_ivar_set); + VALUE path = rb_tmp_class_path(rb_class_real(klass), &permanent, rb_ivar_set); if (NIL_P(path)) return NULL; return RSTRING_PTR(path); } Index: ext/-test-/class/init.c =================================================================== --- ext/-test-/class/init.c (revision 0) +++ ext/-test-/class/init.c (revision 43367) @@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/class/init.c#L1 +#include "ruby.h" + +#define init(n) {void Init_##n(VALUE mod); Init_##n(mod);} + +void +Init_class(void) +{ + VALUE mBug = rb_define_module("Bug"); + VALUE mod = rb_define_module_under(mBug, "Class"); + TEST_INIT_FUNCS(init); +} Property changes on: ext/-test-/class/init.c ___________________________________________________________________ Added: svn:eol-style + LF Index: ext/-test-/class/extconf.rb =================================================================== --- ext/-test-/class/extconf.rb (revision 0) +++ ext/-test-/class/extconf.rb (revision 43367) @@ -0,0 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/class/extconf.rb#L1 +$INCFLAGS << " -I$(topdir) -I$(top_srcdir)" +$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] +inits = $srcs.map {|s| File.basename(s, ".*")} +inits.delete("init") +inits.map! {|s|"X(#{s})"} +$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\"" +create_makefile("-test-/class") Property changes on: ext/-test-/class/extconf.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: ext/-test-/class/class2name.c =================================================================== --- ext/-test-/class/class2name.c (revision 0) +++ ext/-test-/class/class2name.c (revision 43367) @@ -0,0 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/class/class2name.c#L1 +#include <ruby/ruby.h> + +static VALUE +class2name(VALUE self, VALUE klass) +{ + const char *name = rb_class2name(klass); + return name ? rb_str_new_cstr(name) : Qnil; +} + +void +Init_class2name(VALUE klass) +{ + rb_define_singleton_method(klass, "class2name", class2name, 1); +} Property changes on: ext/-test-/class/class2name.c ___________________________________________________________________ Added: svn:eol-style + LF Property changes on: ext/-test-/class ___________________________________________________________________ Added: svn:ignore + Makefile extconf.h mkmf.log Index: test/-ext-/class/test_class2name.rb =================================================================== --- test/-ext-/class/test_class2name.rb (revision 0) +++ test/-ext-/class/test_class2name.rb (revision 43367) @@ -0,0 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/class/test_class2name.rb#L1 +require 'test/unit' +require "-test-/class" + +class Test_Class < Test::Unit::TestCase + class Test_Class2Name < superclass + def test_toplevel_class + assert_equal("Object", Bug::Class.class2name(::Object)) + end + + def test_toplevel_module + assert_equal("Kernel", Bug::Class.class2name(::Kernel)) + end + + def test_singleton_class + assert_equal("Object", Bug::Class.class2name(::Object.new.singleton_class)) + end + end +end Property changes on: test/-ext-/class/test_class2name.rb ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/