1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/readline/readline.c (readline_readline): set encoding to result.

* ext/readline/readline.c (readline_s_set_input, Init_readline): save
	  input IO to hidden instance variable.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2007-12-28 09:46:44 +00:00
parent 793e9423cd
commit 6b54d4fd0b
2 changed files with 25 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Fri Dec 28 18:45:29 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/readline/readline.c (readline_readline): set encoding to result.
* ext/readline/readline.c (readline_s_set_input, Init_readline): save
input IO to hidden instance variable.
Fri Dec 28 01:55:04 2007 Martin Duerst <duerst@it.aoyama.ac.jp>
* transcode.c (transcode_dispatch): reverted some of the changes

View file

@ -29,6 +29,7 @@
#endif
static VALUE mReadline;
static VALUE id_var_input;
#define TOLOWER(c) (isupper(c) ? tolower(c) : c)
@ -93,8 +94,20 @@ readline_readline(int argc, VALUE *argv, VALUE self)
if (RTEST(add_hist) && buff) {
add_history(buff);
}
if (buff)
if (buff) {
rb_io_t *ifp;
rb_encoding* enc;
VALUE input = rb_ivar_get(self, id_var_input);
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);
}
else
result = Qnil;
if (buff) free(buff);
@ -110,6 +123,7 @@ 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(self, id_var_input, input);
return input;
}
@ -755,6 +769,9 @@ 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);