Skip to content

Commit

Permalink
* encoding.c (rb_locale_encoding): should check return value from
Browse files Browse the repository at this point in the history
	  rb_locale_charmap().

	* ruby.c (locale_encoding): removed.

	* ruby.c (process_options): use rb_locale_encoding() instead of
	  locale_encoding().

	* ext/readline/readline.c (readline_readline): use locale encoding
	  instead of input IO's encoding. [ruby-dev:32872]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
unak committed Dec 28, 2007
1 parent b1b238d commit eb1014e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Fri Dec 28 19:39:34 2007 NAKAMURA Usaku <[email protected]>

* encoding.c (rb_locale_encoding): should check return value from
rb_locale_charmap().

* ruby.c (locale_encoding): removed.

* ruby.c (process_options): use rb_locale_encoding() instead of
locale_encoding().

* ext/readline/readline.c (readline_readline): use locale encoding
instead of input IO's encoding. [ruby-dev:32872]

Fri Dec 28 19:29:07 2007 NAKAMURA Usaku <[email protected]>

* ext/readline/readline.c (readline_readline, readline_s_set_input):
Expand Down
6 changes: 5 additions & 1 deletion encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,12 @@ rb_encoding *
rb_locale_encoding(void)
{
VALUE charmap = rb_locale_charmap(rb_cEncoding);
int idx = rb_enc_find_index(StringValueCStr(charmap));
int idx;

if (NIL_P(charmap))
return rb_ascii8bit_encoding();

idx = rb_enc_find_index(StringValueCStr(charmap));
if (idx < 0)
return rb_ascii8bit_encoding();

Expand Down
17 changes: 1 addition & 16 deletions ext/readline/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#endif

static VALUE mReadline;
static VALUE id_var_input;

#define TOLOWER(c) (isupper(c) ? tolower(c) : c)

Expand Down Expand Up @@ -95,18 +94,8 @@ readline_readline(int argc, VALUE *argv, VALUE self)
add_history(buff);
}
if (buff) {
rb_encoding* enc;
VALUE input = rb_ivar_get(mReadline, id_var_input);
rb_io_t *ifp;
GetOpenFile(input, ifp);
if (ifp->enc)
enc = ifp->enc;
else if (ifp->mode & FMODE_BINMODE)
enc = rb_ascii8bit_encoding();
else
enc = rb_default_external_encoding();
result = rb_tainted_str_new2(buff);
rb_enc_associate(result, enc);
rb_enc_associate(result, rb_locale_encoding());
}
else
result = Qnil;
Expand All @@ -123,7 +112,6 @@ readline_s_set_input(VALUE self, VALUE input)
Check_Type(input, T_FILE);
GetOpenFile(input, ifp);
rl_instream = rb_io_stdio_file(ifp);
rb_ivar_set(mReadline, id_var_input, input);
return input;
}

Expand Down Expand Up @@ -769,9 +757,6 @@ Init_readline()
rb_define_singleton_method(mReadline, "filename_quote_characters",
readline_s_get_filename_quote_characters, 0);

id_var_input = rb_intern("#input");
rb_ivar_set(mReadline, id_var_input, rb_stdin);

history = rb_obj_alloc(rb_cObject);
rb_extend_object(history, rb_mEnumerable);
rb_define_singleton_method(history,"to_s", hist_to_s, 0);
Expand Down
19 changes: 1 addition & 18 deletions ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,6 @@ usage(const char *name)
printf(" %s\n", *p++);
}

static rb_encoding *
locale_encoding(void)
{
VALUE codeset = rb_locale_charmap(Qnil);
char *name;
int idx;

if (codeset == Qnil)
return rb_ascii8bit_encoding();

name = StringValueCStr(codeset);
idx = rb_enc_find_index(name);
if (idx < 0)
return rb_ascii8bit_encoding();
return rb_enc_from_index(idx);
}

extern VALUE rb_load_path;

#ifndef CharNext /* defined as CharNext[AW] on Windows. */
Expand Down Expand Up @@ -1025,7 +1008,7 @@ process_options(VALUE arg)
enc = rb_enc_from_index(opt->enc_index);
}
else {
enc = locale_encoding();
enc = rb_locale_encoding();
}
rb_enc_set_default_external(rb_enc_from_encoding(enc));

Expand Down

0 comments on commit eb1014e

Please sign in to comment.