* encoding.c (Init_Encoding): set locale and filesystem encindex.

* ruby.c (process_options): move setting func of filesystem
  encoding to Init_Encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2009-10-29 08:14:09 +00:00
parent 0d9386d123
commit 06346d5849
3 changed files with 26 additions and 22 deletions

View File

@ -1,3 +1,10 @@
Thu Oct 29 15:35:39 2009 NARUSE, Yui <naruse@ruby-lang.org>
* encoding.c (Init_Encoding): set locale and filesystem encindex.
* ruby.c (process_options): move setting func of filesystem
encoding to Init_Encoding.
Thu Oct 29 15:43:25 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Oct 29 15:43:25 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_core.h (rb_name_err_mesg_new): added prototype. * vm_core.h (rb_name_err_mesg_new): added prototype.

View File

@ -26,6 +26,7 @@
static ID id_encoding; static ID id_encoding;
VALUE rb_cEncoding; VALUE rb_cEncoding;
static VALUE rb_encoding_list; static VALUE rb_encoding_list;
static int locale_encindex = -1, filesystem_encindex = -1;
struct rb_encoding_entry { struct rb_encoding_entry {
const char *name; const char *name;
@ -1093,53 +1094,47 @@ rb_usascii_encindex(void)
return ENCINDEX_US_ASCII; return ENCINDEX_US_ASCII;
} }
static int static void
rb_locale_encindex(void) set_locale_encindex(void)
{ {
VALUE charmap = rb_locale_charmap(rb_cEncoding); VALUE charmap = rb_locale_charmap(rb_cEncoding);
int idx;
if (NIL_P(charmap)) if (NIL_P(charmap))
idx = rb_usascii_encindex(); locale_encindex = rb_usascii_encindex();
else if ((idx = rb_enc_find_index(StringValueCStr(charmap))) < 0) else if ((locale_encindex = rb_enc_find_index(StringValueCStr(charmap))) < 0)
idx = rb_ascii8bit_encindex(); locale_encindex = rb_ascii8bit_encindex();
if (rb_enc_registered("locale") < 0) enc_alias_internal("locale", idx); if (rb_enc_registered("locale") < 0) enc_alias_internal("locale", locale_encindex);
return idx;
} }
rb_encoding * rb_encoding *
rb_locale_encoding(void) rb_locale_encoding(void)
{ {
return rb_enc_from_index(rb_locale_encindex()); return rb_enc_from_index(locale_encindex);
} }
static int static void
rb_filesystem_encindex(void) set_filesystem_encindex(void)
{ {
int idx;
#if defined NO_LOCALE_CHARMAP #if defined NO_LOCALE_CHARMAP
idx = rb_enc_to_index(rb_default_external_encoding()); filesystem_encindex = rb_enc_to_index(rb_default_external_encoding());
#elif defined _WIN32 || defined __CYGWIN__ #elif defined _WIN32 || defined __CYGWIN__
char cp[sizeof(int) * 8 / 3 + 4]; char cp[sizeof(int) * 8 / 3 + 4];
snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP()); snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
idx = rb_enc_find_index(cp); filesystem_encindex = rb_enc_find_index(cp);
#elif defined __APPLE__ #elif defined __APPLE__
idx = rb_utf8_encindex(); filesystem_encindex = rb_utf8_encindex();
#else #else
idx = rb_locale_encindex(); filesystem_encindex = locale_encindex;
#endif #endif
if (rb_enc_registered("filesystem") < 0) enc_alias_internal("filesystem", idx); if (rb_enc_registered("filesystem") < 0) enc_alias_internal("filesystem", filesystem_encindex);
return idx;
} }
rb_encoding * rb_encoding *
rb_filesystem_encoding(void) rb_filesystem_encoding(void)
{ {
return rb_enc_from_index(rb_filesystem_encindex()); return rb_enc_from_index(filesystem_encindex);
} }
struct default_encoding { struct default_encoding {
@ -1501,6 +1496,9 @@ Init_Encoding(void)
for (i = 0; i < enc_table.count; ++i) { for (i = 0; i < enc_table.count; ++i) {
rb_ary_push(list, enc_new(enc_table.list[i].enc)); rb_ary_push(list, enc_new(enc_table.list[i].enc));
} }
set_locale_encindex();
set_filesystem_encindex();
} }
/* locale insensitive functions */ /* locale insensitive functions */

1
ruby.c
View File

@ -1302,7 +1302,6 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
ruby_init_loadpath_safe(opt->safe_level); ruby_init_loadpath_safe(opt->safe_level);
rb_enc_find_index("encdb"); rb_enc_find_index("encdb");
lenc = rb_locale_encoding(); lenc = rb_locale_encoding();
(void)rb_filesystem_encoding();
rb_enc_associate(rb_progname, lenc); rb_enc_associate(rb_progname, lenc);
parser = rb_parser_new(); parser = rb_parser_new();
if (opt->dump & DUMP_BIT(yydebug)) { if (opt->dump & DUMP_BIT(yydebug)) {