ruby-changes:46926
From: nobu <ko1@a...>
Date: Thu, 8 Jun 2017 11:07:47 +0900 (JST)
Subject: [ruby-changes:46926] nobu:r59041 (trunk): ruby.c: script name in UTF-8
nobu 2017-06-08 11:07:42 +0900 (Thu, 08 Jun 2017) New Revision: 59041 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59041 Log: ruby.c: script name in UTF-8 * ruby.c (process_options): keep script name in UTF-8 if UTF8_PATH to get rid of loss by conversion. Modified files: trunk/ruby.c Index: ruby.c =================================================================== --- ruby.c (revision 59040) +++ ruby.c (revision 59041) @@ -1446,6 +1446,7 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1446 { NODE *tree = 0; VALUE parser; + VALUE script_name; const rb_iseq_t *iseq; rb_encoding *enc, *lenc; #if UTF8_PATH @@ -1570,13 +1571,15 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1571 ienc = enc; #endif } - if (IF_UTF8_PATH((uenc = rb_utf8_encoding()) != lenc, 0)) { + script_name = opt->script_name; + rb_enc_associate(opt->script_name, + IF_UTF8_PATH(uenc = rb_utf8_encoding(), lenc)); +#if UTF8_PATH + if (uenc != lenc) { opt->script_name = str_conv_enc(opt->script_name, uenc, lenc); opt->script = RSTRING_PTR(opt->script_name); } - else { - rb_enc_associate(opt->script_name, lenc); - } +#endif rb_obj_freeze(opt->script_name); if (IF_UTF8_PATH(uenc != lenc, 1)) { long i; @@ -1654,7 +1657,7 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1657 VALUE f; base_block = toplevel_context(toplevel_binding); rb_parser_set_context(parser, base_block, TRUE); - f = open_load_file(opt->script_name, &opt->xflag); + f = open_load_file(script_name, &opt->xflag); tree = load_file(parser, opt->script_name, f, 1, opt); } ruby_set_script_name(opt->script_name); @@ -1712,7 +1715,7 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1715 { VALUE path = Qnil; if (!opt->e_script && strcmp(opt->script, "-")) { - path = rb_realpath_internal(Qnil, opt->script_name, 1); + path = rb_realpath_internal(Qnil, script_name, 1); } base_block = toplevel_context(toplevel_binding); iseq = rb_iseq_new_main(tree, opt->script_name, path, vm_block_iseq(base_block)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/