* ruby.c (rubylib_mangled_path, rubylib_mangled_path2): cannot use

locale encoding before load path is initialized

* ruby.c (ruby_init_loadpath_safe): ditto.

* ruby.c (process_options): loads encdb so that encodings can be
  loaded, then associates script name and load paths with the
  locale encoding.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-12-15 02:32:21 +00:00
Родитель 23f72026a4
Коммит f403298449
2 изменённых файлов: 39 добавлений и 13 удалений

Просмотреть файл

@ -1,3 +1,14 @@
Mon Dec 15 11:32:18 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (rubylib_mangled_path, rubylib_mangled_path2): cannot use
locale encoding before load path is initialized
* ruby.c (ruby_init_loadpath_safe): ditto.
* ruby.c (process_options): loads encdb so that encodings can be
loaded, then associates script name and load paths with the
locale encoding.
Mon Dec 15 10:00:36 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Dec 15 10:00:36 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (btest-ruby): use RUNRUBY instead of MINIRUBY to load the * common.mk (btest-ruby): use RUNRUBY instead of MINIRUBY to load the

41
ruby.c
Просмотреть файл

@ -213,9 +213,9 @@ rubylib_mangled_path(const char *s, unsigned int l)
} }
} }
if (!newp || l < oldl || STRNCASECMP(oldp, s, oldl) != 0) { if (!newp || l < oldl || STRNCASECMP(oldp, s, oldl) != 0) {
return rb_locale_str_new(s, l); return rb_str_new(s, l);
} }
ret = rb_locale_str_new(0, l + newl - oldl); ret = rb_str_new(0, l + newl - oldl);
ptr = RSTRING_PTR(ret); ptr = RSTRING_PTR(ret);
memcpy(ptr, newp, newl); memcpy(ptr, newp, newl);
memcpy(ptr + newl, s + oldl, l - oldl); memcpy(ptr + newl, s + oldl, l - oldl);
@ -229,8 +229,8 @@ rubylib_mangled_path2(const char *s)
return rubylib_mangled_path(s, strlen(s)); return rubylib_mangled_path(s, strlen(s));
} }
#else #else
#define rubylib_mangled_path rb_locale_str_new #define rubylib_mangled_path rb_str_new
#define rubylib_mangled_path2 rb_locale_str_new_cstr #define rubylib_mangled_path2 rb_str_new_cstr
#endif #endif
static void static void
@ -301,11 +301,17 @@ identical_path(VALUE path)
{ {
return path; return path;
} }
static VALUE
locale_path(VALUE path)
{
rb_enc_associate(path, rb_locale_encoding());
return path;
}
void void
ruby_incpush(const char *path) ruby_incpush(const char *path)
{ {
ruby_push_include(path, identical_path); ruby_push_include(path, locale_path);
} }
static VALUE static VALUE
@ -397,7 +403,7 @@ ruby_init_loadpath_safe(int safe_level)
load_path = GET_VM()->load_path; load_path = GET_VM()->load_path;
if (safe_level == 0) { if (safe_level == 0) {
ruby_incpush(getenv("RUBYLIB")); ruby_push_include(getenv("RUBYLIB"), identical_path);
} }
#ifdef RUBY_SEARCH_PATH #ifdef RUBY_SEARCH_PATH
@ -1178,18 +1184,17 @@ process_options(VALUE arg)
} }
} }
rb_progname = rb_obj_freeze(rb_str_new_cstr(opt->script)); opt->script_name = rb_str_new_cstr(opt->script);
#if defined DOSISH || defined __CYGWIN__
translate_char(RSTRING_PTR(rb_progname), '\\', '/');
#endif
opt->script_name = rb_progname;
opt->script = RSTRING_PTR(opt->script_name); opt->script = RSTRING_PTR(opt->script_name);
#if defined DOSISH || defined __CYGWIN__
translate_char(opt->script, '\\', '/');
#endif
rb_obj_freeze(opt->script_name);
ruby_init_loadpath_safe(opt->safe_level); ruby_init_loadpath_safe(opt->safe_level);
ruby_init_gems(!(opt->disable & DISABLE_BIT(gems))); rb_enc_find_index("encdb");
lenc = rb_locale_encoding(); lenc = rb_locale_encoding();
rb_enc_associate(rb_progname, lenc); rb_enc_associate(rb_progname, lenc);
opt->script_name = rb_str_new4(rb_progname);
parser = rb_parser_new(); parser = rb_parser_new();
if (opt->dump & DUMP_BIT(yydebug)) { if (opt->dump & DUMP_BIT(yydebug)) {
rb_parser_set_yydebug(parser, Qtrue); rb_parser_set_yydebug(parser, Qtrue);
@ -1216,6 +1221,15 @@ process_options(VALUE arg)
rb_enc_set_default_internal(rb_enc_from_encoding(enc)); rb_enc_set_default_internal(rb_enc_from_encoding(enc));
opt->intern.enc.index = -1; opt->intern.enc.index = -1;
} }
rb_enc_associate(opt->script_name, lenc);
{
long i;
VALUE load_path = GET_VM()->load_path;
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
rb_enc_associate(RARRAY_PTR(load_path)[i], lenc);
}
}
ruby_init_gems(!(opt->disable & DISABLE_BIT(gems)));
ruby_set_argv(argc, argv); ruby_set_argv(argc, argv);
process_sflag(opt); process_sflag(opt);
@ -1284,6 +1298,7 @@ process_options(VALUE arg)
rb_define_readonly_boolean("$-a", opt->do_split); rb_define_readonly_boolean("$-a", opt->do_split);
rb_set_safe_level(opt->safe_level); rb_set_safe_level(opt->safe_level);
rb_progname = opt->script_name;
return iseq; return iseq;
} }