diff options
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -1667,6 +1667,17 @@ tty_enabled(void) #endif static VALUE +copy_str(VALUE str, rb_encoding *enc, bool intern) +{ + if (!intern) { + if (rb_enc_str_coderange_scan(str, enc) == ENC_CODERANGE_BROKEN) + return 0; + return rb_enc_associate(rb_str_dup(str), enc); + } + return rb_enc_interned_str(RSTRING_PTR(str), RSTRING_LEN(str), enc); +} + +static VALUE process_options(int argc, char **argv, ruby_cmdline_options_t *opt) { rb_ast_t *ast = 0; @@ -1682,6 +1693,8 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) char fbuf[MAXPATHLEN]; int i = (int)proc_options(argc, argv, opt, 0); unsigned int dump = opt->dump & dump_exit_bits; + rb_vm_t *vm = GET_VM(); + const long loaded_before_enc = RARRAY_LEN(vm->loaded_features); if (opt->dump & (DUMP_BIT(usage)|DUMP_BIT(help))) { int tty = isatty(1); @@ -1883,7 +1896,6 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) rb_obj_freeze(opt->script_name); if (IF_UTF8_PATH(uenc != lenc, 1)) { long i; - rb_vm_t *vm = GET_VM(); VALUE load_path = vm->load_path; const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK; int modifiable = FALSE; @@ -1897,7 +1909,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) if (newpath == path) continue; path = newpath; #else - path = rb_enc_associate(rb_str_dup(path), lenc); + if (!(path = copy_str(path, lenc, !mark))) continue; #endif if (mark) rb_ivar_set(path, id_initial_load_path_mark, path); if (!modifiable) { @@ -1910,6 +1922,19 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) rb_ary_replace(vm->load_path_snapshot, load_path); } } + { + VALUE loaded_features = vm->loaded_features; + bool modified = false; + for (long i = loaded_before_enc; i < RARRAY_LEN(loaded_features); ++i) { + VALUE path = RARRAY_AREF(loaded_features, i); + if (!(path = copy_str(path, IF_UTF8_PATH(uenc, lenc), true))) continue; + modified = true; + RARRAY_ASET(loaded_features, i, path); + } + if (modified) { + rb_ary_replace(vm->loaded_features_snapshot, loaded_features); + } + } if (opt->features.mask & COMPILATION_FEATURES) { VALUE option = rb_hash_new(); |