ruby-changes:40619
From: nobu <ko1@a...>
Date: Sat, 21 Nov 2015 18:57:52 +0900 (JST)
Subject: [ruby-changes:40619] nobu:r52698 (trunk): ruby.c: --debug=frozen-string-literal option
nobu 2015-11-21 18:57:31 +0900 (Sat, 21 Nov 2015) New Revision: 52698 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52698 Log: ruby.c: --debug=frozen-string-literal option * ruby.c (need_argument): move frozen-string-literal-debug option from --enable to --debug. [Feature #11725] Modified files: trunk/ChangeLog trunk/ruby.c trunk/test/ruby/test_marshal.rb trunk/test/ruby/test_rubyoptions.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 52697) +++ ChangeLog (revision 52698) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Sat Nov 21 18:41:53 2015 Nobuyoshi Nakada <nobu@r...> +Sat Nov 21 18:57:28 2015 Nobuyoshi Nakada <nobu@r...> + + * ruby.c (need_argument): move frozen-string-literal-debug option + from --enable to --debug. [Feature #11725] * ruby.c (proc_options): fix pointer overrun. do not advance argv until it is valid. Index: ruby.c =================================================================== --- ruby.c (revision 52697) +++ ruby.c (revision 52698) @@ -755,7 +755,6 @@ feature_option(const char *str, int len, https://github.com/ruby/ruby/blob/trunk/ruby.c#L755 SET_FEATURE(did_you_mean); SET_FEATURE(rubyopt); SET_FEATURE(frozen_string_literal); - SET_FEATURE(frozen_string_literal_debug); if (NAME_MATCH_P("all", str, len)) { found: *argp = (*argp & ~mask) | (mask & enable); @@ -778,6 +777,14 @@ disable_option(const char *str, int len, https://github.com/ruby/ruby/blob/trunk/ruby.c#L777 } static void +debug_option(const char *str, int len, void *arg) +{ +#define SET_WHEN_DEBUG(t, bit) SET_WHEN(#bit, t##_BIT(bit), str, len) + SET_WHEN_DEBUG(FEATURE, frozen_string_literal_debug); + rb_warn("unknown argument for --debug: `%.*s'", len, str); +} + +static void dump_option(const char *str, int len, void *arg) { #define SET_WHEN_DUMP(bit) SET_WHEN(#bit, DUMP_BIT(bit), str, len) @@ -1087,22 +1094,25 @@ proc_options(long argc, char **argv, str https://github.com/ruby/ruby/blob/trunk/ruby.c#L1094 # define check_envopt(name, allow_envopt) \ (((allow_envopt) || !envopt) ? (void)0 : \ rb_raise(rb_eRuntimeError, "invalid switch in RUBYOPT: --" name)) -# define need_argument(name, s, needs_arg) \ - ((*(s) ? !*++(s) : (!argc || !((s) = argv[1]) || (--argc, ++argv, 0))) && (needs_arg) ? \ +# define need_argument(name, s, needs_arg, next_arg) \ + ((*(s) ? !*++(s) : (next_arg) && (!argc || !((s) = argv[1]) || (--argc, ++argv, 0))) && (needs_arg) ? \ rb_raise(rb_eRuntimeError, "missing argument for --" name) \ : (void)0) # define is_option_with_arg(name, allow_hyphen, allow_envopt) \ - is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue) -# define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg) \ + is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue, Qtrue) +# define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg) \ (strncmp((name), s, n = sizeof(name) - 1) == 0 && is_option_end(s[n], (allow_hyphen)) ? \ (check_envopt(name, (allow_envopt)), s += n, \ - need_argument(name, s, needs_arg), 1) : 0) + need_argument(name, s, needs_arg, next_arg), 1) : 0) if (strcmp("copyright", s) == 0) { if (envopt) goto noenvopt_long; opt->dump |= DUMP_BIT(copyright); } - else if (strcmp("debug", s) == 0) { + else if (is_option_with_optarg("debug", Qtrue, Qtrue, Qfalse, Qfalse)) { + if (s && *s) { + ruby_each_words(s, debug_option, &opt->features); + } ruby_debug = Qtrue; ruby_verbose = Qtrue; } Index: test/ruby/test_marshal.rb =================================================================== --- test/ruby/test_marshal.rb (revision 52697) +++ test/ruby/test_marshal.rb (revision 52698) @@ -705,7 +705,7 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L705 expected = out opt << "--enable=frozen-string-literal" - opt << "--enable=frozen-string-literal-debug" + opt << "--debug=frozen-string-literal" out, err, status = EnvUtil.invoke_ruby(*args) assert_empty(err) assert_predicate(status, :success?) Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 52697) +++ test/ruby/test_rubyoptions.rb (revision 52698) @@ -806,14 +806,14 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L806 end def test_frozen_string_literal_debug - assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", "--enable-frozen-string-literal-debug" ], '"foo" << "bar"', [], /created at/) - assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", "--disable-frozen-string-literal-debug"], '"foo" << "bar"', [], /created at/) - assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", "--enable-frozen-string-literal-debug" ], '"foo#{123}bar" << "bar"', [], /created at/) - assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", "--disable-frozen-string-literal-debug"], '"foo#{123}bar" << "bar"', [], /can\'t modify frozen String \(RuntimeError\)\n\z/) - assert_in_out_err(["--disable=gems", "--disable-frozen-string-literal", "--enable-frozen-string-literal-debug" ], '"foo" << "bar"', [], []) - assert_in_out_err(["--disable=gems", "--disable-frozen-string-literal", "--disable-frozen-string-literal-debug"], '"foo" << "bar"', [], []) - assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal-debug" ], '"foo" << "bar"', [], []) - assert_in_out_err(["--disable=gems", "--disable-frozen-string-literal-debug"], '"foo" << "bar"', [], []) + assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", "--debug-frozen-string-literal" ], '"foo" << "bar"', [], /created at/) + assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", ], '"foo" << "bar"', [], /created at/) + assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", "--debug-frozen-string-literal" ], '"foo#{123}bar" << "bar"', [], /created at/) + assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", ], '"foo#{123}bar" << "bar"', [], /can\'t modify frozen String \(RuntimeError\)\n\z/) + assert_in_out_err(["--disable=gems", "--disable-frozen-string-literal", "--debug-frozen-string-literal" ], '"foo" << "bar"', [], []) + assert_in_out_err(["--disable=gems", "--disable-frozen-string-literal", ], '"foo" << "bar"', [], []) + assert_in_out_err(["--disable=gems", "--debug-frozen-string-literal" ], '"foo" << "bar"', [], []) + assert_in_out_err(["--disable=gems", ], '"foo" << "bar"', [], []) assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", ], '"foo" << "bar"', [], /created at/) assert_in_out_err(["--disable=gems", "--enable-frozen-string-literal", ], '"foo#{123}bar" << "bar"', [], /can\'t modify frozen String \(RuntimeError\)\n\z/) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/