[前][次][番号順一覧][スレッド一覧]

ruby-changes:3274

From: ko1@a...
Date: 28 Dec 2007 18:47:02 +0900
Subject: [ruby-changes:3274] usa - Ruby:r14767 (trunk): * ext/readline/readline.c (readline_readline): set encoding to result.

usa	2007-12-28 18:46:44 +0900 (Fri, 28 Dec 2007)

  New Revision: 14767

  Modified files:
    trunk/ChangeLog
    trunk/ext/readline/readline.c

  Log:
    * 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.
    


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14767&r2=14766
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/readline/readline.c?r1=14767&r2=14766

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14766)
+++ ChangeLog	(revision 14767)
@@ -1,3 +1,10 @@
+Fri Dec 28 18:45:29 2007  NAKAMURA Usaku  <usa@r...>
+
+	* 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@i...>
 
 	* transcode.c (transcode_dispatch): reverted some of the changes
Index: ext/readline/readline.c
===================================================================
--- ext/readline/readline.c	(revision 14766)
+++ ext/readline/readline.c	(revision 14767)
@@ -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 @@
     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 @@
     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 @@
     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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]