From 6cb161a66c014db83c62ebf8a0d6beff60f44382 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 31 Dec 2007 14:57:46 +0000 Subject: * ruby.c (proc_options, process_options): delays finding encoding until load_path is set. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ruby.c') diff --git a/ruby.c b/ruby.c index 2e44c47fbd..a47403eb55 100644 --- a/ruby.c +++ b/ruby.c @@ -81,6 +81,7 @@ struct cmdline_options { int yydebug; char *script; VALUE e_script; + VALUE enc_name; int enc_index; }; @@ -723,7 +724,7 @@ proc_options(int argc, char **argv, struct cmdline_options *opt) break; } if (enc) { - opt->enc_index = rb_enc_find_index(rb_enc_name(enc)); + opt->enc_name = rb_str_new2(rb_enc_name(enc)); } s++; } @@ -789,16 +790,12 @@ 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: - if ((idx = rb_enc_find_index(s)) < 0) { - rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s); - } - opt->enc_index = idx; + opt->enc_name = rb_str_new2(s); } else if (strncmp("encoding=", s, 9) == 0) { if (!*(s += 9)) goto noencoding; @@ -967,6 +964,12 @@ process_options(VALUE arg) ruby_init_gems(opt); parser = rb_parser_new(); if (opt->yydebug) rb_parser_set_yydebug(parser, Qtrue); + if (opt->enc_name != 0) { + s = RSTRING_PTR(opt->enc_name); + 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); -- cgit v1.2.3