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

ruby-changes:24072

From: nobu <ko1@a...>
Date: Mon, 18 Jun 2012 10:43:10 +0900 (JST)
Subject: [ruby-changes:24072] nobu:r36123 (trunk): ext/readline/readline.c: [Bug #6601]

nobu	2012-06-18 10:43:00 +0900 (Mon, 18 Jun 2012)

  New Revision: 36123

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36123

  Log:
    ext/readline/readline.c: [Bug #6601]
    
    * ext/readline/readline.c (readline_getc): deal with ESC just followed
      by ASCII as meta prefix in incremental search mode.  based on the
      patch from rctay (Tay Ray Chuan) at [ruby-core:45682].  [Bug #6601]

  Modified files:
    trunk/ChangeLog
    trunk/ext/readline/readline.c
    trunk/test/readline/test_readline.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36122)
+++ ChangeLog	(revision 36123)
@@ -1,3 +1,9 @@
+Mon Jun 18 10:42:57 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/readline/readline.c (readline_getc): deal with ESC just followed
+	  by ASCII as meta prefix in incremental search mode.  based on the
+	  patch from rctay (Tay Ray Chuan) at [ruby-core:45682].  [Bug #6601]
+
 Sun Jun 17 22:23:53 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* dir.c (rb_file_directory_p): move documentation for Dir.exist? from
Index: ext/readline/readline.c
===================================================================
--- ext/readline/readline.c	(revision 36122)
+++ ext/readline/readline.c	(revision 36123)
@@ -130,7 +130,6 @@
 
 #if defined HAVE_RL_GETC_FUNCTION
 static VALUE readline_instream;
-static ID id_getbyte;
 
 #ifndef HAVE_RL_GETC
 #define rl_getc(f) EOF
@@ -173,9 +172,19 @@
         }
     }
 #endif
-    c = rb_funcall(readline_instream, id_getbyte, 0, 0);
+    c = rb_io_getbyte(readline_instream);
     if (NIL_P(c)) return EOF;
-    return NUM2CHR(c);
+    if (c == INT2FIX(ESC) &&
+	RL_ISSTATE(RL_STATE_ISEARCH) && /* isn't needed in other states? */
+	rb_io_read_pending(ifp)) {
+	int meta = 0;
+	c = rb_io_getbyte(readline_instream);
+	if (FIXNUM_P(c) && isascii(FIX2INT(c))) meta = 1;
+	rb_io_ungetbyte(readline_instream, c);
+	if (meta) rl_execute_next(ESC);
+	return ESC;
+    }
+    return FIX2INT(c);
 }
 #elif defined HAVE_RL_EVENT_HOOK
 #define BUSY_WAIT 0
@@ -1703,7 +1712,6 @@
     /* and using_history() call rl_initialize(). */
     /* This assignment should be placed before using_history() */
     rl_getc_function = readline_getc;
-    id_getbyte = rb_intern_const("getbyte");
 #elif defined HAVE_RL_EVENT_HOOK
     rl_event_hook = readline_event;
 #endif
Index: test/readline/test_readline.rb
===================================================================
--- test/readline/test_readline.rb	(revision 36122)
+++ test/readline/test_readline.rb	(revision 36123)
@@ -399,6 +399,21 @@
     end
   end if !/EditLine/n.match(Readline::VERSION)
 
+  def test_input_metachar
+    bug6601 = '[ruby-core:45682]'
+    Readline::HISTORY << "hello"
+    wo = nil
+    line = with_pipe do |r, w|
+      wo = w.dup
+      wo.write("\C-re\ef\n")
+    end
+    assert_equal("hello", line, bug6601)
+  ensure
+    wo.close
+    with_pipe {|r, w| w.write("\C-a\C-k\n")} # clear line_buffer
+    Readline::HISTORY.clear
+  end
+
   private
 
   def replace_stdio(stdin_path, stdout_path)

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

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