From 14ab3bd2ac7a3dda443342354847b99d1967e73a Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 25 Dec 2007 14:16:03 +0000 Subject: [PATCH] * ruby.c (proc_options): encoding option in shbang and RUBYOPT did not work, do not store alloca()ed string in a parent scope struct. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ruby.c | 15 +++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index b82f86a445..929fa2f896 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Dec 25 23:16:01 2007 Nobuyoshi Nakada + + * ruby.c (proc_options): encoding option in shbang and RUBYOPT did not + work, do not store alloca()ed string in a parent scope struct. + Tue Dec 25 22:56:52 2007 NAKAMURA Usaku * win32/Makefile.sub (config.status): keep this file. diff --git a/ruby.c b/ruby.c index fce8479bd1..94aba59008 100644 --- a/ruby.c +++ b/ruby.c @@ -81,7 +81,6 @@ struct cmdline_options { int yydebug; char *script; VALUE e_script; - const char *enc_name; int enc_index; }; @@ -550,6 +549,7 @@ proc_options(int argc, char **argv, struct cmdline_options *opt) { int argc0 = argc; const char *s; + const char *enc_name = 0; if (argc == 0) return 0; @@ -740,7 +740,7 @@ proc_options(int argc, char **argv, struct cmdline_options *opt) break; } if (enc) { - opt->enc_name = rb_enc_name(enc); + opt->enc_index = rb_enc_find_index(rb_enc_name(enc)); } s++; } @@ -806,12 +806,16 @@ proc_options(int argc, char **argv, struct cmdline_options *opt) else if (strcmp("disable-gems", s) == 0) opt->disable_gems = 1; else if (strcmp("encoding", s) == 0) { + int idx; if (!--argc || !(s = *++argv)) { noencoding: rb_raise(rb_eRuntimeError, "missing argument for --encoding"); } encoding: - opt->enc_name = s; + if ((idx = rb_enc_find_index(s)) < 0) { + rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s); + } + opt->enc_index = idx; } else if (strncmp("encoding=", s, 9) == 0) { if (!*(s += 9)) goto noencoding; @@ -980,11 +984,6 @@ process_options(VALUE arg) ruby_init_gems(opt); parser = rb_parser_new(); if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue); - if ((s = opt->enc_name) != 0) { - if ((opt->enc_index = rb_enc_find_index(s)) < 0) { - rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s); - } - } if (opt->e_script) { if (opt->enc_index >= 0) rb_enc_associate_index(opt->e_script, opt->enc_index);