1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-06-08 02:07:42 +00:00
parent aac0b43ed5
commit 238a6246ff

15
ruby.c
View file

@ -1446,6 +1446,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
{
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, ruby_cmdline_options_t *opt)
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, ruby_cmdline_options_t *opt)
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, ruby_cmdline_options_t *opt)
{
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));