ruby-changes:42003
From: nobu <ko1@a...>
Date: Thu, 10 Mar 2016 15:20:00 +0900 (JST)
Subject: [ruby-changes:42003] nobu:r54077 (trunk): node.c: hidden options hash
nobu 2016-03-10 15:19:55 +0900 (Thu, 10 Mar 2016) New Revision: 54077 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54077 Log: node.c: hidden options hash * node.c (dump_option): nd_compile_option is a hidden hash object, cannot call inspect on it. Modified files: trunk/ChangeLog trunk/node.c trunk/test/ruby/test_rubyoptions.rb Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 54076) +++ test/ruby/test_rubyoptions.rb (revision 54077) @@ -752,21 +752,19 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L752 assert_in_out_err(['-p', '-e', 'sub(/t.*/){"TEST"}'], %[test], %w[TEST], [], bug7157) end - def assert_norun_with_rflag(opt) + def assert_norun_with_rflag(*opt) bug10435 = "[ruby-dev:48712] [Bug #10435]: should not run with #{opt} option" stderr = [] Tempfile.create(%w"bug10435- .rb") do |script| dir, base = File.split(script.path) script.puts "abort ':run'" script.close - opts = ['-C', dir, '-r', "./#{base}", opt] - assert_in_out_err([*opts, '-ep']) do |_, e| - stderr.concat(e) - end + opts = ['-C', dir, '-r', "./#{base}", *opt] + _, e = assert_in_out_err([*opts, '-ep'], "", //) + stderr.concat(e) if e stderr << "---" - assert_in_out_err([*opts, base]) do |_, e| - stderr.concat(e) - end + _, e = assert_in_out_err([*opts, base], "", //) + stderr.concat(e) if e end assert_not_include(stderr, ":run", bug10435) end @@ -783,6 +781,7 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L781 def test_dump_parsetree_with_rflag assert_norun_with_rflag('--dump=parsetree') + assert_norun_with_rflag('--dump=parsetree', '-e', '#frozen-string-literal: true') end def test_dump_insns_with_rflag Index: node.c =================================================================== --- node.c (revision 54076) +++ node.c (revision 54077) @@ -37,6 +37,11 @@ https://github.com/ruby/ruby/blob/trunk/node.c#L37 rb_str_resize(indent, RSTRING_LEN(indent) - 4); \ } while (0) +#define COMPOUND_FIELD1(name, ann, block) \ + COMPOUND_FIELD(FIELD_NAME_LEN(#name, ann), \ + FIELD_NAME_DESC(#name, ann), \ + block) + #define FIELD_NAME_DESC(name, ann) name " (" ann ")" #define FIELD_NAME_LEN(name, ann) (int)( \ comment ? \ @@ -57,9 +62,9 @@ https://github.com/ruby/ruby/blob/trunk/node.c#L62 #define F_MSG(name, ann, desc) SIMPLE_FIELD1(#name, ann) A(desc) #define F_NODE(name, ann) \ - COMPOUND_FIELD(FIELD_NAME_LEN(#name, ann), \ - FIELD_NAME_DESC(#name, ann), \ - dump_node(buf, indent, comment, node->name)) + COMPOUND_FIELD1(name, ann, dump_node(buf, indent, comment, node->name)) +#define F_OPTION(name, ann) \ + COMPOUND_FIELD1(name, ann, dump_option(buf, indent, node->name)) #define ANN(ann) \ if (comment) { \ @@ -91,6 +96,42 @@ add_id(VALUE buf, ID id) https://github.com/ruby/ruby/blob/trunk/node.c#L96 } } +struct add_option_arg { + VALUE buf, indent; + st_index_t count; +}; + +static int +add_option_i(VALUE key, VALUE val, VALUE args) +{ + struct add_option_arg *argp = (void *)args; + VALUE buf = argp->buf; + VALUE indent = argp->indent; + + A_INDENT; + A("+- "); + AR(rb_sym2str(key)); + A(": "); + A_LIT(val); + A("\n"); + return ST_CONTINUE; +} + +static void +dump_option(VALUE buf, VALUE indent, VALUE opt) +{ + struct add_option_arg arg; + + if (!RB_TYPE_P(opt, T_HASH)) { + A_LIT(opt); + return; + } + arg.buf = buf; + arg.indent = indent; + arg.count = 0; + rb_hash_foreach(opt, add_option_i, (VALUE)&arg); +} + static void dump_node(VALUE buf, VALUE indent, int comment, NODE *node) { @@ -828,7 +869,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L869 F_NODE(nd_body, "body"); LAST_NODE; #define nd_compile_option u3.value - F_LIT(nd_compile_option, "compile_option"); + F_OPTION(nd_compile_option, "compile_option"); break; case NODE_LAMBDA: Index: ChangeLog =================================================================== --- ChangeLog (revision 54076) +++ ChangeLog (revision 54077) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Mar 10 15:19:54 2016 Nobuyoshi Nakada <nobu@r...> + + * node.c (dump_option): nd_compile_option is a hidden hash object, + cannot call inspect on it. + Thu Mar 10 09:49:54 2016 Rei Odaira <Rei.Odaira@g...> * test/socket/test_socket.rb (test_udp_recvmsg_truncation): -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/