Skip to content

Commit

Permalink
Revert set locale and filesystem encindex in Init_Encoding.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Oct 29, 2009
1 parent 06346d5 commit 2f2e845
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Thu Oct 29 18:37:02 2009 NARUSE, Yui <[email protected]>

* encoding.c (Init_Encoding): revert previous commit.

* ruby.c (process_options): ditto.

Thu Oct 29 15:35:39 2009 NARUSE, Yui <[email protected]>

* encoding.c (Init_Encoding): set locale and filesystem encindex.
Expand Down
40 changes: 21 additions & 19 deletions encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
static ID id_encoding;
VALUE rb_cEncoding;
static VALUE rb_encoding_list;
static int locale_encindex = -1, filesystem_encindex = -1;

struct rb_encoding_entry {
const char *name;
Expand Down Expand Up @@ -1094,47 +1093,53 @@ rb_usascii_encindex(void)
return ENCINDEX_US_ASCII;
}

static void
set_locale_encindex(void)
static int
rb_locale_encindex(void)
{
VALUE charmap = rb_locale_charmap(rb_cEncoding);
int idx;

if (NIL_P(charmap))
locale_encindex = rb_usascii_encindex();
else if ((locale_encindex = rb_enc_find_index(StringValueCStr(charmap))) < 0)
locale_encindex = rb_ascii8bit_encindex();
idx = rb_usascii_encindex();
else if ((idx = rb_enc_find_index(StringValueCStr(charmap))) < 0)
idx = rb_ascii8bit_encindex();

if (rb_enc_registered("locale") < 0) enc_alias_internal("locale", locale_encindex);
if (rb_enc_registered("locale") < 0) enc_alias_internal("locale", idx);

return idx;
}

rb_encoding *
rb_locale_encoding(void)
{
return rb_enc_from_index(locale_encindex);
return rb_enc_from_index(rb_locale_encindex());
}

static void
set_filesystem_encindex(void)
static int
rb_filesystem_encindex(void)
{
int idx;
#if defined NO_LOCALE_CHARMAP
filesystem_encindex = rb_enc_to_index(rb_default_external_encoding());
idx = rb_enc_to_index(rb_default_external_encoding());
#elif defined _WIN32 || defined __CYGWIN__
char cp[sizeof(int) * 8 / 3 + 4];
snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
filesystem_encindex = rb_enc_find_index(cp);
idx = rb_enc_find_index(cp);
#elif defined __APPLE__
filesystem_encindex = rb_utf8_encindex();
idx = rb_utf8_encindex();
#else
filesystem_encindex = locale_encindex;
idx = rb_locale_encindex();
#endif

if (rb_enc_registered("filesystem") < 0) enc_alias_internal("filesystem", filesystem_encindex);
if (rb_enc_registered("filesystem") < 0) enc_alias_internal("filesystem", idx);

return idx;
}

rb_encoding *
rb_filesystem_encoding(void)
{
return rb_enc_from_index(filesystem_encindex);
return rb_enc_from_index(rb_filesystem_encindex());
}

struct default_encoding {
Expand Down Expand Up @@ -1496,9 +1501,6 @@ Init_Encoding(void)
for (i = 0; i < enc_table.count; ++i) {
rb_ary_push(list, enc_new(enc_table.list[i].enc));
}
set_locale_encindex();
set_filesystem_encindex();

}

/* locale insensitive functions */
Expand Down
1 change: 1 addition & 0 deletions ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
ruby_init_loadpath_safe(opt->safe_level);
rb_enc_find_index("encdb");
lenc = rb_locale_encoding();
(void)rb_filesystem_encoding();
rb_enc_associate(rb_progname, lenc);
parser = rb_parser_new();
if (opt->dump & DUMP_BIT(yydebug)) {
Expand Down

0 comments on commit 2f2e845

Please sign in to comment.